From b0384f40741d194e4a60e56a2eed066d8c96313f Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 2 Apr 2015 11:56:34 +1100 Subject: [PATCH] Various other fixes --- PlotSquared/pom.xml | 2 +- .../intellectualcrafters/plot/BukkitMain.java | 7 +------ .../plot/generator/AugmentedPopulator.java | 6 ++++-- .../plot/generator/BukkitHybridUtils.java | 2 +- .../plot/util/ClusterManager.java | 3 ++- .../plot/util/MainUtil.java | 8 +++++-- .../plot/util/bukkit/BukkitChunkManager.java | 5 +---- .../plot/util/bukkit/BukkitSetupUtils.java | 4 ++-- .../plot/util/bukkit/SendChunk.java | 21 ++++++++++++++++--- .../plot/util/bukkit/SetBlockFast.java | 21 ++++++++++++++++--- .../plot/util/bukkit/SetBlockFast_1_8.java | 6 +++--- .../plot/util/bukkit/SetBlockSlow.java | 16 +++++++++++++- 12 files changed, 72 insertions(+), 29 deletions(-) diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index 1a9532c40..44fae6f26 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.9.1 + 2.9.2 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 b145d76ab..2e2654d73 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -289,12 +289,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { BlockUpdateUtil.setBlockManager = BukkitSetBlockManager.setBlockManager; try { new SendChunk(); - if (checkVersion(1, 7, 10) && !checkVersion(1, 7, 11)) { - MainUtil.canSendChunk = false; - } - else { - MainUtil.canSendChunk = true; - } + MainUtil.canSendChunk = true; } catch (final Throwable e) { MainUtil.canSendChunk = false; } 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 9991b745f..fe284fdcb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -11,6 +11,7 @@ import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.BlockWrapper; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotGenerator; @@ -19,6 +20,7 @@ import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; @@ -128,7 +130,7 @@ public class AugmentedPopulator extends BlockPopulator { @Override public void run() { populateBiome(world, x, z); - chunk.unload(true, true); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); } }, 20); } else { @@ -143,7 +145,7 @@ public class AugmentedPopulator extends BlockPopulator { public void run() { chunk.load(true); populateBlocks(world, rand, X, Z, x, z, check); - chunk.unload(true, true); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); } }, 40 + rand.nextInt(40)); } 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 8595105e9..fa40e9da6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -151,7 +151,7 @@ public class BukkitHybridUtils extends HybridUtils { final Chunk chunk = world.getChunkAt(x, z); chunks2.add(chunk); regenerateRoad(worldname, new ChunkLoc(x, z)); - ChunkManager.manager.unloadChunk(worldname, new ChunkLoc(x, z)); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); } } } 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 916d660f8..519d01fa6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.generator.AugmentedPopulator; 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.PlotCluster; @@ -276,7 +277,7 @@ public class ClusterManager { public void run() { if ((populator == null) || (plotworld.TYPE == 0)) { world.regenerateChunk(chunk.getX(), chunk.getZ()); - chunk.unload(true, true); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); } else { populator.populate(world, rand, chunk); } 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 28848045d..0981e0b10 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -21,6 +21,7 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.UUID; @@ -29,6 +30,7 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; 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.PlotBlock; @@ -170,6 +172,10 @@ public class MainUtil { } } + public static void update(String world, ChunkLoc loc) { + BlockUpdateUtil.setBlockManager.update(world, Arrays.asList(loc)); + } + // public static void update(final Location loc) { // final String world = loc.getWorld(); // int ox = loc.getX() >> 4; @@ -862,14 +868,12 @@ public class MainUtil { final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(plot2.world, plot2.id); final Location top = MainUtil.getPlotTopLoc(plot1.world, plot1.id); if (plot1.owner == null) { - TaskManager.runTaskLater(whenDone, 1); return false; } final Plot pos1 = getBottomPlot(plot1); final Plot pos2 = getTopPlot(plot1); final PlotId size = MainUtil.getSize(plot1.world, plot1); if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { - TaskManager.runTaskLater(whenDone, 1); return false; } final int offset_x = plot2.id.x - pos1.id.x; 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 index de33208f7..4235c01e1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitChunkManager.java @@ -234,9 +234,6 @@ public class BukkitChunkManager extends ChunkManager { restoreBlocks(newWorld, relX, relZ); restoreEntities(newWorld, relX, relZ); BukkitSetBlockManager.setBlockManager.update(chunks); - for (final Chunk chunk : chunks) { - chunk.unload(true, true); - } TaskManager.runTask(whenDone); Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); TaskManager.tasks.remove(currentIndex); @@ -344,7 +341,7 @@ public class BukkitChunkManager extends ChunkManager { restoreBlocks(world, 0, 0); restoreEntities(world, 0, 0); } - chunk.unload(true, true); + MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); } CURRENT_PLOT_CLEAR = null; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java index 96aeb94f3..3ec8fe1e9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitSetupUtils.java @@ -32,9 +32,9 @@ public class BukkitSetupUtils extends SetupUtils { final String name = plugin.getDescription().getName(); if (generator instanceof PlotGenerator) { final PlotGenerator pgen = (PlotGenerator) generator; - if (pgen.getPlotManager() instanceof SquarePlotManager) { +// if (pgen.getPlotManager() instanceof SquarePlotManager) { SetupUtils.generators.put(name, pgen); - } +// } } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java index 75ec4bc8b..9c4bb056f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/SendChunk.java @@ -10,6 +10,7 @@ import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; +import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; @@ -22,6 +23,8 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; * @author Empire92 */ public class SendChunk { + + private static boolean v1_7_10 = BukkitMain.checkVersion(1, 7, 10) && !BukkitMain.checkVersion(1, 8, 0); // Ref Class private static final RefClass classWorld = getRefClass("{nms}.World"); private static final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer"); @@ -58,6 +61,7 @@ public class SendChunk { int diffx, diffz; final int view = Bukkit.getServer().getViewDistance() << 4; for (final Chunk chunk : chunks) { + boolean unload = true; final Object c = methodGetHandle.of(chunk).call(); final Object w = world.of(c).get(); final Object p = players.of(w).get(); @@ -67,11 +71,22 @@ public class SendChunk { diffx = Math.abs(x - (chunk.getX() << 4)); diffz = Math.abs(z - (chunk.getZ() << 4)); if ((diffx <= view) && (diffz <= view)) { - final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); - final Object pq = chunkCoordIntPairQueue.of(ep).get(); - ((List) pq).add(pair); + unload = false; + if (v1_7_10) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(true); + } + else { + final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ()); + final Object pq = chunkCoordIntPairQueue.of(ep).get(); + ((List) pq).add(pair); + } } } + if (unload) { + chunk.unload(true, true); + System.out.print("UNLOADING CHUNK"); + } } } 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 e4570822b..e79f658e1 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 @@ -71,6 +71,8 @@ public class SetBlockFast extends BukkitSetBlockManager { }, 20); } + private ChunkLoc lastLoc = null; + /** * Set the block at the location * @@ -84,6 +86,19 @@ public class SetBlockFast extends BukkitSetBlockManager { */ @Override public void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data) { + + int X = x >> 4; + int Z = z >> 4; + ChunkLoc loc = new ChunkLoc(X, Z); + if (!loc.equals(lastLoc)) { + Chunk chunk = toUpdate.get(loc); + if (chunk == null) { + chunk = world.getChunkAt(X, Z); + toUpdate.put(loc, chunk); + } + chunk.load(false); + } + final Object w = methodGetHandle.of(world).call(); final Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4); final Object block = methodGetById.of(null).call(blockId); @@ -101,9 +116,9 @@ public class SetBlockFast extends BukkitSetBlockManager { return; } if (!MainUtil.canSendChunk) { - for (final Chunk chunk : chunks) { - chunk.unload(); - chunk.load(false); + for (Chunk chunk : chunks) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(true); } return; } 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 8c0ab884c..a40b153fa 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 @@ -317,9 +317,9 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { return; } if (!MainUtil.canSendChunk) { - for (final Chunk chunk : chunks) { - chunk.unload(); - chunk.load(false); + for (Chunk chunk : chunks) { + chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(true); } return; } 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 8420a3ad2..720ae38c1 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,6 +6,8 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Block; +import com.intellectualcrafters.plot.util.MainUtil; + 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) { @@ -25,6 +27,18 @@ public class SetBlockSlow extends BukkitSetBlockManager { @Override public void update(final Collection chunks) { - // TODO Auto-generated method stub + if (MainUtil.canSendChunk) { + try { + SendChunk.sendChunk(chunks); + } catch (final Throwable e) { + MainUtil.canSendChunk = false; + } + } + else { + for (Chunk chunk : chunks) { + chunk.unload(); + chunk.load(true); + } + } } }