diff --git a/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java b/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java index c084953..e052dfc 100755 --- a/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java +++ b/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java @@ -25,48 +25,47 @@ public class CoreProtectEditSessionEvent { } public static void register() { - try { - if (isInitialized()) { - return; - } + if (isInitialized()) { + return; + } - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> { - try { - WorldEdit.getInstance().getEventBus().register(event); - initialized = true; - ConfigHandler.worldeditEnabled = true; - Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST)); - } - catch (Exception e) { - Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.FIRST)); - } - }, 0); + try { + WorldEdit.getInstance().getEventBus().register(event); + initialized = true; + ConfigHandler.worldeditEnabled = true; } catch (Exception e) { - e.printStackTrace(); + // Failed to initialize WorldEdit logging } + + Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> { + try { + if (isInitialized()) { + Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST)); + } + else { + Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.FIRST)); + } + } + catch (Exception e) { + e.printStackTrace(); + } + }); } public static void unregister() { - try { - if (!isInitialized()) { - return; - } + if (!isInitialized()) { + return; + } - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> { - try { - WorldEdit.getInstance().getEventBus().unregister(event); - initialized = false; - ConfigHandler.worldeditEnabled = false; - Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND)); - } - catch (Exception e) { - Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND)); - } - }, 0); + try { + WorldEdit.getInstance().getEventBus().unregister(event); + initialized = false; + ConfigHandler.worldeditEnabled = false; + Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND)); } catch (Exception e) { - e.printStackTrace(); + Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND)); } } @@ -74,7 +73,7 @@ public class CoreProtectEditSessionEvent { public void wrapForLogging(EditSessionEvent event) { Actor actor = event.getActor(); World world = event.getWorld(); - if (actor != null && event.getStage() == Stage.BEFORE_CHANGE) { + if (actor != null && event.getStage() == Stage.BEFORE_HISTORY) { event.setExtent(new CoreProtectLogger(actor, world, event.getExtent())); } } diff --git a/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java b/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java index e226000..7af48ea 100755 --- a/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java +++ b/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java @@ -6,7 +6,6 @@ import org.bukkit.inventory.ItemStack; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; @@ -34,10 +33,7 @@ public class CoreProtectLogger extends AbstractDelegateExtent { @Override public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { - if (!(eventWorld instanceof BukkitWorld)) { - return eventExtent.setBlock(position, block); - } - org.bukkit.World world = ((BukkitWorld) eventWorld).getWorld(); + org.bukkit.World world = BukkitAdapter.adapt(eventWorld); if (!Config.getConfig(world).WORLDEDIT) { return eventExtent.setBlock(position, block); }