From cba12d584d861fba426c39ac2ba568e6c74d3023 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 23 Feb 2015 16:29:45 +1100 Subject: [PATCH] Added event system --- .../intellectualcrafters/plot/BukkitMain.java | 40 +- .../intellectualcrafters/plot/IPlotMain.java | 9 +- .../plot/PlotSquared.java | 9 +- .../plot/commands/Claim.java | 12 +- .../plot/commands/Debug.java | 3 - .../plot/commands/DebugClaimTest.java | 14 +- .../plot/commands/DebugClear.java | 6 +- .../plot/commands/Denied.java | 5 +- .../plot/commands/Helpers.java | 5 +- .../plot/commands/Merge.java | 7 +- .../plot/commands/RegenAllRoads.java | 4 +- .../plot/commands/Swap.java | 4 +- .../plot/commands/Trim.java | 14 +- .../plot/commands/Trusted.java | 5 +- .../plot/commands/Unlink.java | 6 +- .../plot/events/PlayerClaimPlotEvent.java | 1 - .../plot/events/PlotDeleteEvent.java | 13 +- .../plot/flag/FlagManager.java | 11 +- .../plot/generator/AugmentedPopulator.java | 16 +- .../plot/generator/BukkitHybridUtils.java | 8 +- .../plot/generator/ClassicPlotManager.java | 17 +- .../plot/generator/HybridGen.java | 6 +- .../plot/generator/HybridPop.java | 6 +- .../plot/generator/HybridUtils.java | 4 +- .../plot/generator/SquarePlotManager.java | 4 +- .../plot/object/PseudoRandom.java | 26 + .../plot/util/BlockManager.java | 25 +- .../plot/util/BlockUpdateUtil.java | 12 + .../plot/util/ChunkManager.java | 39 + .../plot/util/ClusterManager.java | 4 +- .../plot/util/EventUtil.java | 42 + .../plot/util/ExpireManager.java | 9 +- .../plot/util/MainUtil.java | 21 +- .../plot/util/bukkit/BukkitChunkManager.java | 769 ++++++++++++++++++ .../plot/util/bukkit/BukkitEventUtil.java | 111 +++ .../util/bukkit/BukkitSetBlockManager.java | 28 + .../plot/util/bukkit/BukkitUtil.java | 8 +- .../plot/util/bukkit/PWE.java | 17 +- .../plot/util/bukkit/SetBlockFast.java | 2 +- .../plot/util/bukkit/SetBlockFast_1_8.java | 2 +- .../plot/util/bukkit/SetBlockSlow.java | 2 +- 41 files changed, 1180 insertions(+), 166 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitEventUtil.java create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 7bae4e1dd..e66a44e75 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -39,22 +39,24 @@ import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; -import com.intellectualcrafters.plot.util.AChunkManager; -import com.intellectualcrafters.plot.util.AbstractSetBlock; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.BlockUpdateUtil; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ConsoleColors; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils; import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.ChunkManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; import com.intellectualcrafters.plot.util.bukkit.Metrics; import com.intellectualcrafters.plot.util.bukkit.SendChunk; import com.intellectualcrafters.plot.util.bukkit.SetBlockFast; import com.intellectualcrafters.plot.util.bukkit.SetBlockFast_1_8; -import com.intellectualcrafters.plot.util.bukkit.SetBlockManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.SetBlockSlow; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; @@ -260,19 +262,19 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public BlockManager initBlockManager() { if (checkVersion(1, 8, 0)) { try { - SetBlockManager.setBlockManager = new SetBlockFast_1_8(); + BukkitSetBlockManager.setBlockManager = new SetBlockFast_1_8(); } catch (final Throwable e) { e.printStackTrace(); - SetBlockManager.setBlockManager = new SetBlockSlow(); + BukkitSetBlockManager.setBlockManager = new SetBlockSlow(); } } else { try { - SetBlockManager.setBlockManager = new SetBlockFast(); + BukkitSetBlockManager.setBlockManager = new SetBlockFast(); } catch (final Throwable e) { - SetBlockManager.setBlockManager = new SetBlockSlow(); + BukkitSetBlockManager.setBlockManager = new SetBlockSlow(); } } - AbstractSetBlock.setBlockManager = SetBlockManager.setBlockManager; + BlockUpdateUtil.setBlockManager = BukkitSetBlockManager.setBlockManager; try { new SendChunk(); MainUtil.canSendChunk = true; @@ -305,17 +307,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } } - @Override - public boolean callRemovePlot(final String world, final PlotId id) { - final PlotDeleteEvent event = new PlotDeleteEvent(world, id); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - event.setCancelled(true); - return false; - } - return true; - } - @Override public HybridUtils initHybridUtils() { return new BukkitHybridUtils(); @@ -355,7 +346,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } @Override - public AChunkManager initChunkManager() { - return new ChunkManager(); + public ChunkManager initChunkManager() { + return new BukkitChunkManager(); + } + + @Override + public EventUtil initEventUtil() { + return new BukkitEventUtil(); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index eebc86696..3e945f4ba 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -6,8 +6,9 @@ import net.milkbowl.vault.economy.Economy; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -40,8 +41,10 @@ public interface IPlotMain { public Economy getEconomy(); public BlockManager initBlockManager(); + + public EventUtil initEventUtil(); - public AChunkManager initChunkManager(); + public ChunkManager initChunkManager(); public SetupUtils initSetupUtils(); @@ -52,6 +55,4 @@ public interface IPlotMain { public boolean initPlotMeConverter(); public void getGenerator(String world, String name); - - public boolean callRemovePlot(String world, PlotId id); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 97687329f..b61567a35 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -49,9 +49,10 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ClusterManager; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.ExpireManager; import com.intellectualcrafters.plot.util.Logger; import com.intellectualcrafters.plot.util.Logger.LogLevel; @@ -204,7 +205,7 @@ public class PlotSquared { } public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) { - // FIXME plot remove event + EventUtil.manager.callDelete(world, id); plots.get(world).remove(id); if (MainUtil.lastPlot.containsKey(world)) { final PlotId last = MainUtil.lastPlot.get(world); @@ -436,6 +437,8 @@ public class PlotSquared { IMP.registerWorldEditEvents(); // create UUIDWrapper UUIDHandler.uuidWrapper = IMP.initUUIDHandler(); + // create event util class + EventUtil.manager = IMP.initEventUtil(); // create Hybrid utility class HybridUtils.manager = IMP.initHybridUtils(); // create setup util class @@ -443,7 +446,7 @@ public class PlotSquared { // Set block BlockManager.manager = IMP.initBlockManager(); // Set chunk - AChunkManager.manager = IMP.initChunkManager(); + ChunkManager.manager = IMP.initChunkManager(); // PlotMe TaskManager.runTaskLater(new Runnable() { @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 10b744d57..1d3d154b9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -27,6 +27,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; @@ -47,13 +48,8 @@ public class Claim extends SubCommand { if (plot.hasOwner() || plot.settings.isMerged()) { return false; } - // FIXME claim plot event - // final PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, auto); - // Bukkit.getPluginManager().callEvent(event); - // boolean result = event.isCancelled(); - final boolean result = false; - - if (!result) { + final boolean result = EventUtil.manager.callClaim(player, plot, false); + if (result) { MainUtil.createPlot(player.getUUID(), plot); MainUtil.setSign(player.getName(), plot); MainUtil.sendMessage(player, C.CLAIMED); @@ -79,7 +75,7 @@ public class Claim extends SubCommand { PlotSquared.getPlotManager(world).claimPlot(plotworld, plot); MainUtil.update(loc); } - return !result; + return result; } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java index e14bfd1ca..a443c7473 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Debug.java @@ -55,9 +55,6 @@ public class Debug extends SubCommand { for (final String world : PlotSquared.getPlotWorlds()) { worlds.append(world).append(" "); } - - // FIXME not sure if we actually need any of this debug info as we should just do a timings report which is more detailed anyway - information.append(header); information.append(getSection(section, "Lag / TPS")); information.append(getLine(line, "Ticks Per Second", Lag.getTPS())); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 08b6b3303..45e134a1c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -35,8 +35,9 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -53,11 +54,8 @@ public class DebugClaimTest extends SubCommand { } public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) { - // FIXME call claim event - // boolean result = event result - final boolean result = true; - - if (!result) { + final boolean result = EventUtil.manager.callClaim(player, plot, false); + if (result) { MainUtil.createPlot(player.getUUID(), plot); MainUtil.setSign(player.getName(), plot); MainUtil.sendMessage(player, C.CLAIMED); @@ -65,7 +63,7 @@ public class DebugClaimTest extends SubCommand { MainUtil.teleportPlayer(player, player.getLocation(), plot); } } - return result; + return !result; } @Override @@ -101,7 +99,7 @@ public class DebugClaimTest extends SubCommand { } final Location loc = manager.getSignLoc(plotworld, plot); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); - final boolean result = AChunkManager.manager.loadChunk(world, chunk); + final boolean result = ChunkManager.manager.loadChunk(world, chunk); if (!result) { continue; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java index 1365ba7b8..509106be0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClear.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -63,7 +63,7 @@ public class DebugClear extends SubCommand { return false; } MainUtil.runners.put(plot, 1); - AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { + ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { @Override public void run() { MainUtil.runners.remove(plot); @@ -96,7 +96,7 @@ public class DebugClear extends SubCommand { return false; } MainUtil.runners.put(plot, 1); - AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { + ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { @Override public void run() { MainUtil.runners.remove(plot); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java index 5153aad5a..168b6b8a7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Denied.java @@ -28,6 +28,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -82,7 +83,7 @@ public class Denied extends SubCommand { } plot.addDenied(uuid); DBFunc.setDenied(loc.getWorld(), plot, uuid); - //FIXME PlayerPlotDeniedEvent + EventUtil.manager.callDenied(plr, plot, uuid, true); } else { MainUtil.sendMessage(plr, C.ALREADY_ADDED); return false; @@ -112,7 +113,7 @@ public class Denied extends SubCommand { final UUID uuid = UUIDHandler.getUUID(args[1]); plot.removeDenied(uuid); DBFunc.removeDenied(loc.getWorld(), plot, uuid); - // FIXME PlayerPlotDeniedEvent + EventUtil.manager.callDenied(plr, plot, uuid, false); MainUtil.sendMessage(plr, C.DENIED_REMOVED); } else { MainUtil.sendMessage(plr, C.DENIED_NEED_ARGUMENT); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java index 32044c4e9..3f3b6573c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Helpers.java @@ -27,6 +27,7 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -81,7 +82,7 @@ public class Helpers extends SubCommand { } plot.addHelper(uuid); DBFunc.setHelper(loc.getWorld(), plot, uuid); - // FIXME PlayerPlotHelperEvent + EventUtil.manager.callHelper(plr, plot, uuid, true); } else { MainUtil.sendMessage(plr, C.ALREADY_ADDED); return false; @@ -103,7 +104,7 @@ public class Helpers extends SubCommand { final UUID uuid = UUIDHandler.getUUID(args[1]); plot.removeHelper(uuid); DBFunc.removeHelper(loc.getWorld(), plot, uuid); - // FIXME PlayerPlotHelperEvent + EventUtil.manager.callHelper(plr, plot, uuid, false); MainUtil.sendMessage(plr, C.HELPER_REMOVED); } else { MainUtil.sendMessage(plr, C.HELPER_NEED_ARGUMENT); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 54b7df308..78874b1a6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -32,6 +32,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -151,10 +152,8 @@ public class Merge extends SubCommand { sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } - //FIXME PlotMergeEvent - // boolean result = event.isCancelled(); - final boolean result = false; - if (result) { + final boolean result = EventUtil.manager.callMerge(world, plot, plots); + if (!result) { MainUtil.sendMessage(plr, "&cMerge has been cancelled"); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java index 0556eab54..7107f4ada 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java @@ -29,7 +29,7 @@ import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; public class RegenAllRoads extends SubCommand { public RegenAllRoads() { @@ -52,7 +52,7 @@ public class RegenAllRoads extends SubCommand { sendMessage(player, C.NOT_VALID_PLOT_WORLD); return false; } - final List chunks = AChunkManager.manager.getChunkChunks(name); + final List chunks = ChunkManager.manager.getChunkChunks(name); PlotSquared.log("&cIf no schematic is set, the following will not do anything"); PlotSquared.log("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic"); PlotSquared.log("&6Potential chunks to update: &7" + (chunks.size() * 1024)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java index 1ca9fba1e..acac040e7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -27,7 +27,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -83,7 +83,7 @@ public class Swap extends SubCommand { MainUtil.sendMessage(plr, C.SWAP_SYNTAX); return false; } - AChunkManager.manager.swap(world, plot.id, plotid); + ChunkManager.manager.swap(world, plot.id, plotid); // FIXME Requires testing!! DBFunc.dbManager.swapPlots(plot, MainUtil.getPlot(world, plotid)); MainUtil.sendMessage(plr, C.SWAP_SUCCESS); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index c626953bf..1a2a805f2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -35,7 +35,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; @@ -168,7 +168,7 @@ public class Trim extends SubCommand { sendMessage("Collecting region data..."); final ArrayList plots = new ArrayList<>(); plots.addAll(PlotSquared.getPlots(world).values()); - final HashSet chunks = new HashSet<>(AChunkManager.manager.getChunkChunks(world)); + final HashSet chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world)); sendMessage(" - MCA #: " + chunks.size()); sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)"); sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes"); @@ -190,10 +190,10 @@ public class Trim extends SubCommand { final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); final Location pos3 = new Location(world, pos1.getX(), 64, pos2.getZ()); final Location pos4 = new Location(world, pos2.getX(), 64, pos1.getZ()); - chunks.remove(AChunkManager.getChunkChunk(pos1)); - chunks.remove(AChunkManager.getChunkChunk(pos2)); - chunks.remove(AChunkManager.getChunkChunk(pos3)); - chunks.remove(AChunkManager.getChunkChunk(pos4)); + chunks.remove(ChunkManager.getChunkChunk(pos1)); + chunks.remove(ChunkManager.getChunkChunk(pos2)); + chunks.remove(ChunkManager.getChunkChunk(pos3)); + chunks.remove(ChunkManager.getChunkChunk(pos4)); } } }, 20); @@ -205,7 +205,7 @@ public class Trim extends SubCommand { public static void deleteChunks(final String world, final ArrayList chunks) { for (final ChunkLoc loc : chunks) { - AChunkManager.manager.deleteRegionFile(world, loc); + ChunkManager.manager.deleteRegionFile(world, loc); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java index 79378c179..38ebc32aa 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Trusted.java @@ -27,6 +27,7 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -82,7 +83,7 @@ public class Trusted extends SubCommand { } plot.addTrusted(uuid); DBFunc.setTrusted(loc.getWorld(), plot, uuid); - // FIXME PlayerPlotTrustedEvent + EventUtil.manager.callTrusted(plr, plot, uuid, true); } else { MainUtil.sendMessage(plr, C.ALREADY_ADDED); return false; @@ -104,7 +105,7 @@ public class Trusted extends SubCommand { final UUID uuid = UUIDHandler.getUUID(args[1]); plot.removeTrusted(uuid); DBFunc.removeTrusted(loc.getWorld(), plot, uuid); - // FIXME PlayerPlotTrustedEvent + EventUtil.manager.callTrusted(plr, plot, uuid, false); MainUtil.sendMessage(plr, C.TRUSTED_REMOVED); } else { MainUtil.sendMessage(plr, C.TRUSTED_NEED_ARGUMENT); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index 9654b709e..cb99409f8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -72,7 +73,10 @@ public class Unlink extends SubCommand { final PlotId pos1 = MainUtil.getBottomPlot(plot).id; final PlotId pos2 = MainUtil.getTopPlot(plot).id; final ArrayList ids = MainUtil.getPlotSelectionIds(pos1, pos2); - // FIXME PlotUnlinkEvent (cancellable) + final boolean result = EventUtil.manager.callUnlink(world, ids); + if (!result) { + return false; + } final PlotManager manager = PlotSquared.getPlotManager(world); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); manager.startPlotUnlink(plotworld, ids); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java index 3be47e9ec..89a0b39ed 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java @@ -31,7 +31,6 @@ import com.intellectualcrafters.plot.object.Plot; * @author Citymonstret * @author Empire92 */ -@SuppressWarnings("unused") public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable { private static HandlerList handlers = new HandlerList(); private final Plot plot; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java index e49ddae35..b1aef9342 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/events/PlotDeleteEvent.java @@ -32,11 +32,10 @@ import com.intellectualcrafters.plot.object.PlotId; * @author Citymonstret * @author Empire92 */ -public class PlotDeleteEvent extends Event implements Cancellable { +public class PlotDeleteEvent extends Event { private static HandlerList handlers = new HandlerList(); private final PlotId id; private final String world; - private boolean cancelled; /** * PlotDeleteEvent: Called when a plot is deleted @@ -75,14 +74,4 @@ public class PlotDeleteEvent extends Event implements Cancellable { public HandlerList getHandlers() { return handlers; } - - @Override - public boolean isCancelled() { - return this.cancelled; - } - - @Override - public void setCancelled(final boolean b) { - this.cancelled = b; - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 828ce4227..dfd8b7cf0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.EventUtil; /** * Flag Manager Utility @@ -137,7 +138,10 @@ public class FlagManager { * @param flag */ public static boolean addPlotFlag(final Plot plot, final Flag flag) { - // FIXME PlotFlagAddEvent + final boolean result = EventUtil.manager.callFlagAdd(flag, plot); + if (!result) { + return false; + } final Flag hasFlag = getPlotFlag(plot, flag.getKey()); if (hasFlag != null) { plot.settings.flags.remove(hasFlag); @@ -189,7 +193,10 @@ public class FlagManager { if (hasFlag != null) { final Flag flagObj = FlagManager.getPlotFlagAbs(plot, flag); if (flagObj != null) { - // FIXME PlotFlagRemoveEvent + final boolean result = EventUtil.manager.callFlagRemove(flagObj, plot); + if (!result) { + return false; + } plot.settings.flags.remove(hasFlag); DBFunc.setFlags(plot.world, plot, plot.settings.flags); return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java index dfe66821f..b43c12f79 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -19,10 +19,10 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.bukkit.ChunkManager; -import com.intellectualcrafters.plot.util.bukkit.SetBlockManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; public class AugmentedPopulator extends BlockPopulator { public final PlotWorld plotworld; @@ -130,7 +130,7 @@ public class AugmentedPopulator extends BlockPopulator { public void run() { populateBiome(world, x, z); chunk.unload(true, true); - SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); + BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); } }, 20); } else { @@ -146,7 +146,7 @@ public class AugmentedPopulator extends BlockPopulator { chunk.load(true); populateBlocks(world, rand, X, Z, x, z, check); chunk.unload(true, true); - SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); + BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); } }, 40 + rand.nextInt(40)); } @@ -175,15 +175,15 @@ public class AugmentedPopulator extends BlockPopulator { final int xx = x + blockInfo.x; final int zz = z + blockInfo.z; if (this.p) { - if (AChunkManager.CURRENT_PLOT_CLEAR != null) { - if (ChunkManager.isIn(AChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) { + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) { continue; } } else if (this.manager.getPlotIdAbs(this.plotworld, xx, 0, zz) != null) { continue; } } - SetBlockManager.setBlockManager.set(world, xx, blockInfo.y, zz, blockInfo.id, (byte) 0); + BukkitSetBlockManager.setBlockManager.set(world, xx, blockInfo.y, zz, blockInfo.id, (byte) 0); } } for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java index 279ac4bdf..3eea75c01 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -14,9 +14,9 @@ import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.SetBlockManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; public class BukkitHybridUtils extends HybridUtils { @@ -87,7 +87,7 @@ public class BukkitHybridUtils extends HybridUtils { regenerateRoad(worldname, new ChunkLoc(x, z)); } } - SetBlockManager.setBlockManager.update(chunks2); + BukkitSetBlockManager.setBlockManager.update(chunks2); } private static boolean UPDATE = false; @@ -98,7 +98,7 @@ public class BukkitHybridUtils extends HybridUtils { if (BukkitHybridUtils.UPDATE) { return false; } - final List chunks = AChunkManager.manager.getChunkChunks(world); + final List chunks = ChunkManager.manager.getChunkChunks(world); final Plugin plugin = BukkitMain.THIS; this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index 68f1f146a..a69f0a949 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -7,6 +7,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; @@ -64,7 +65,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } } @@ -74,7 +75,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } } @@ -84,7 +85,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } } @@ -94,7 +95,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } } @@ -123,7 +124,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } x = top.getX(); @@ -131,7 +132,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } z = top.getZ(); @@ -139,7 +140,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } x = bottom.getX(); @@ -147,7 +148,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { xl[i] = x; zl[i] = z; yl[i] = y; - bl[i] = blocks[BlockManager.random(blocks.length)]; + bl[i] = blocks[PseudoRandom.random(blocks.length)]; i++; } BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 3e290cff8..7a4fcf5f5 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -37,7 +37,7 @@ import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; /** * The default generator is very messy, as we have decided to try externalize all calculations from within the loop. - @@ -241,7 +241,7 @@ public class HybridGen extends PlotGenerator { } } } - final RegionWrapper plot = AChunkManager.CURRENT_PLOT_CLEAR; + final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR; if (plot != null) { final int X = cx << 4; final int Z = cz << 4; @@ -265,7 +265,7 @@ public class HybridGen extends PlotGenerator { setBlock(this.result, x, this.plotheight, z, this.plotfloors); } else { final ChunkLoc loc = new ChunkLoc(X + x, Z + z); - final HashMap blocks = AChunkManager.GENERATE_BLOCKS.get(loc); + final HashMap blocks = ChunkManager.GENERATE_BLOCKS.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { setBlock(this.result, x, y, z, blocks.get(y).shortValue()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java index 0b9b8b6d4..33ff0691c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java @@ -12,7 +12,7 @@ import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; /** * @author Citymonstret @@ -117,7 +117,7 @@ public class HybridPop extends BlockPopulator { this.X = cx << 4; this.Z = cz << 4; PlotSquared.getPlotManager(w.getName()); - final RegionWrapper plot = AChunkManager.CURRENT_PLOT_CLEAR; + final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR; if (plot != null) { short sx = (short) ((this.X) % this.size); short sz = (short) ((this.Z) % this.size); @@ -140,7 +140,7 @@ public class HybridPop extends BlockPopulator { } } else { final ChunkLoc loc = new ChunkLoc(this.X + x, this.Z + z); - final HashMap data = AChunkManager.GENERATE_DATA.get(loc); + final HashMap data = ChunkManager.GENERATE_DATA.get(loc); if (data != null) { for (final short y : data.keySet()) { setBlock(w, x, y, z, data.get(y).byteValue()); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index 989558b58..b31cd43d1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -11,7 +11,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SchematicHandler; @@ -102,7 +102,7 @@ public abstract class HybridUtils { final PlotId id2 = manager.getPlotId(plotworld, ex, 0, ez); boolean toCheck = false; if ((id1 == null) || (id2 == null) || (id1 != id2)) { - final boolean result = AChunkManager.manager.loadChunk(world, chunk); + final boolean result = ChunkManager.manager.loadChunk(world, chunk); if (result) { if (id1 != null) { final Plot p1 = MainUtil.getPlot(world, id1); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 89601effa..5574ddbdd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -5,7 +5,7 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.AChunkManager; +import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; @@ -17,7 +17,7 @@ public abstract class SquarePlotManager extends GridPlotManager { public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final boolean isDelete, final Runnable whenDone) { final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id); - AChunkManager.manager.regenerateRegion(pos1, pos2, whenDone); + ChunkManager.manager.regenerateRegion(pos1, pos2, whenDone); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java new file mode 100644 index 000000000..17190cefe --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PseudoRandom.java @@ -0,0 +1,26 @@ +package com.intellectualcrafters.plot.object; + +public class PseudoRandom { + private static long state = 1; + + public static long nextLong() { + final long a = state; + state = xorShift64(a); + return a; + } + + public static long xorShift64(long a) { + a ^= (a << 21); + a ^= (a >>> 35); + a ^= (a << 4); + return a; + } + + public static int random(final int n) { + if (n == 1) { + return 0; + } + final long r = ((nextLong() >>> 32) * n) >> 32; + return (int) r; + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java index 104d0c2c3..9b372b980 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java @@ -2,31 +2,10 @@ package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PseudoRandom; public abstract class BlockManager { public static BlockManager manager; - private static long state = 1; - - public static long nextLong() { - final long a = state; - state = xorShift64(a); - return a; - } - - public static long xorShift64(long a) { - a ^= (a << 21); - a ^= (a >>> 35); - a ^= (a << 4); - return a; - } - - public static int random(final int n) { - if (n == 1) { - return 0; - } - final long r = ((nextLong() >>> 32) * n) >> 32; - return (int) r; - } public abstract String[] getBiomeList(); @@ -61,7 +40,7 @@ public abstract class BlockManager { final byte[] data = new byte[blocks.length]; for (int i = 0; i < blocks.length; i++) { final PlotBlock[] current = blocks[i]; - final int n = random(current.length); + final int n = PseudoRandom.random(current.length); id[i] = current[n].id; data[i] = current[n].data; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java new file mode 100644 index 000000000..40fca502f --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java @@ -0,0 +1,12 @@ +package com.intellectualcrafters.plot.util; + +import java.util.List; + +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; + +public abstract class BlockUpdateUtil { + public static BlockUpdateUtil setBlockManager = null; + + public abstract void update(String worldname, List chunkLocs); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java new file mode 100644 index 000000000..6e139e6e4 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -0,0 +1,39 @@ +package com.intellectualcrafters.plot.util; + +import java.util.HashMap; +import java.util.List; + +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.RegionWrapper; + +public abstract class ChunkManager { + public static ChunkManager manager = null; + public static RegionWrapper CURRENT_PLOT_CLEAR = null; + public static HashMap> GENERATE_BLOCKS = new HashMap<>(); + public static HashMap> GENERATE_DATA = new HashMap<>(); + + public static ChunkLoc getChunkChunk(final Location loc) { + final int x = loc.getX() >> 9; + final int z = loc.getZ() >> 9; + return new ChunkLoc(x, z); + } + + public abstract boolean loadChunk(String world, ChunkLoc loc); + + public abstract List getChunkChunks(String world); + + public abstract void deleteRegionFile(final String world, final ChunkLoc loc); + + public abstract Plot hasPlot(String world, ChunkLoc chunk); + + public abstract boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone); + + public abstract boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone); + + public abstract void clearAllEntities(final Plot plot); + + public abstract void swap(String world, PlotId id, PlotId plotid); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index bf3edc131..5f6112ab1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -24,7 +24,7 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -import com.intellectualcrafters.plot.util.bukkit.SetBlockManager; +import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class ClusterManager { @@ -277,7 +277,7 @@ public class ClusterManager { @Override public void run() { if ((populator == null) || (plotworld.TYPE == 0)) { - SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); + BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); world.regenerateChunk(chunk.getX(), chunk.getZ()); chunk.unload(true, true); } else { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java new file mode 100644 index 000000000..6543b7c05 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -0,0 +1,42 @@ +package com.intellectualcrafters.plot.util; + +import java.util.ArrayList; +import java.util.UUID; + + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; + +public abstract class EventUtil { + + public static EventUtil manager = null; + + public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto); + + public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot); + + public abstract boolean callClear(final String world, final PlotId id); + + public abstract void callDelete(final String world, final PlotId id); + + public abstract boolean callFlagAdd(final Flag flag, final Plot plot); + + public abstract boolean callFlagRemove(final Flag flag, final Plot plot); + + public abstract boolean callMerge(final String world, final Plot plot, final ArrayList plots); + + public abstract boolean callUnlink(final String world, final ArrayList plots); + + public abstract void callEntry(final PlotPlayer player, final Plot plot); + + public abstract void callLeave(final PlotPlayer player, final Plot plot); + + public abstract void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added); + + public abstract void callHelper(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added); + + public abstract void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added); +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index 4ea467c31..2a021a67e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -97,10 +97,6 @@ public class ExpireManager { } final PlotDeleteEvent event = new PlotDeleteEvent(world, plot.id); Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - event.setCancelled(true); - return; - } for (final UUID helper : plot.helpers) { final PlotPlayer player = UUIDHandler.getPlayer(helper); if (player != null) { @@ -108,6 +104,11 @@ public class ExpireManager { } } final PlotManager manager = PlotSquared.getPlotManager(world); + if (manager == null) { + PlotSquared.log("&cThis is a friendly reminder to create or delete " + world +" as it is currently setup incorrectly"); + expiredPlots.get(world).remove(plot); + return; + } if (plot.settings.isMerged()) { Unlink.unlinkPlot(plot); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 82aecd3ac..577265e79 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotSettings; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.SendChunk; @@ -99,7 +100,8 @@ public class MainUtil { // TODO // boolean result = PlotSquared.IMP.callPlayerTeleportToPlotEvent(player, from, plot); - final boolean result = true; + + final boolean result = false; // TOOD ^ remove that if (!result) { @@ -163,7 +165,7 @@ public class MainUtil { chunks.add(chunk); } } - AbstractSetBlock.setBlockManager.update(world, chunks); + BlockUpdateUtil.setBlockManager.update(world, chunks); } public static void createWorld(final String world, final String generator) { @@ -230,7 +232,10 @@ public class MainUtil { final PlotManager manager = PlotSquared.getPlotManager(world); final PlotWorld plotworld = PlotSquared.getPlotWorld(world); - // FIXME call event + boolean result = EventUtil.manager.callMerge(world, getPlot(world, pos1), plotIds); + if (!result) { + return false; + } manager.startPlotMerge(plotworld, plotIds); for (int x = pos1.x; x <= pos2.x; x++) { @@ -483,7 +488,7 @@ public class MainUtil { if (runners.containsKey(plot)) { return false; } - AChunkManager.manager.clearAllEntities(plot); + ChunkManager.manager.clearAllEntities(plot); clear(plot.world, plot, isDelete, whenDone); removeSign(plot); return true; @@ -503,7 +508,7 @@ public class MainUtil { runners.put(plot, 1); if (plotworld.TERRAIN != 0) { final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); - AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { + ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { @Override public void run() { runners.remove(plot); @@ -539,7 +544,7 @@ public class MainUtil { for (int y = pos1.getY(); y < pos2.getY(); y++) { for (int x = pos1.getX(); x < pos2.getX(); x++) { for (int z = pos1.getZ(); z < pos2.getZ(); z++) { - final int i = BlockManager.random(blocks.length); + final int i = PseudoRandom.random(blocks.length); xl[index] = x; yl[index] = y; zl[index] = z; @@ -811,11 +816,11 @@ public class MainUtil { plot.id.y += offset_y; PlotSquared.getPlots(world).put(plot.id, plot); } - AChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() { + ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() { @Override public void run() { final Location bot = bot1.clone().add(1, 0, 1); - AChunkManager.manager.regenerateRegion(bot, top, null); + ChunkManager.manager.regenerateRegion(bot, top, null); TaskManager.runTaskLater(whenDone, 1); } }); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java new file mode 100644 index 000000000..9622f2f19 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java @@ -0,0 +1,769 @@ +package com.intellectualcrafters.plot.util.bukkit; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +import org.apache.commons.lang.mutable.MutableInt; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.Note; +import org.bukkit.SkullType; +import org.bukkit.World; +import org.bukkit.block.Banner; +import org.bukkit.block.Beacon; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.BrewingStand; +import org.bukkit.block.Chest; +import org.bukkit.block.CommandBlock; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.block.Dispenser; +import org.bukkit.block.Dropper; +import org.bukkit.block.Furnace; +import org.bukkit.block.Hopper; +import org.bukkit.block.Jukebox; +import org.bukkit.block.NoteBlock; +import org.bukkit.block.Sign; +import org.bukkit.block.Skull; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import com.intellectualcrafters.plot.BukkitMain; +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.listeners.PlotListener; +import com.intellectualcrafters.plot.object.BlockLoc; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.entity.EntityWrapper; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.TaskManager; + +public class BukkitChunkManager extends ChunkManager { + public static MutableInt index = new MutableInt(0); + public static HashMap tasks = new HashMap<>(); + + @Override + public ArrayList getChunkChunks(final String world) { + final String directory = new File(".").getAbsolutePath() + File.separator + world + File.separator + "region"; + final File folder = new File(directory); + final File[] regionFiles = folder.listFiles(); + final ArrayList chunks = new ArrayList<>(); + for (final File file : regionFiles) { + final String name = file.getName(); + if (name.endsWith("mca")) { + final String[] split = name.split("\\."); + try { + final int x = Integer.parseInt(split[1]); + final int z = Integer.parseInt(split[2]); + final ChunkLoc loc = new ChunkLoc(x, z); + chunks.add(loc); + } catch (final Exception e) { + } + } + } + for (final Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) { + final ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5); + if (!chunks.contains(loc)) { + chunks.add(loc); + } + } + return chunks; + } + + @Override + public void deleteRegionFile(final String world, final ChunkLoc loc) { + TaskManager.runTaskAsync(new Runnable() { + @Override + public void run() { + final String directory = world + File.separator + "region" + File.separator + "r." + loc.x + "." + loc.z + ".mca"; + final File file = new File(directory); + PlotSquared.log("&6 - Deleting file: " + file.getName() + " (max 1024 chunks)"); + if (file.exists()) { + file.delete(); + } + } + }); + } + + @Override + public Plot hasPlot(final String world, final ChunkLoc chunk) { + final int x1 = chunk.x << 4; + final int z1 = chunk.z << 4; + final int x2 = x1 + 15; + final int z2 = z1 + 15; + final Location bot = new Location(world, x1, 0, z1); + Plot plot; + plot = MainUtil.getPlot(bot); + if ((plot != null) && (plot.owner != null)) { + return plot; + } + final Location top = new Location(world, x2, 0, z2); + plot = MainUtil.getPlot(top); + if ((plot != null) && (plot.owner != null)) { + return plot; + } + return null; + } + + private static HashMap chestContents; + private static HashMap furnaceContents; + private static HashMap dispenserContents; + private static HashMap dropperContents; + private static HashMap brewingStandContents; + private static HashMap beaconContents; + private static HashMap hopperContents; + private static HashMap furnaceTime; + private static HashMap skullData; + private static HashMap jukeDisc; + private static HashMap brewTime; + private static HashMap spawnerData; + private static HashMap cmdData; + private static HashMap signContents; + private static HashMap noteBlockContents; + private static HashMap> bannerColors; + private static HashMap bannerBase; + private static HashSet entities; + + /** + * Copy a region to a new location (in the same world) + */ + @Override + public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) { + index.increment(); + final int relX = newPos.getX() - pos1.getX(); + final int relZ = newPos.getZ() - pos1.getZ(); + final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + final World world = Bukkit.getWorld(pos1.getWorld()); + final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); + final Chunk c2 = world.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4); + final Chunk c3 = world.getChunkAt((pos1.getX() + relX) >> 4, (pos1.getZ() + relZ) >> 4); + final Chunk c4 = world.getChunkAt((pos2.getX() + relX) >> 4, (pos2.getZ() + relZ) >> 4); + final int sx = pos1.getX(); + final int sz = pos1.getZ(); + final int ex = pos2.getX(); + final int ez = pos2.getZ(); + final int c1x = c1.getX(); + final int c1z = c1.getZ(); + final int c2x = c2.getX(); + final int c2z = c2.getZ(); + final int c3x = c3.getX(); + final int c3z = c3.getZ(); + final int c4x = c4.getX(); + final int c4z = c4.getZ(); + final ArrayList chunks = new ArrayList<>(); + final ArrayList toGenerate = new ArrayList<>(); + // Load chunks + for (int x = c1x; x <= c2x; x++) { + for (int z = c1z; z <= c2z; z++) { + final Chunk chunk = world.getChunkAt(x, z); + toGenerate.add(chunk); + } + } + final Plugin plugin = BukkitMain.THIS; + final Integer currentIndex = index.toInteger(); + final int loadTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + final long start = System.currentTimeMillis(); + while ((System.currentTimeMillis() - start) < 25) { + if (toGenerate.size() == 0) { + Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); + tasks.remove(currentIndex); + TaskManager.runTask(new Runnable() { + @Override + public void run() { + index.increment(); + // Copy entities + initMaps(); + for (int x = c3x; x <= c4x; x++) { + for (int z = c3z; z <= c4z; z++) { + final Chunk chunk = world.getChunkAt(x, z); + chunks.add(chunk); + chunk.load(false); + saveEntitiesIn(chunk, region); + restoreEntities(world, relX, relZ); + } + } + // Copy blocks + final MutableInt mx = new MutableInt(sx); + final Integer currentIndex = index.toInteger(); + final int maxY = world.getMaxHeight(); + final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + final long start = System.currentTimeMillis(); + while ((System.currentTimeMillis() - start) < 25) { + final int xv = mx.intValue(); + for (int z = sz; z <= ez; z++) { + saveBlocks(world, maxY, xv, z); + for (int y = 1; y <= maxY; y++) { + final Block block = world.getBlockAt(xv, y, z); + final int id = block.getTypeId(); + final byte data = block.getData(); + BukkitSetBlockManager.setBlockManager.set(world, xv + relX, y, z + relZ, id, data); + } + } + mx.increment(); + if (xv == ex) { // done! + restoreBlocks(world, relX, relZ); + BukkitSetBlockManager.setBlockManager.update(chunks); + for (final Chunk chunk : chunks) { + chunk.unload(true, true); + } + TaskManager.runTask(whenDone); + Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); + tasks.remove(currentIndex); + return; + } + } + }; + }, 1, 1); + tasks.put(currentIndex, task); + } + }); + return; + } + final Chunk chunk = toGenerate.get(0); + toGenerate.remove(0); + chunk.load(true); + chunks.add(chunk); + } + } + }, 1l, 1l); + tasks.put(currentIndex, loadTask); + return true; + } + + @Override + public boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone) { + index.increment(); + final Plugin plugin = BukkitMain.THIS; + final World world = Bukkit.getWorld(pos1.getWorld()); + final Chunk c1 = world.getChunkAt(pos1.getX() >> 4, pos1.getZ() >> 4); + final Chunk c2 = world.getChunkAt(pos2.getX() >> 4, pos2.getZ() >> 4); + final int sx = pos1.getX(); + final int sz = pos1.getZ(); + final int ex = pos2.getX(); + final int ez = pos2.getZ(); + final int c1x = c1.getX(); + final int c1z = c1.getZ(); + final int c2x = c2.getX(); + final int c2z = c2.getZ(); + + final ArrayList chunks = new ArrayList(); + for (int x = c1x; x <= c2x; x++) { + for (int z = c1z; z <= c2z; z++) { + final Chunk chunk = world.getChunkAt(x, z); + chunk.load(false); + chunks.add(chunk); + } + } + final int maxY = world.getMaxHeight(); + final Integer currentIndex = index.toInteger(); + final Integer task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + if (chunks.size() == 0) { + TaskManager.runTaskLater(whenDone, 1); + Bukkit.getScheduler().cancelTask(tasks.get(currentIndex)); + tasks.remove(currentIndex); + return; + } + CURRENT_PLOT_CLEAR = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); + final Chunk chunk = chunks.get(0); + chunks.remove(0); + final int x = chunk.getX(); + final int z = chunk.getZ(); + boolean loaded = true; + if (!chunk.isLoaded()) { + final boolean result = chunk.load(false); + if (!result) { + loaded = false; + ; + } + if (!chunk.isLoaded()) { + loaded = false; + } + } + if (loaded) { + initMaps(); + final int absX = x << 4; + final int absZ = z << 4; + boolean save = false; + if ((x == c1x) || (z == c1z)) { + save = true; + for (int X = 0; X < 16; X++) { + for (int Z = 0; Z < 16; Z++) { + if ((((X + absX) < sx) || ((Z + absZ) < sz)) || (((X + absX) > ex) || ((Z + absZ) > ez))) { + saveBlocks(world, maxY, X + absX, Z + absZ); + } + } + } + } else if ((x == c2x) || (z == c2z)) { + for (int X = 0; X < 16; X++) { + save = true; + for (int Z = 0; Z < 16; Z++) { + if ((((X + absX) > ex) || ((Z + absZ) > ez)) || (((X + absX) < sx) || ((Z + absZ) < sz))) { + saveBlocks(world, maxY, X + absX, Z + absZ); + } + } + } + } + if (save) { + saveEntitiesOut(chunk, CURRENT_PLOT_CLEAR); + } + world.regenerateChunk(x, z); + if (save) { + restoreBlocks(world, 0, 0); + restoreEntities(world, 0, 0); + } + chunk.unload(true, true); + BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); + } + CURRENT_PLOT_CLEAR = null; + } + }, 1, 1); + tasks.put(currentIndex, task); + return true; + } + + public static void initMaps() { + GENERATE_BLOCKS = new HashMap<>(); + GENERATE_DATA = new HashMap<>(); + chestContents = new HashMap<>(); + furnaceContents = new HashMap<>(); + dispenserContents = new HashMap<>(); + dropperContents = new HashMap<>(); + brewingStandContents = new HashMap<>(); + beaconContents = new HashMap<>(); + hopperContents = new HashMap<>(); + furnaceTime = new HashMap<>(); + skullData = new HashMap<>(); + brewTime = new HashMap<>(); + jukeDisc = new HashMap<>(); + spawnerData = new HashMap<>(); + noteBlockContents = new HashMap<>(); + signContents = new HashMap<>(); + cmdData = new HashMap<>(); + bannerBase = new HashMap<>(); + bannerColors = new HashMap<>(); + entities = new HashSet<>(); + } + + public static boolean isIn(final RegionWrapper region, final int x, final int z) { + return ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)); + } + + public static void saveEntitiesOut(final Chunk chunk, final RegionWrapper region) { + for (final Entity entity : chunk.getEntities()) { + final Location loc = BukkitUtil.getLocation(entity); + final int x = loc.getX(); + final int z = loc.getZ(); + if (isIn(region, x, z)) { + continue; + } + if (entity.getVehicle() != null) { + continue; + } + final EntityWrapper wrap = new EntityWrapper(entity, (short) 2); + entities.add(wrap); + } + } + + public static void saveEntitiesIn(final Chunk chunk, final RegionWrapper region) { + for (final Entity entity : chunk.getEntities()) { + final Location loc = BukkitUtil.getLocation(entity); + final int x = loc.getX(); + final int z = loc.getZ(); + if (!isIn(region, x, z)) { + continue; + } + if (entity.getVehicle() != null) { + continue; + } + final EntityWrapper wrap = new EntityWrapper(entity, (short) 2); + entities.add(wrap); + } + } + + public static void restoreEntities(final World world, final int x_offset, final int z_offset) { + for (final EntityWrapper entity : entities) { + try { + entity.spawn(world, x_offset, z_offset); + } catch (final Exception e) { + PlotSquared.log("Failed to restore entity " + entity.x + "," + entity.y + "," + entity.z + " : " + entity.id + " : " + EntityType.fromId(entity.id)); + e.printStackTrace(); + } + } + } + + public static void restoreBlocks(final World world, final int x_offset, final int z_offset) { + for (final BlockLoc loc : chestContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Chest) { + final Chest chest = (Chest) state; + chest.getInventory().setContents(chestContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate chest: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : signContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Sign) { + final Sign sign = (Sign) state; + int i = 0; + for (final String line : signContents.get(loc)) { + sign.setLine(i, line); + i++; + } + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate sign: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : dispenserContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Dispenser) { + ((Dispenser) (state)).getInventory().setContents(dispenserContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate dispenser: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : dropperContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Dropper) { + ((Dropper) (state)).getInventory().setContents(dropperContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate dispenser: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : beaconContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Beacon) { + ((Beacon) (state)).getInventory().setContents(beaconContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate beacon: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : jukeDisc.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Jukebox) { + ((Jukebox) (state)).setPlaying(Material.getMaterial(jukeDisc.get(loc))); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to restore jukebox: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : skullData.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Skull) { + final Object[] data = skullData.get(loc); + if (data[0] != null) { + ((Skull) (state)).setOwner((String) data[0]); + } + if (((Integer) data[1]) != 0) { + ((Skull) (state)).setRotation(BlockFace.values()[(int) data[1]]); + } + if (((Integer) data[2]) != 0) { + ((Skull) (state)).setSkullType(SkullType.values()[(int) data[2]]); + } + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to restore jukebox: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : hopperContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Hopper) { + ((Hopper) (state)).getInventory().setContents(hopperContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate hopper: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : noteBlockContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof NoteBlock) { + ((NoteBlock) (state)).setNote(noteBlockContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate note block: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : brewTime.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof BrewingStand) { + ((BrewingStand) (state)).setBrewingTime(brewTime.get(loc)); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to restore brewing stand cooking: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : spawnerData.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof CreatureSpawner) { + ((CreatureSpawner) (state)).setCreatureTypeId(spawnerData.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to restore spawner type: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : cmdData.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof CommandBlock) { + ((CommandBlock) (state)).setCommand(cmdData.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to restore command block: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : brewingStandContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof BrewingStand) { + ((BrewingStand) (state)).getInventory().setContents(brewingStandContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate brewing stand: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : furnaceTime.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Furnace) { + final Short[] time = furnaceTime.get(loc); + ((Furnace) (state)).setBurnTime(time[0]); + ((Furnace) (state)).setCookTime(time[1]); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to restore furnace cooking: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : furnaceContents.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Furnace) { + ((Furnace) (state)).getInventory().setContents(furnaceContents.get(loc)); + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate furnace: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + for (final BlockLoc loc : bannerBase.keySet()) { + final Block block = world.getBlockAt(loc.x + x_offset, loc.y, loc.z + z_offset); + final BlockState state = block.getState(); + if (state instanceof Banner) { + final Banner banner = (Banner) state; + final byte base = bannerBase.get(loc); + final ArrayList colors = bannerColors.get(loc); + banner.setBaseColor(DyeColor.values()[base]); + for (final Byte[] color : colors) { + banner.addPattern(new Pattern(DyeColor.getByDyeData(color[1]), PatternType.values()[color[0]])); + } + state.update(true); + } else { + PlotSquared.log("&c[WARN] Plot clear failed to regenerate banner: " + loc.x + x_offset + "," + loc.y + "," + loc.z + z_offset); + } + } + } + + public static void saveBlocks(final World world, final int maxY, final int x, final int z) { + final HashMap ids = new HashMap<>(); + final HashMap datas = new HashMap<>(); + for (short y = 1; y < maxY; y++) { + final Block block = world.getBlockAt(x, y, z); + final short id = (short) block.getTypeId(); + if (id != 0) { + ids.put(y, id); + final byte data = block.getData(); + if (data != 0) { + datas.put(y, data); + } + BlockLoc bl; + switch (id) { + case 54: + bl = new BlockLoc(x, y, z); + final InventoryHolder chest = (InventoryHolder) block.getState(); + final ItemStack[] inventory = chest.getInventory().getContents().clone(); + chestContents.put(bl, inventory); + break; + case 52: + bl = new BlockLoc(x, y, z); + final CreatureSpawner spawner = (CreatureSpawner) block.getState(); + final String type = spawner.getCreatureTypeId(); + if ((type != null) && (type.length() != 0)) { + spawnerData.put(bl, type); + } + break; + case 137: + bl = new BlockLoc(x, y, z); + final CommandBlock cmd = (CommandBlock) block.getState(); + final String string = cmd.getCommand(); + if ((string != null) && (string.length() > 0)) { + cmdData.put(bl, string); + } + break; + case 63: + case 68: + case 323: + bl = new BlockLoc(x, y, z); + final Sign sign = (Sign) block.getState(); + sign.getLines(); + signContents.put(bl, sign.getLines().clone()); + break; + case 61: + case 62: + bl = new BlockLoc(x, y, z); + final Furnace furnace = (Furnace) block.getState(); + final short burn = furnace.getBurnTime(); + final short cook = furnace.getCookTime(); + final ItemStack[] invFur = furnace.getInventory().getContents().clone(); + furnaceContents.put(bl, invFur); + if (cook != 0) { + furnaceTime.put(bl, new Short[] { burn, cook }); + } + break; + case 23: + bl = new BlockLoc(x, y, z); + final Dispenser dispenser = (Dispenser) block.getState(); + final ItemStack[] invDis = dispenser.getInventory().getContents().clone(); + dispenserContents.put(bl, invDis); + break; + case 158: + bl = new BlockLoc(x, y, z); + final Dropper dropper = (Dropper) block.getState(); + final ItemStack[] invDro = dropper.getInventory().getContents().clone(); + dropperContents.put(bl, invDro); + break; + case 117: + bl = new BlockLoc(x, y, z); + final BrewingStand brewingStand = (BrewingStand) block.getState(); + final short time = (short) brewingStand.getBrewingTime(); + if (time > 0) { + brewTime.put(bl, time); + } + final ItemStack[] invBre = brewingStand.getInventory().getContents().clone(); + brewingStandContents.put(bl, invBre); + break; + case 25: + bl = new BlockLoc(x, y, z); + final NoteBlock noteBlock = (NoteBlock) block.getState(); + final Note note = noteBlock.getNote(); + noteBlockContents.put(bl, note); + break; + case 138: + bl = new BlockLoc(x, y, z); + final Beacon beacon = (Beacon) block.getState(); + final ItemStack[] invBea = beacon.getInventory().getContents().clone(); + beaconContents.put(bl, invBea); + break; + case 84: + bl = new BlockLoc(x, y, z); + final Jukebox jukebox = (Jukebox) block.getState(); + final Material playing = jukebox.getPlaying(); + if (playing != null) { + jukeDisc.put(bl, (short) playing.getId()); + } + break; + case 154: + bl = new BlockLoc(x, y, z); + final Hopper hopper = (Hopper) block.getState(); + final ItemStack[] invHop = hopper.getInventory().getContents().clone(); + hopperContents.put(bl, invHop); + break; + case 397: + bl = new BlockLoc(x, y, z); + final Skull skull = (Skull) block.getState(); + final String o = skull.getOwner(); + final byte skulltype = getOrdinal(SkullType.values(), skull.getSkullType()); + skull.getRotation(); + final short rot = getOrdinal(BlockFace.values(), skull.getRotation()); + skullData.put(bl, new Object[] { o, rot, skulltype }); + break; + case 176: + case 177: + bl = new BlockLoc(x, y, z); + final Banner banner = (Banner) block.getState(); + final byte base = getOrdinal(DyeColor.values(), banner.getBaseColor()); + final ArrayList types = new ArrayList<>(); + for (final Pattern pattern : banner.getPatterns()) { + types.add(new Byte[] { getOrdinal(PatternType.values(), pattern.getPattern()), pattern.getColor().getDyeData() }); + } + bannerBase.put(bl, base); + bannerColors.put(bl, types); + break; + } + } + } + final ChunkLoc loc = new ChunkLoc(x, z); + GENERATE_BLOCKS.put(loc, ids); + GENERATE_DATA.put(loc, datas); + } + + private static byte getOrdinal(final Object[] list, final Object value) { + for (byte i = 0; i < list.length; i++) { + if (list[i].equals(value)) { + return i; + } + } + return 0; + } + + @Override + public void clearAllEntities(final Plot plot) { + final List entities = BukkitUtil.getEntities(plot.world); + for (final Entity entity : entities) { + final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity)); + if (plot.id.equals(id)) { + if (entity instanceof Player) { + final Player player = (Player) entity; + MainUtil.teleportPlayer(BukkitUtil.getPlayer(player), BukkitUtil.getLocation(entity), plot); + PlotListener.plotExit(player, plot); + } else { + entity.remove(); + } + } + } + } + + @Override + public boolean loadChunk(final String world, final ChunkLoc loc) { + return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(false); + } + + @Override + public void swap(final String world, final PlotId id, final PlotId plotid) { + // FIXME swap plots + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitEventUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitEventUtil.java new file mode 100644 index 000000000..24fd886a6 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitEventUtil.java @@ -0,0 +1,111 @@ +package com.intellectualcrafters.plot.util.bukkit; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +import com.intellectualcrafters.plot.events.PlayerClaimPlotEvent; +import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; +import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; +import com.intellectualcrafters.plot.events.PlayerPlotDeniedEvent; +import com.intellectualcrafters.plot.events.PlayerPlotHelperEvent; +import com.intellectualcrafters.plot.events.PlayerPlotTrustedEvent; +import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; +import com.intellectualcrafters.plot.events.PlotClearEvent; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.events.PlotFlagAddEvent; +import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; +import com.intellectualcrafters.plot.events.PlotMergeEvent; +import com.intellectualcrafters.plot.events.PlotUnlinkEvent; +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.BukkitPlayer; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.EventUtil; + +public class BukkitEventUtil extends EventUtil { + + public Player getPlayer(PlotPlayer player) { + return ((BukkitPlayer) player).player; + } + + public boolean callEvent(Event event) { + Bukkit.getServer().getPluginManager().callEvent(event); + if (event instanceof Cancellable) { + return !((Cancellable) event).isCancelled(); + } + return true; + } + + @Override + public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) { + return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto)); + } + + @Override + public boolean callTeleport(PlotPlayer player, Location from, Plot plot) { + return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot)); + } + + @Override + public boolean callClear(String world, PlotId id) { + return callEvent(new PlotClearEvent(world, id)); + } + + @Override + public void callDelete(String world, PlotId id) { + callEvent(new PlotDeleteEvent(world, id)); + } + + @Override + public boolean callFlagAdd(Flag flag, Plot plot) { + return callEvent(new PlotFlagAddEvent(flag, plot)); + } + + @Override + public boolean callFlagRemove(Flag flag, Plot plot) { + return callEvent(new PlotFlagRemoveEvent(flag, plot)); + } + + @Override + public boolean callMerge(String world, Plot plot, ArrayList plots) { + return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(world), plot, plots)); + } + + @Override + public boolean callUnlink(String world, ArrayList plots) { + return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(world), plots)); + } + + @Override + public void callEntry(PlotPlayer player, Plot plot) { + callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot)); + } + + @Override + public void callLeave(PlotPlayer player, Plot plot) { + callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot)); + } + + @Override + public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) { + callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added)); + } + + @Override + public void callHelper(PlotPlayer initiator, Plot plot, UUID player, boolean added) { + callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added)); + } + + @Override + public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) { + callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added)); + } + +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java new file mode 100644 index 000000000..e9a718e43 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetBlockManager.java @@ -0,0 +1,28 @@ +package com.intellectualcrafters.plot.util.bukkit; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Chunk; +import org.bukkit.World; + +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.util.BlockUpdateUtil; + +public abstract class BukkitSetBlockManager extends BlockUpdateUtil { + public static BukkitSetBlockManager setBlockManager = null; + + public abstract void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data); + + public abstract void update(List list); + + @Override + public void update(final String worldname, final List chunkLocs) { + final World world = BukkitUtil.getWorld(worldname); + final ArrayList chunks = new ArrayList(); + for (final ChunkLoc loc : chunkLocs) { + chunks.add(world.getChunkAt(loc.x, loc.z)); + } + setBlockManager.update(chunks); + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java index 350b37a76..dcd36902f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitUtil.java @@ -96,7 +96,7 @@ public class BukkitUtil extends BlockManager { chunks.add(chunk); } } - SetBlockManager.setBlockManager.update(chunks); + BukkitSetBlockManager.setBlockManager.update(chunks); } public static String getWorld(final Entity entity) { @@ -114,10 +114,10 @@ public class BukkitUtil extends BlockManager { public static void setBlock(final World world, final int x, final int y, final int z, final int id, final byte data) { try { - SetBlockManager.setBlockManager.set(world, x, y, z, id, data); + BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data); } catch (final Throwable e) { - SetBlockManager.setBlockManager = new SetBlockSlow(); - SetBlockManager.setBlockManager.set(world, x, y, z, id, data); + BukkitSetBlockManager.setBlockManager = new SetBlockSlow(); + BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java index 04ba415cf..e59dc8939 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/PWE.java @@ -42,9 +42,18 @@ import com.sk89q.worldedit.regions.CuboidRegion; * @author Empire92 */ public class PWE { + + public static LocalSession getSession(PlotPlayer p) { + if (PlotSquared.worldEdit == null) { + return WorldEdit.getInstance().getSession(p.getName()); + } else { + return PlotSquared.worldEdit.getSession(((BukkitPlayer) p).player); + } + } + public static void setMask(final PlotPlayer p, final Location l, final boolean force) { try { - final LocalSession s = WorldEdit.getInstance().getSession(p.getName()); + LocalSession s = getSession(p); if (!PlotSquared.isPlotWorld(l.getWorld())) { removeMask(p); } @@ -84,7 +93,7 @@ public class PWE { } public static boolean hasMask(final PlotPlayer p) { - final LocalSession s = WorldEdit.getInstance().getSession(p.getName()); + LocalSession s = getSession(p); return !noMask(s); } @@ -95,7 +104,7 @@ public class PWE { @SuppressWarnings("deprecation") public static void setNoMask(final PlotPlayer p) { try { - final LocalSession s = WorldEdit.getInstance().getSession(p.getName()); + LocalSession s = getSession(p); final com.sk89q.worldedit.bukkit.BukkitPlayer plr = PlotSquared.worldEdit.wrapPlayer(((BukkitPlayer) p).player); final Vector p1 = new Vector(69, 69, 69), p2 = new Vector(69, 69, 69); s.setMask(new RegionMask(new CuboidRegion(plr.getWorld(), p1, p2))); @@ -111,7 +120,7 @@ public class PWE { public static void removeMask(final PlotPlayer p) { try { - final LocalSession s = WorldEdit.getInstance().getSession(p.getName()); + LocalSession s = getSession(p); removeMask(p, s); } catch (final Exception e) { // throw new diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java index 740b51295..5405ae533 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast.java @@ -36,7 +36,7 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; * * @author Empire92 */ -public class SetBlockFast extends SetBlockManager { +public class SetBlockFast extends BukkitSetBlockManager { private static final RefClass classBlock = getRefClass("{nms}.Block"); private static final RefClass classChunk = getRefClass("{nms}.Chunk"); private static final RefClass classWorld = getRefClass("{nms}.World"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java index 29592ae0f..c635714b2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockFast_1_8.java @@ -38,7 +38,7 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; * * @author Empire92 */ -public class SetBlockFast_1_8 extends SetBlockManager { +public class SetBlockFast_1_8 extends BukkitSetBlockManager { private static final RefClass classBlock = getRefClass("{nms}.Block"); private static final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition"); private static final RefClass classIBlockData = getRefClass("{nms}.IBlockData"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java index ea15a158b..2f8a80697 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SetBlockSlow.java @@ -6,7 +6,7 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Block; -public class SetBlockSlow extends SetBlockManager { +public class SetBlockSlow extends BukkitSetBlockManager { @Override public void set(final World world, final int x, final int y, final int z, final int id, final byte data) { final Block block = world.getBlockAt(x, y, z);