forked from LogBlock/LogBlock
Dragon Egg teleport logging
This commit is contained in:
@ -209,6 +209,9 @@ public class LogBlock extends JavaPlugin {
|
||||
if (isLogging(Logging.GRASSGROWTH) || isLogging(Logging.MYCELIUMSPREAD) || isLogging(Logging.VINEGROWTH) || isLogging(Logging.MUSHROOMSPREAD)) {
|
||||
pm.registerEvents(new BlockSpreadLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
||||
pm.registerEvents(new DragonEggLogging(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,8 +7,8 @@ public enum Logging {
|
||||
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, COMPARATORINTERACT,
|
||||
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE,
|
||||
NATURALSTRUCTUREGROW, GRASSGROWTH, MYCELIUMSPREAD, VINEGROWTH, MUSHROOMSPREAD,
|
||||
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW,
|
||||
WORLDEDIT, TNTMINECARTEXPLOSION(true), ENDERCRYSTALEXPLOSION(true), BEDEXPLOSION(true);
|
||||
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW, WORLDEDIT, TNTMINECARTEXPLOSION(true),
|
||||
ENDERCRYSTALEXPLOSION(true), BEDEXPLOSION(true), DRAGONEGGTELEPORT(true);
|
||||
|
||||
public static final int length = Logging.values().length;
|
||||
private final boolean defaultEnabled;
|
||||
|
@ -0,0 +1,73 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.util.LoggingUtil;
|
||||
|
||||
public class DragonEggLogging extends LoggingListener {
|
||||
|
||||
private UUID lastDragonEggInteractionPlayer;
|
||||
private Location lastDragonEggInteractionLocation;
|
||||
|
||||
public DragonEggLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && event.getClickedBlock().getType() == Material.DRAGON_EGG) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (!Config.isLogging(block.getWorld(), Logging.DRAGONEGGTELEPORT)) {
|
||||
return;
|
||||
}
|
||||
lastDragonEggInteractionPlayer = event.getPlayer().getUniqueId();
|
||||
lastDragonEggInteractionLocation = block.getLocation();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lastDragonEggInteractionPlayer = null;
|
||||
lastDragonEggInteractionLocation = null;
|
||||
}
|
||||
}.runTask(LogBlock.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDragonEggTeleport(BlockFromToEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Player teleportCause = null;
|
||||
if (lastDragonEggInteractionPlayer != null && lastDragonEggInteractionLocation != null && lastDragonEggInteractionLocation.equals(block.getLocation())) {
|
||||
teleportCause = Bukkit.getPlayer(lastDragonEggInteractionPlayer);
|
||||
}
|
||||
|
||||
if (block.getType() == Material.DRAGON_EGG && Config.isLogging(block.getWorld(), Logging.DRAGONEGGTELEPORT)) {
|
||||
Actor actor = new Actor("DragonEgg");
|
||||
if (teleportCause != null) {
|
||||
actor = Actor.actorFromEntity(teleportCause);
|
||||
}
|
||||
BlockData data = block.getBlockData();
|
||||
consumer.queueBlockBreak(actor, block.getLocation(), data);
|
||||
BlockState finalState = event.getToBlock().getState();
|
||||
finalState.setBlockData(data);
|
||||
LoggingUtil.smartLogBlockPlace(consumer, actor, event.getToBlock().getState(), finalState);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user