diff --git a/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java b/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java index ccd5903..1f4b6d0 100755 --- a/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java +++ b/src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java @@ -1,49 +1,42 @@ package net.coreprotect.worldedit; +import org.bukkit.Bukkit; + import com.sk89q.worldedit.EditSession.Stage; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.event.extent.EditSessionEvent; import com.sk89q.worldedit.util.eventbus.Subscribe; + import net.coreprotect.CoreProtect; import net.coreprotect.config.ConfigHandler; import net.coreprotect.language.Phrase; import net.coreprotect.language.Selector; import net.coreprotect.thread.Scheduler; import net.coreprotect.utility.Chat; -import org.bukkit.Bukkit; -public class CoreProtectEditSessionEvent -{ +public class CoreProtectEditSessionEvent { private static boolean initialized = false; private static boolean isFAWE = false; private static CoreProtectEditSessionEvent event = new CoreProtectEditSessionEvent(); - public static boolean isInitialized() - { + public static boolean isInitialized() { return initialized; } - public static boolean isFAWE() - { + public static boolean isFAWE() { return isFAWE; } - public static void register() - { - if (isInitialized()) - { + public static void register() { + if (isInitialized()) { return; } - try - { - WorldEdit.getInstance().getEventBus().register(new Object() - { + try { + WorldEdit.getInstance().getEventBus().register(new Object() { @Subscribe - public void onEditSessionEvent(EditSessionEvent event) - { - if (event.getActor() != null && event.getStage() == Stage.BEFORE_CHANGE) - { + public void onEditSessionEvent(EditSessionEvent event) { + if (event.getActor() != null && event.getStage() == Stage.BEFORE_CHANGE) { event.setExtent(new CoreProtectLogger(event.getActor(), event.getWorld(), event.getExtent())); } } @@ -52,47 +45,37 @@ public class CoreProtectEditSessionEvent ConfigHandler.worldeditEnabled = true; isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null); } - catch (Exception e) - { + catch (Exception e) { // Failed to initialize WorldEdit logging } - Scheduler.runTask(CoreProtect.getInstance(), () -> - { - try - { - if (isInitialized()) - { + Scheduler.runTask(CoreProtect.getInstance(), () -> { + try { + if (isInitialized()) { Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST)); } - else - { + else { Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST)); } } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); } }); } - public static void unregister() - { - if (!isInitialized()) - { + public static void unregister() { + if (!isInitialized()) { return; } - try - { + try { WorldEdit.getInstance().getEventBus().unregister(event); initialized = false; ConfigHandler.worldeditEnabled = false; Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND)); } - catch (Exception e) - { + catch (Exception e) { Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND)); } } diff --git a/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java b/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java index ac49bb3..d5dc87b 100755 --- a/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java +++ b/src/main/java/net/coreprotect/worldedit/CoreProtectLogger.java @@ -1,5 +1,9 @@ package net.coreprotect.worldedit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -14,20 +18,16 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; + import net.coreprotect.config.Config; import net.coreprotect.utility.Util; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -public class CoreProtectLogger extends AbstractDelegateExtent -{ +public class CoreProtectLogger extends AbstractDelegateExtent { private final Actor eventActor; private final World eventWorld; private final Extent eventExtent; - protected CoreProtectLogger(Actor actor, World world, Extent extent) - { + protected CoreProtectLogger(Actor actor, World world, Extent extent) { super(extent); this.eventActor = actor; this.eventWorld = world; @@ -35,17 +35,13 @@ public class CoreProtectLogger extends AbstractDelegateExtent } @Override - public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException - { + public > boolean setBlock(BlockVector3 position, T block) throws WorldEditException { org.bukkit.World world = BukkitAdapter.adapt(eventWorld); - if (!Config.getConfig(world).WORLDEDIT) - { - if (CoreProtectEditSessionEvent.isFAWE()) - { + if (!Config.getConfig(world).WORLDEDIT) { + if (CoreProtectEditSessionEvent.isFAWE()) { return eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block); } - else - { + else { return eventExtent.setBlock(position, block); } } @@ -60,18 +56,14 @@ public class CoreProtectLogger extends AbstractDelegateExtent // e.g. BaseBlock block = eventWorld.getBlock(position); ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : Util.getContainerContents(oldType, null, location); - if (CoreProtectEditSessionEvent.isFAWE()) - { - if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block)) - { + if (CoreProtectEditSessionEvent.isFAWE()) { + if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block)) { WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData); return true; } } - else - { - if (eventExtent.setBlock(position, block)) - { + else { + if (eventExtent.setBlock(position, block)) { WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData); return true; } @@ -81,17 +73,14 @@ public class CoreProtectLogger extends AbstractDelegateExtent } @Override - public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException - { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { return this.setBlock(BlockVector3.at(x, y, z), block); } @Override - public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) throws MaxChangedBlocksException - { + public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) throws MaxChangedBlocksException { org.bukkit.World world = BukkitAdapter.adapt(eventWorld); - if (!Config.getConfig(world).WORLDEDIT) - { + if (!Config.getConfig(world).WORLDEDIT) { return eventExtent.replaceBlocks(region, mask, pattern); } processPatternToBlocks(world, region, pattern); @@ -99,21 +88,17 @@ public class CoreProtectLogger extends AbstractDelegateExtent } @Override - public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException - { + public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException { org.bukkit.World world = BukkitAdapter.adapt(eventWorld); - if (!Config.getConfig(world).WORLDEDIT) - { + if (!Config.getConfig(world).WORLDEDIT) { return eventExtent.setBlocks(region, pattern); } processPatternToBlocks(world, region, pattern); return eventExtent.setBlocks(region, pattern); } - private void processPatternToBlocks(org.bukkit.World world, Region region, Pattern pattern) - { - for (BlockVector3 position : region.clone()) - { + private void processPatternToBlocks(org.bukkit.World world, Region region, Pattern pattern) { + for (BlockVector3 position : region.clone()) { BlockState oldBlock = eventExtent.getBlock(position); Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType()); Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ()); @@ -126,4 +111,4 @@ public class CoreProtectLogger extends AbstractDelegateExtent WorldEditLogger.postProcess(eventExtent, eventActor, position, location, pattern.applyBlock(position), baseBlock, oldType, oldBlock, containerData); } } -} \ No newline at end of file +}