From 6ca6880917ebb3141beff1c9f796df2a6ab9d747 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 25 Aug 2015 09:01:45 +1000 Subject: [PATCH] New features + fixes Fixed a very specific case of IC world not loading with multiverse every second startup Fixed chunks not being sent for plot clearing (although it was being sent for other thing) Fixes #554 Added fast experimental sudo-async worldedit processor --- .../com/intellectualcrafters/plot/PS.java | 10 +- .../plot/commands/DebugClaimTest.java | 6 +- .../plot/config/Settings.java | 1 + .../com/plotsquared/bukkit/BukkitMain.java | 26 +++- .../worldedit/ProcessedWEExtent.java | 133 +++++++++++++++++- .../listeners/worldedit/WESubscriber.java | 2 +- .../bukkit/util/BukkitChunkManager.java | 4 + .../bukkit/util/BukkitSetupUtils.java | 38 +++-- .../plotsquared/bukkit/util/SendChunk.java | 13 +- 9 files changed, 194 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index b39a55179..7b2f3d01f 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -268,7 +268,10 @@ public class PS { if (world.equals("CheckingPlotSquaredGenerator")) { continue; } - if (!BlockManager.manager.isWorld(world)) { + if (!BlockManager.manager.isWorld(world) || (BlockManager.manager.isWorld(world) && !isPlotWorld(world))) { + PS.debug("&c`" + world + "` was not properly loaded - PlotSquared will now try to load it properly: "); + PS.debug("&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml as well"); + PS.debug("&8 - &7Your world management plugin may be faulty. Consider using an up to date plugin."); IMP.setGenerator(world); } } @@ -1250,6 +1253,7 @@ public class PS { LOADING_WORLD = false; } } else { + LOADING_WORLD = false; plotWorld = generator.getNewPlotWorld(world); plotManager = generator.getPlotManager(); if (!config.contains(path)) { @@ -1842,6 +1846,7 @@ public class PS { // Chunk processor options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR); options.put("chunk-processor.auto-unload", Settings.CHUNK_PROCESSOR_GC); + options.put("chunk-processor.experimental-fast-async-worldedit", Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT); options.put("chunk-processor.auto-trim", Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE); options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES); options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES); @@ -1956,10 +1961,9 @@ public class PS { // Chunk processor Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled"); - Settings.CHUNK_PROCESSOR_GC = config.getBoolean("chunk-processor.auto-unload"); Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE = config.getBoolean("chunk-processor.auto-trim"); - + Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT = config.getBoolean("chunk-processor.experimental-fast-async-worldedit"); Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES = config.getInt("chunk-processor.max-blockstates"); Settings.CHUNK_PROCESSOR_MAX_ENTITIES = config.getInt("chunk-processor.max-entities"); Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS = config.getBoolean("chunk-processor.disable-physics"); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index e98a1f9ff..16b16c34e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -81,10 +81,10 @@ public class DebugClaimTest extends SubCommand { try { final String[] split1 = args[1].split(";"); final String[] split2 = args[2].split(";"); - min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1])); - max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1])); + min = PlotId.fromString(args[1]); + max = PlotId.fromString(args[2]); } catch (final Exception e) { - return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X,Y are the plot coords\nThe conversion will only check the plots in the selected area."); + return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion will only check the plots in the selected area."); } MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while..."); MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)"); diff --git a/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 10c5d970f..10d27a846 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -68,6 +68,7 @@ public class Settings { * Chunk processor */ public static boolean CHUNK_PROCESSOR = false; + public static boolean EXPERIMENTAL_FAST_ASYNC_WORLDEDIT = false; public static boolean CHUNK_PROCESSOR_TRIM_ON_SAVE = false; public static boolean CHUNK_PROCESSOR_GC = false; public static int CHUNK_PROCESSOR_MAX_BLOCKSTATES = 4096; diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index ce6c80db7..c645e4cf8 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -53,6 +53,7 @@ import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector; import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter; import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017; import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper; +import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.HybridGen; import com.plotsquared.bukkit.listeners.ChunkListener; import com.plotsquared.bukkit.listeners.ForceFieldListener; @@ -578,13 +579,26 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { setup.step = new ConfigurationNode[0]; setup.world = worldname; SetupUtils.manager.setupWorld(setup); - return; } - try { - SetGenCB.setGenerator(BukkitUtil.getWorld(worldname)); - } catch (Exception e) { - log("Failed to reload world: " + world); - Bukkit.getServer().unloadWorld(world, false); + else { + try { + if (!PS.get().isPlotWorld(worldname)) { + SetGenCB.setGenerator(BukkitUtil.getWorld(worldname)); + } + } catch (Exception e) { + log("Failed to reload world: " + world); + Bukkit.getServer().unloadWorld(world, false); + } + } + world = Bukkit.getWorld(worldname); + final ChunkGenerator gen = world.getGenerator(); + if (gen instanceof BukkitPlotGenerator) { + PS.get().loadWorld(worldname, new BukkitGeneratorWrapper(worldname, (BukkitPlotGenerator) gen)); + } + else { + if (PS.get().config.contains("worlds." + worldname)) { + PS.get().loadWorld(worldname, new BukkitGeneratorWrapper(worldname, null)); + } } } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java index 72079c56f..b878673ec 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/ProcessedWEExtent.java @@ -4,7 +4,11 @@ import java.util.HashSet; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.SetBlockQueue; +import com.plotsquared.bukkit.util.BukkitUtil; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; @@ -22,15 +26,18 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { int Ecount = 0; boolean BSblocked = false; boolean Eblocked = false; + private String world; - public ProcessedWEExtent(HashSet mask, Extent extent) { + public ProcessedWEExtent(String world, HashSet mask, Extent extent) { super(extent); this.mask = mask; + this.world = world; } @Override public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException { - switch (block.getType()) { + int id = block.getType(); + switch (id) { case 54: case 130: case 142: @@ -74,10 +81,126 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { BSblocked = true; PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ())); } + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + return super.setBlock(location, block); + } + break; } - } - if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { - return super.setBlock(location, block); + default: { + int x = location.getBlockX(); + int y = location.getBlockY(); + int z = location.getBlockZ(); + if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockZ())) { + switch(id) { + case 0: + case 2: + case 4: + case 13: + case 14: + case 15: + case 20: + case 21: + case 22: + case 24: + case 25: + case 30: + case 32: + case 37: + case 39: + case 40: + case 41: + case 42: + case 45: + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 52: + case 54: + case 55: + case 56: + case 57: + case 58: + case 60: + case 61: + case 62: + case 7: + case 8: + case 9: + case 10: + case 11: + case 73: + case 74: + case 75: + case 76: + case 78: + case 79: + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 87: + case 88: + case 101: + case 102: + case 103: + case 110: + case 112: + case 113: + case 117: + case 121: + case 122: + case 123: + case 124: + case 129: + case 133: + case 138: + case 137: + case 140: + case 165: + case 166: + case 169: + case 170: + case 172: + case 173: + case 174: + case 176: + case 177: + case 181: + case 182: + case 188: + case 189: + case 190: + case 191: + case 192: { + if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { + SetBlockQueue.setBlock(world, x, y, z, id); + } + else { + super.setBlock(location, block); + } + break; + } + default: { + if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) { + SetBlockQueue.setBlock(world, x, y, z, new PlotBlock((short) id, (byte) block.getData())); + } + else { + super.setBlock(location, block); + } + break; + } + } + return true; +// BlockManager.manager.functionSetBlock(world, x, y, z, id, data); +// return super.setBlock(location, block); + } + } + } return false; } diff --git a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java index cded65024..6a5db5250 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/worldedit/WESubscriber.java @@ -41,7 +41,7 @@ public class WESubscriber { return; } if (Settings.CHUNK_PROCESSOR) { - event.setExtent(new ProcessedWEExtent(mask, event.getExtent())); + event.setExtent(new ProcessedWEExtent(world, mask, event.getExtent())); } else { event.setExtent(new WEExtent(mask, event.getExtent())); diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index 2451224ac..444dc2fae 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -56,6 +56,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.BlockUpdateUtil; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; @@ -101,6 +102,9 @@ public class BukkitChunkManager extends ChunkManager { World worldObj = Bukkit.getWorld(world); // Chunk chunk = worldObj.getChunkAt(loc.x, loc.z); worldObj.regenerateChunk(loc.x, loc.z); + if (MainUtil.canSendChunk && BlockUpdateUtil.setBlockManager != null) { + BlockUpdateUtil.setBlockManager.update(world, Arrays.asList(loc)); + } for (final Player player : worldObj.getPlayers()) { org.bukkit.Location locObj = player.getLocation(); if (locObj.getBlockX() >> 4 == loc.x && locObj.getBlockZ() >> 4 == loc.z && !locObj.getBlock().isEmpty()) { diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index ac52e40e0..22c0fc5d3 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -72,28 +72,36 @@ public class BukkitSetupUtils extends SetupUtils { if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator); setGenerator(world, object.setupGenerator); - } else { - if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator); - setGenerator(world, object.setupGenerator); - } else { - final WorldCreator wc = new WorldCreator(object.world); - wc.generator(object.setupGenerator); - wc.environment(Environment.NORMAL); - Bukkit.createWorld(wc); - setGenerator(world, object.setupGenerator); + if (Bukkit.getWorld(world) != null) { + return world; } } + if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator); + setGenerator(world, object.setupGenerator); + if (Bukkit.getWorld(world) != null) { + return world; + } + } + final WorldCreator wc = new WorldCreator(object.world); + wc.generator(object.setupGenerator); + wc.environment(Environment.NORMAL); + Bukkit.createWorld(wc); + setGenerator(world, object.setupGenerator); } else { if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal"); - } else { - if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world); - } else { - Bukkit.createWorld(new WorldCreator(object.world).environment(World.Environment.NORMAL)); + if (Bukkit.getWorld(world) != null) { + return world; } } + if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) { + Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world); + if (Bukkit.getWorld(world) != null) { + return world; + } + } + Bukkit.createWorld(new WorldCreator(object.world).environment(World.Environment.NORMAL)); } return object.world; } diff --git a/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/src/main/java/com/plotsquared/bukkit/util/SendChunk.java index d88a6970b..2e01b0371 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SendChunk.java +++ b/src/main/java/com/plotsquared/bukkit/util/SendChunk.java @@ -104,14 +104,15 @@ public class SendChunk { if (dx > view || dz > view) { continue; } - Object c = methodGetHandleChunk.of(chunk).call(); + net.minecraft.server.v1_8_R2.Chunk c = (net.minecraft.server.v1_8_R2.Chunk) methodGetHandleChunk.of(chunk).call(); + c.initLighting(); chunks.remove(chunk); Object con = connection.of(entity).get(); - if (dx != 0 || dz != 0) { - Object packet = MapChunk.create(c, true, 1); - send.of(con).call(packet); - } - Object packet = MapChunk.create(c, true, 65565); +// if (dx != 0 || dz != 0) { +// Object packet = MapChunk.create(c, true, 0); +// send.of(con).call(packet); +// } + Object packet = MapChunk.create(c, true, 65535); send.of(con).call(packet); } }