diff --git a/src/main/java/de/diddiz/LogBlock/LogBlock.java b/src/main/java/de/diddiz/LogBlock/LogBlock.java index 158b09d..714f4da 100644 --- a/src/main/java/de/diddiz/LogBlock/LogBlock.java +++ b/src/main/java/de/diddiz/LogBlock/LogBlock.java @@ -89,7 +89,7 @@ public class LogBlock extends JavaPlugin if (noDb) return; if (pm.getPlugin("WorldEdit") != null) { - LogBlockEditSessionFactory.initialize(); + LogBlockEditSessionFactory.initialize(this); } commandsHandler = new CommandsHandler(this); getCommand("lb").setExecutor(commandsHandler); diff --git a/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java b/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java index 7c0813e..f87c786 100644 --- a/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java +++ b/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java @@ -10,39 +10,67 @@ import com.sk89q.worldedit.bukkit.BukkitWorld; import de.diddiz.LogBlock.LogBlock; import de.diddiz.LogBlock.Logging; import de.diddiz.LogBlock.config.Config; -import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; public class LogBlockEditSession extends EditSession { private LocalPlayer player; + private LogBlock plugin; /** * {@inheritDoc} */ - public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) { + public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player, LogBlock lb) { super(world, maxBlocks); this.player = player; + this.plugin = lb; } /** * {@inheritDoc} */ - public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { + public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player, LogBlock lb) { super(world, maxBlocks, blockBag); this.player = player; + this.plugin = lb; } @Override public boolean rawSetBlock(Vector pt, BaseBlock block) { - if (!(player.getWorld() instanceof BukkitWorld)) { + if (!(player.getWorld() instanceof BukkitWorld) || !(Config.isLogging(player.getWorld().getName(), Logging.WORLDEDIT))) { return super.rawSetBlock(pt, block); } + int typeBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + byte dataBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData(); + // If we're dealing with a sign, store the block state to read the text off + BlockState stateBefore = null; + if (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId()) { + stateBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getState(); + } boolean success = super.rawSetBlock(pt, block); - if (success && Config.isLogging(player.getWorld().getName(), Logging.WORLDEDIT)) { - Location location = new Location(Bukkit.getWorld(player.getWorld().getName()), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); - LogBlock.getInstance().getConsumer().queueBlock(player.getName(), location, typeBefore, location.getBlock().getTypeId(), location.getBlock().getData()); + if (success) { + Location location = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + + // Check to see if we've broken a sign + if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId())) { + plugin.getConsumer().queueSignBreak(player.getName(), (Sign) stateBefore); + if (block.getType() != Material.AIR.getId()) { + plugin.getConsumer().queueBlockPlace(player.getName(), location, block.getType(), (byte) block.getData()); + } + } else { + if (dataBefore != 0) { + plugin.getConsumer().queueBlockBreak(player.getName(), location, typeBefore, dataBefore); + if (block.getType() != Material.AIR.getId()) { + plugin.getConsumer().queueBlockPlace(player.getName(), location, block.getType(), (byte) block.getData()); + } + } else { + plugin.getConsumer().queueBlock(player.getName(), location, typeBefore, block.getType(), (byte) block.getData()); + } + } } return success; } diff --git a/src/main/java/de/diddiz/worldedit/LogBlockEditSessionFactory.java b/src/main/java/de/diddiz/worldedit/LogBlockEditSessionFactory.java index 900ea60..50bf4b9 100644 --- a/src/main/java/de/diddiz/worldedit/LogBlockEditSessionFactory.java +++ b/src/main/java/de/diddiz/worldedit/LogBlockEditSessionFactory.java @@ -1,26 +1,37 @@ package de.diddiz.worldedit; -import com.sk89q.worldedit.*; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.EditSessionFactory; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.LocalWorld; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bags.BlockBag; +import de.diddiz.LogBlock.LogBlock; public class LogBlockEditSessionFactory extends EditSessionFactory { + private LogBlock plugin; + + public LogBlockEditSessionFactory(LogBlock lb) { + this.plugin = lb; + } + @Override public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) { - return new LogBlockEditSession(world, maxBlocks, player); + return new LogBlockEditSession(world, maxBlocks, player, plugin); } @Override public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) { - return new LogBlockEditSession(world, maxBlocks, blockBag, player); + return new LogBlockEditSession(world, maxBlocks, blockBag, player, plugin); } - public static void initialize() { + public static void initialize(LogBlock logBlock) { try { // Check to see if the world edit version is compatible Class.forName("com.sk89q.worldedit.EditSessionFactory").getDeclaredMethod("getEditSession", LocalWorld.class, int.class, BlockBag.class, LocalPlayer.class); - WorldEdit.getInstance().setEditSessionFactory(new LogBlockEditSessionFactory()); - } catch (Throwable t) { + WorldEdit.getInstance().setEditSessionFactory(new LogBlockEditSessionFactory(logBlock)); + } catch (Throwable ignored) { } }