From 3b1cae732c655a2efbbe3a834567b9479537d29d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 4 May 2015 23:53:24 +1000 Subject: [PATCH] misc fixes --- PlotSquared/pom.xml | 2 +- .../intellectualcrafters/plot/BukkitMain.java | 12 +- .../plot/PlotSquared.java | 2 +- .../plot/commands/DebugFill.java | 114 ++++++++++-------- .../plot/listeners/WorldEvents.java | 21 +++- .../plot/object/PlotGenerator.java | 7 +- .../plot/util/SetBlockQueue.java | 58 +++++++-- 7 files changed, 145 insertions(+), 71 deletions(-) diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index b5d2ed70b..011c30fa1 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.10.2 + 2.10.4 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 779511ed9..dc82b4408 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -322,10 +322,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Override final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { + WorldEvents.lastWorld = world; if (!PlotSquared.setupPlotWorld(world, id)) { return null; } - return new HybridGen(); + HybridGen result = new HybridGen(); + TaskManager.runTaskLater(new Runnable() { + @Override + public void run() { + if (WorldEvents.lastWorld != null && WorldEvents.lastWorld.equals(world)) { + WorldEvents.lastWorld = null; + } + } + }, 20); + return result; } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 31bd88321..528ffd3a4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -97,7 +97,7 @@ public class PlotSquared { private static LinkedHashMap> plots; private static Database database; public static Connection connection; - + public static Database getDatabase() { return database; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java index fc676c07c..f3b38ce1c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugFill.java @@ -23,16 +23,12 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; -import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper; -import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper; -import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper; -import com.intellectualcrafters.plot.uuid.UUIDWrapper; public class DebugFill extends SubCommand { public DebugFill() { @@ -61,56 +57,72 @@ public class DebugFill extends SubCommand { final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); MainUtil.sendMessage(player, "&cPreparing task"); - TaskManager.runTaskAsync(new Runnable() { + SetBlockQueue.addNotify(new Runnable() { @Override public void run() { - MainUtil.sendMessage(player, "&7 - Starting"); - if (args[0].equalsIgnoreCase("all")) { - for (int x = bottom.getX(); x <= top.getX(); x++) { - for (int y = 0; y <= 255; y++) { - for (int z = bottom.getZ(); z <= top.getZ(); z++) { - SetBlockQueue.setBlock(plot.world, x, y, z, 7); - } - } - } - } - else if (args[0].equals("outline")) { - int x, z; - z = bottom.getZ(); - for (x = bottom.getX(); x <= (top.getX() - 1); x++) { - for (int y = 1; y <= 255; y++) { - SetBlockQueue.setBlock(plot.world, x, y, z, 7); - } - } - x = top.getX(); - for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { - for (int y = 1; y <= 255; y++) { - SetBlockQueue.setBlock(plot.world, x, y, z, 7); - } - } - z = top.getZ(); - for (x = top.getX(); x >= (bottom.getX() + 1); x--) { - for (int y = 1; y <= 255; y++) { - SetBlockQueue.setBlock(plot.world, x, y, z, 7); - } - } - x = bottom.getX(); - for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { - for (int y = 1; y <= 255; y++) { - SetBlockQueue.setBlock(plot.world, x, y, z, 7); - } - } - int y = 255; - for (x = bottom.getX(); x <= top.getX(); x++) { - for (z = bottom.getZ(); z <= top.getZ(); z++) { - SetBlockQueue.setBlock(plot.world, x, y, z, 7); - } - } - } - SetBlockQueue.addNotify(new Runnable() { + TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - MainUtil.sendMessage(player, "&aFill task complete!"); + MainUtil.sendMessage(player, "&7 - Starting"); + if (args[0].equalsIgnoreCase("all")) { + for (int x = bottom.getX(); x <= top.getX(); x++) { + for (int y = 0; y <= 255; y++) { + for (int z = bottom.getZ(); z <= top.getZ(); z++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + } + SetBlockQueue.addNotify(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(player, "&aFill task complete!"); + } + }); + } + else if (args[0].equals("outline")) { + int x, z; + z = bottom.getZ(); + for (x = bottom.getX(); x <= (top.getX() - 1); x++) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + x = top.getX(); + for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + z = top.getZ(); + for (x = top.getX(); x >= (bottom.getX() + 1); x--) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + x = bottom.getX(); + for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { + for (int y = 1; y <= 255; y++) { + SetBlockQueue.setBlock(plot.world, x, y, z, 7); + } + } + SetBlockQueue.addNotify(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :("); + bottom.setY(255); + top.add(1,0,1); + SetBlockQueue.setSlow(true); + MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0)); + SetBlockQueue.addNotify(new Runnable() { + @Override + public void run() { + MainUtil.sendMessage(player, "&aFill task complete!"); + SetBlockQueue.setSlow(false); + } + }); + } + }); + } } }); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java index 01bdcc690..16a9a7229 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java @@ -13,17 +13,32 @@ import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; public class WorldEvents implements Listener { + + public static String lastWorld = null; + + public static String getName(World world) { + if (lastWorld != null) { + return lastWorld; + } + else { + return world.getName(); + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public static void onWorldInit(final WorldInitEvent event) { final World world = event.getWorld(); + String name = getName(world); final ChunkGenerator gen = world.getGenerator(); if (gen instanceof PlotGenerator) { - PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen); + // + PlotSquared.loadWorld(name, (PlotGenerator) gen); } else { - if (PlotSquared.config.contains("worlds." + world.getName())) { - PlotSquared.loadWorld(world.getName(), null); + if (PlotSquared.config.contains("worlds." + name)) { + PlotSquared.loadWorld(name, null); } } + lastWorld = null; } @EventHandler diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java index 1e5603760..d1281e294 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -31,6 +31,7 @@ import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.listeners.WorldEvents; import com.intellectualcrafters.plot.util.ChunkManager; public abstract class PlotGenerator extends ChunkGenerator { @@ -43,8 +44,8 @@ public abstract class PlotGenerator extends ChunkGenerator { @SuppressWarnings("unchecked") @Override public List getDefaultPopulators(World world) { - PlotSquared.loadWorld(world.getName(), this); - PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); + PlotSquared.loadWorld(WorldEvents.getName(world), this); + PlotWorld plotworld = PlotSquared.getPlotWorld(WorldEvents.getName(world)); if (!plotworld.MOB_SPAWNING) { if (!plotworld.SPAWN_EGGS) { world.setSpawnFlags(false, false); @@ -61,7 +62,7 @@ public abstract class PlotGenerator extends ChunkGenerator { world.setMonsterSpawnLimit(-1); world.setWaterAnimalSpawnLimit(-1); } - return (List)(List) getPopulators(world.getName()); + return (List)(List) getPopulators(WorldEvents.getName(world)); } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java index 082b27a56..12ecc6677 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java @@ -2,7 +2,6 @@ package com.intellectualcrafters.plot.util; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Map.Entry; import com.intellectualcrafters.plot.PlotSquared; @@ -16,6 +15,7 @@ public class SetBlockQueue { private volatile static boolean running = false; private volatile static boolean locked = false; private volatile static HashSet runnables; + private volatile static boolean slow = false; public synchronized static void allocate(int t) { allocate = t; @@ -25,15 +25,23 @@ public class SetBlockQueue { return allocate; } + public static void setSlow(boolean value) { + slow = value; + } + public synchronized static void addNotify(Runnable whenDone) { if (runnables == null) { TaskManager.runTask(whenDone); + slow = false; + locked = false; } else { runnables.add(whenDone); } } + private static long last; + public synchronized static void init() { if (blocks == null) { if (AugmentedPopulator.x_loc == null) { @@ -59,22 +67,48 @@ public class SetBlockQueue { runnables = null; blocks = null; running = false; + slow = false; return; } - long start = System.currentTimeMillis() + allocate; - Iterator> i = blocks.entrySet().iterator(); - while (System.currentTimeMillis() < start && i.hasNext()) { + long newLast = System.currentTimeMillis(); + last = Math.max(newLast - 100, last); + while (blocks.size() > 0 && (System.currentTimeMillis() - last < 100 + allocate)) { if (locked) { return; } - Entry n = i.next(); - i.remove(); + Entry n = blocks.entrySet().iterator().next(); ChunkWrapper chunk = n.getKey(); + PlotBlock[][] blocks = n.getValue(); int X = chunk.x << 4; int Z = chunk.z << 4; - PlotBlock[][] blocks = n.getValue(); String world = chunk.world; -// ChunkManager.manager.setChunk(chunk, blocks); + if (slow) { + boolean once = false; + for (int j = 0; j < blocks.length; j++) { + PlotBlock[] blocksj = blocks[j]; + if (blocksj != null) { + long start = System.currentTimeMillis(); + for (int k = 0; k < blocksj.length; k++) { + if (once && (System.currentTimeMillis() - start > allocate)) { + SetBlockQueue.blocks.put(n.getKey(), blocks); + return; + } + PlotBlock block = blocksj[k]; + if (block != null) { + int x = AugmentedPopulator.x_loc[j][k]; + int y = AugmentedPopulator.y_loc[j][k]; + int z = AugmentedPopulator.z_loc[j][k]; + BlockManager.manager.functionSetBlock(world, X + x, y, Z + z, block.id, block.data); + blocks[j][k] = null; + once = true; + } + } + } + } + SetBlockQueue.blocks.remove(n.getKey()); + return; + } + SetBlockQueue.blocks.remove(n.getKey()); for (int j = 0; j < blocks.length; j++) { PlotBlock[] blocksj = blocks[j]; if (blocksj != null) { @@ -108,11 +142,13 @@ public class SetBlockQueue { z -= Z << 4; ChunkWrapper wrap = new ChunkWrapper(world, X, Z); - PlotBlock[][] result = blocks.get(wrap); + PlotBlock[][] result; + result = blocks.get(wrap); if (!blocks.containsKey(wrap)) { result = new PlotBlock[16][]; blocks.put(wrap, result); } + if (result[y >> 4] == null) { result[y >> 4] = new PlotBlock[4096]; } @@ -132,9 +168,9 @@ public class SetBlockQueue { int Z = z >> 4; x -= X << 4; z -= Z << 4; - ChunkWrapper wrap = new ChunkWrapper(world, X, Z); - PlotBlock[][] result = blocks.get(wrap); + PlotBlock[][] result; + result = blocks.get(wrap); if (!blocks.containsKey(wrap)) { result = new PlotBlock[16][]; blocks.put(wrap, result);