From dcd3ff31db710be2bbbf0366f14763d5a2928774 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 21 Feb 2021 00:04:56 +0100 Subject: [PATCH] Fix WorldEdit integration stopping edits It's been only more than a year, it's fine --- .../minecraft/limitedcreative/Hooks.java | 9 +-- .../limitedcreative/ModInventories.java | 1 - .../blockstate/BlockStateCommand.java | 65 +++++++++---------- .../worldedit/EditSessionExtent.java | 9 +-- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java index 4e4e7e1..c7386a6 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Hooks.java @@ -1,13 +1,12 @@ package de.jaschastarke.minecraft.limitedcreative; -import org.bukkit.Bukkit; - import de.jaschastarke.hooking.BooleanHooker; import de.jaschastarke.hooking.GetHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.MultiVerseHooks; import de.jaschastarke.minecraft.limitedcreative.hooks.PlayerCheckHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.WorldTypeHooker; import de.jaschastarke.minecraft.limitedcreative.hooks.xAuthHooks; +import org.bukkit.Bukkit; public final class Hooks { public static PlayerCheckHooker IsLoggedIn = new PlayerCheckHooker(true); @@ -53,7 +52,8 @@ public final class Hooks { public static boolean isAuthMePresent() { if (isPluginEnabled("AuthMe")) { try { - return Class.forName("uk.org.whoami.authme.api.API") != null; + Class.forName("uk.org.whoami.authme.api.API"); + return true; } catch (ClassNotFoundException e) { return false; } @@ -64,7 +64,8 @@ public final class Hooks { public static boolean isXAuth20Present() { if (isPluginEnabled("xAuth")) { try { - return Class.forName("com.cypherx.xauth.xAuth") != null; + Class.forName("com.cypherx.xauth.xAuth"); + return true; } catch (ClassNotFoundException e) { return false; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java index 80680d8..a360f4d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java @@ -28,7 +28,6 @@ public class ModInventories extends CoreModule { return "Inventory"; } - @SuppressWarnings("deprecation") @Override public void initialize(ModuleEntry entry) { super.initialize(entry); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java index f32358f..f7b5343 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateCommand.java @@ -166,44 +166,41 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed { final BlockVector3 min = selection.getMinimumPoint(); final BlockVector3 max = selection.getMaximumPoint(); - - mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new Runnable() { - @Override - public void run() { - if (mod.isDebug()) - mod.getLog().debug("Scheduler: Asynchronous Task run"); - DBTransaction update = mod.getModel().groupUpdate(); - int count = 0; - World w = selection.getWorld(); - assert w != null; - org.bukkit.World bw = BukkitAdapter.adapt(w); - - Cuboid c = new Cuboid(); - c.add(new Location(bw, min.getBlockX(), min.getBlockY(), min.getBlockZ())); - c.add(new Location(bw, max.getBlockX(), max.getBlockY(), max.getBlockZ())); - mod.getModel().cacheStates(c); - - BlockState seed = new BlockState(); - seed.setPlayer(context.getPlayer()); - seed.setGameMode(tgm); - seed.setSource(Source.COMMAND); - seed.setDate(new Date()); - for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { - for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { - for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { - BlockVector3 loc = BlockVector3.at(x, y, z); - if (!w.getBlock(loc).getBlockType().getMaterial().isAir() && selection.contains(loc)) { - seed.setLocation(new Location(bw, x, y, z)); - update.setState(new BlockState(seed)); - count++; - } + + mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), () -> { + if (mod.isDebug()) + mod.getLog().debug("Scheduler: Asynchronous Task run"); + DBTransaction update = mod.getModel().groupUpdate(); + int count = 0; + World w = selection.getWorld(); + assert w != null; + org.bukkit.World bw = BukkitAdapter.adapt(w); + + Cuboid c = new Cuboid(); + c.add(new Location(bw, min.getBlockX(), min.getBlockY(), min.getBlockZ())); + c.add(new Location(bw, max.getBlockX(), max.getBlockY(), max.getBlockZ())); + mod.getModel().cacheStates(c); + + BlockState seed = new BlockState(); + seed.setPlayer(context.getPlayer()); + seed.setGameMode(tgm); + seed.setSource(Source.COMMAND); + seed.setDate(new Date()); + for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { + for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { + for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { + BlockVector3 loc = BlockVector3.at(x, y, z); + if (!w.getBlock(loc).getBlockType().getMaterial().isAir() && selection.contains(loc)) { + seed.setLocation(new Location(bw, x, y, z)); + update.setState(new BlockState(seed)); + count++; } } } - update.finish(); - - context.response(L("command.blockstate.command_updated", count)); } + update.finish(); + + context.response(L("command.blockstate.command_updated", count)); }); return true; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java index e93aea7..54231d6 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/worldedit/EditSessionExtent.java @@ -18,7 +18,7 @@ public class EditSessionExtent extends AbstractDelegateExtent { private ModBlockStates mod; private Player player = null; private World world; - + public EditSessionExtent(Extent extent, ModBlockStates mod, Player player, World world) { super(extent); this.mod = mod; @@ -29,13 +29,13 @@ public class EditSessionExtent extends AbstractDelegateExtent { /** * Called when a block is being changed. * - * @param pt the position + * @param pt the position * @param newBlock the new block to replace the old one */ @Override public > boolean setBlock(BlockVector3 pt, T newBlock) throws WorldEditException { if (mod.isDebug()) - mod.getLog().debug("WorldEdit-Integration: BlockChange: "+pt.toString()+" BB: " + newBlock.toString()); + mod.getLog().debug("WorldEdit-Integration: BlockChange: " + pt.toString() + " BB: " + newBlock.toString()); Location loc = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (newBlock.getBlockType().getMaterial().isAir()) { mod.getModel().removeState(loc.getBlock()); @@ -51,9 +51,10 @@ public class EditSessionExtent extends AbstractDelegateExtent { s.setSource(Source.EDIT); if (mod.isDebug()) mod.getLog().debug("WorldEdit-Integration: Saving BlockState: " + s.toString()); - + mod.getModel().setState(s); } + super.setBlock(pt, newBlock); return true; } }