diff --git a/pom.xml b/pom.xml
index d88a1f5..8f97fd6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,7 @@
com.sk89q
worldedit
- 5.5
+ 6.0.0-SNAPSHOT
@@ -89,9 +89,6 @@
1.6
1.6
-
- **/de/diddiz/worldedit/*.java
-
diff --git a/src/main/java/de/diddiz/LogBlock/Actor.java b/src/main/java/de/diddiz/LogBlock/Actor.java
index a8311b1..19b490f 100644
--- a/src/main/java/de/diddiz/LogBlock/Actor.java
+++ b/src/main/java/de/diddiz/LogBlock/Actor.java
@@ -39,6 +39,12 @@ public class Actor {
this.UUID = UUID;
}
+
+ public Actor(String name, java.util.UUID UUID) {
+ this.name = name;
+ this.UUID = UUID.toString();
+
+ }
public Actor(String name) {
this(name, generateUUID(name));
@@ -58,7 +64,7 @@ public class Actor {
public static Actor actorFromEntity(Entity entity) {
if (entity instanceof Player) {
- return new Actor(entityName(entity),entity.getUniqueId().toString());
+ return new Actor(entityName(entity),entity.getUniqueId());
} else {
return new Actor(entityName(entity));
}
diff --git a/src/main/java/de/diddiz/LogBlock/LogBlock.java b/src/main/java/de/diddiz/LogBlock/LogBlock.java
index 322eeb1..384f3ab 100644
--- a/src/main/java/de/diddiz/LogBlock/LogBlock.java
+++ b/src/main/java/de/diddiz/LogBlock/LogBlock.java
@@ -24,7 +24,7 @@ import de.diddiz.LogBlock.listeners.StructureGrowLogging;
import de.diddiz.LogBlock.listeners.ToolListener;
import de.diddiz.LogBlock.listeners.WitherLogging;
import de.diddiz.util.MySQLConnectionPool;
-//import de.diddiz.worldedit.LogBlockEditSessionFactory;
+import de.diddiz.worldedit.WorldEditLoggingHook;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -116,9 +116,9 @@ public class LogBlock extends JavaPlugin
}
if (noDb)
return;
-// if (pm.getPlugin("WorldEdit") != null) {
-// LogBlockEditSessionFactory.initialize(this);
-// }
+ if (pm.getPlugin("WorldEdit") != null) {
+ new WorldEditLoggingHook(this).hook();
+ }
commandsHandler = new CommandsHandler(this);
getCommand("lb").setExecutor(commandsHandler);
if (enableAutoClearLog && autoClearLogDelay > 0)
diff --git a/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java b/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java
deleted file mode 100644
index ecd4156..0000000
--- a/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package de.diddiz.worldedit;
-
-import com.sk89q.worldedit.EditSession;
-import com.sk89q.worldedit.LocalPlayer;
-import com.sk89q.worldedit.LocalWorld;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.bags.BlockBag;
-import com.sk89q.worldedit.blocks.BaseBlock;
-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.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, LogBlock lb) {
- super(world, maxBlocks);
- this.player = player;
- this.plugin = lb;
- }
-
- /**
- * {@inheritDoc}
- */
- 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) || !(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) {
- 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, (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
deleted file mode 100644
index 50bf4b9..0000000
--- a/src/main/java/de/diddiz/worldedit/LogBlockEditSessionFactory.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package de.diddiz.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, plugin);
- }
-
- @Override
- public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
- return new LogBlockEditSession(world, maxBlocks, blockBag, player, plugin);
- }
-
- 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(logBlock));
- } catch (Throwable ignored) {
-
- }
- }
-
-}
diff --git a/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java b/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java
new file mode 100644
index 0000000..7acc140
--- /dev/null
+++ b/src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java
@@ -0,0 +1,114 @@
+package de.diddiz.worldedit;
+
+import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.blocks.BaseBlock;
+import com.sk89q.worldedit.bukkit.BukkitWorld;
+import com.sk89q.worldedit.event.extent.EditSessionEvent;
+//...so they ALSO have a class called Actor... need to fully-qualify when we use ours
+import com.sk89q.worldedit.extension.platform.Actor;
+import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
+import com.sk89q.worldedit.util.eventbus.Subscribe;
+import de.diddiz.LogBlock.LogBlock;
+import de.diddiz.LogBlock.Logging;
+import de.diddiz.LogBlock.config.Config;
+import java.util.logging.Level;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.Sign;
+
+public class WorldEditLoggingHook {
+
+ private LogBlock plugin;
+
+ public WorldEditLoggingHook(LogBlock plugin) {
+ this.plugin = plugin;
+ }
+
+ // Convert WE Actor to LB Actor
+ private de.diddiz.LogBlock.Actor AtoA(Actor weActor) {
+ if (weActor.isPlayer()) {
+ return new de.diddiz.LogBlock.Actor(weActor.getName(),weActor.getUniqueId());
+ }
+ return new de.diddiz.LogBlock.Actor(weActor.getName());
+ }
+
+ private World adapt(com.sk89q.worldedit.world.World weWorld) {
+ if (weWorld == null) {
+ throw new NullPointerException("[Logblock-Worldedit] The provided world was null.");
+ }
+ if (weWorld instanceof BukkitWorld) return ((BukkitWorld) weWorld).getWorld();
+ World world = Bukkit.getServer().getWorld(weWorld.getName());
+ if (world == null) throw new IllegalArgumentException("Can't find a Bukkit world for " + weWorld);
+ return world;
+ }
+
+ public void hook() {
+ WorldEdit.getInstance().getEventBus().register(new Object() {
+ @Subscribe
+ public void wrapForLogging(final EditSessionEvent event) {
+ final Actor actor = event.getActor();
+ if (actor == null ) return;
+ final de.diddiz.LogBlock.Actor lbActor = AtoA(actor);
+
+ // Check to ensure the world should be logged
+ final World world;
+ final com.sk89q.worldedit.world.World k = event.getWorld();
+ try {
+ world = adapt(k);
+ } catch (RuntimeException ex) {
+ plugin.getLogger().warning("Failed to register logging for WorldEdit!");
+ plugin.getLogger().log(Level.WARNING, ex.getMessage(),ex);
+ return;
+ }
+
+ // If config becomes reloadable, this check should be moved
+ if (!(Config.isLogging(world, Logging.WORLDEDIT))) {
+ return;
+ }
+
+ event.setExtent(new AbstractLoggingExtent(event.getExtent()) {
+ @Override
+ protected void onBlockChange(Vector pt, BaseBlock block) {
+
+ if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) {
+ return;
+ }
+
+ Location location = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
+ Block origin = location.getBlock();
+ int typeBefore = origin.getTypeId();
+ byte dataBefore = origin.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 = origin.getState();
+ }
+
+ // 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(lbActor, (Sign) stateBefore);
+ if (block.getType() != Material.AIR.getId()) {
+ plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
+ }
+ } else {
+ if (dataBefore != 0) {
+ plugin.getConsumer().queueBlockBreak(lbActor, location, typeBefore, dataBefore);
+ if (block.getType() != Material.AIR.getId()) {
+ plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
+ }
+ } else {
+ plugin.getConsumer().queueBlock(lbActor, location, typeBefore, block.getType(), (byte) block.getData());
+ }
+ }
+ }
+ });
+ }
+ });
+ }
+}