From 5b56b6786e9079d031e0e1540944b9d69eba6225 Mon Sep 17 00:00:00 2001 From: Byteflux Date: Tue, 9 Jun 2015 15:28:59 -0700 Subject: [PATCH 1/3] Try and teleport players above plot after clearing --- .../plot/util/ChunkManager.java | 2 ++ .../plot/util/ClusterManager.java | 5 ++-- .../plot/util/MainUtil.java | 4 +-- .../plot/util/bukkit/BukkitChunkManager.java | 26 ++++++++++++++++--- .../plot/util/bukkit/BukkitUtil.java | 4 ++- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index e983876cb..1e0ec2ce1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -37,6 +37,8 @@ public abstract class ChunkManager { public abstract List getChunkChunks(String world); + public abstract void regenerateChunk(String world, ChunkLoc loc); + public abstract void deleteRegionFile(final String world, final ChunkLoc loc); public abstract void deleteRegionFiles(final String world, final List chunks); 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 9504032ff..df0f475ef 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -286,8 +286,9 @@ public class ClusterManager { @Override public void run() { if ((populator == null) || (plotworld.TYPE == 0)) { - world.regenerateChunk(chunk.getX(), chunk.getZ()); - MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); + ChunkLoc loc = new ChunkLoc(chunk.getX(), chunk.getZ()); + ChunkManager.manager.regenerateChunk(world.getName(), loc); + MainUtil.update(world.getName(), loc); } 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 a4709ffb1..c94b5d2e6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -272,7 +272,7 @@ public class MainUtil { z = bot.getZ() + plotworld.DEFAULT_HOME.z; } final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(plot.world), plot).getY()); - return new Location(plot.world, x, y, z); + return new Location(plot.world, x, y + 1, z); } final Location top = getPlotTopLoc(plot.world, plot.id); final Location bot = getPlotBottomLoc(plot.world, plot.id); @@ -280,7 +280,7 @@ public class MainUtil { final int z = bot.getZ(); PlotManager manager = PlotSquared.getPlotManager(plot.world); final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(plot.world), plot).getY()); - return new Location(plot.world, x, y, z); + return new Location(plot.world, x, y + 1, z); } public static boolean teleportPlayer(final PlotPlayer player, final Location from, final Plot plot) { 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 652591a85..baf42380a 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 @@ -94,6 +94,22 @@ public class BukkitChunkManager extends ChunkManager { return chunks; } + @Override + public void regenerateChunk(String world, ChunkLoc loc) { + World worldObj = Bukkit.getWorld(world); + worldObj.regenerateChunk(loc.x, loc.z); + for (final Player player : Bukkit.getOnlinePlayers()) { + Location playerLoc = BukkitUtil.getLocation(player.getLocation()); + if (playerLoc.getX() >> 4 == loc.x && playerLoc.getZ() >> 4 == loc.z) { + final Plot plot = MainUtil.getPlot(playerLoc); + if (plot != null) { + final PlotPlayer pp = BukkitUtil.getPlayer(player); + pp.teleport(MainUtil.getDefaultHome(plot)); + } + } + } + } + @Override public void deleteRegionFile(final String world, final ChunkLoc loc) { TaskManager.runTaskAsync(new Runnable() { @@ -360,12 +376,13 @@ public class BukkitChunkManager extends ChunkManager { if (save) { saveEntitiesOut(chunk, CURRENT_PLOT_CLEAR); } - world.regenerateChunk(x, z); + ChunkLoc loc = new ChunkLoc(chunk.getX(), chunk.getZ()); + regenerateChunk(world.getName(), loc); if (save) { restoreBlocks(world, 0, 0); restoreEntities(world, 0, 0); } - MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); + MainUtil.update(world.getName(), loc); BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); } CURRENT_PLOT_CLEAR = null; @@ -1092,12 +1109,13 @@ public class BukkitChunkManager extends ChunkManager { if (save) { saveEntitiesOut(chunk, CURRENT_PLOT_CLEAR); } - world.regenerateChunk(cx, cz); + ChunkLoc chunkLoc = new ChunkLoc(chunk.getX(), chunk.getZ()); + regenerateChunk(world.getName(), chunkLoc); if (save) { restoreBlocks(world, 0, 0); restoreEntities(world, 0, 0); } - MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ())); + MainUtil.update(world.getName(), chunkLoc); BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk })); CURRENT_PLOT_CLEAR = null; } 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 681d80387..ee0cb746a 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 @@ -19,11 +19,13 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import com.intellectualcrafters.plot.object.BukkitPlayer; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.ChunkManager; public class BukkitUtil extends BlockManager { private static HashMap worlds = new HashMap<>(); @@ -157,7 +159,7 @@ public class BukkitUtil extends BlockManager { World worldObj = getWorld(world); Chunk chunk = worldObj.getChunkAt(x, z); if (chunk.isLoaded() || chunk.load(false)) { - worldObj.regenerateChunk(x, z); + ChunkManager.manager.regenerateChunk(world, new ChunkLoc(x, z)); } } From 97d4e29010b0fcd3c131610579f3145fe5fb29ec Mon Sep 17 00:00:00 2001 From: Byteflux Date: Tue, 9 Jun 2015 18:46:36 -0700 Subject: [PATCH 2/3] Only re-teleport players if stuck after chunk has regenerated --- .../plot/util/bukkit/BukkitChunkManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 baf42380a..82da9abd7 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 @@ -98,10 +98,10 @@ public class BukkitChunkManager extends ChunkManager { public void regenerateChunk(String world, ChunkLoc loc) { World worldObj = Bukkit.getWorld(world); worldObj.regenerateChunk(loc.x, loc.z); - for (final Player player : Bukkit.getOnlinePlayers()) { - Location playerLoc = BukkitUtil.getLocation(player.getLocation()); - if (playerLoc.getX() >> 4 == loc.x && playerLoc.getZ() >> 4 == loc.z) { - final Plot plot = MainUtil.getPlot(playerLoc); + 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()) { + final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(locObj)); if (plot != null) { final PlotPlayer pp = BukkitUtil.getPlayer(player); pp.teleport(MainUtil.getDefaultHome(plot)); From fbb35ec6fa752acc17cdc4f437e3a85f37082832 Mon Sep 17 00:00:00 2001 From: confuser Date: Wed, 10 Jun 2015 10:51:52 +0100 Subject: [PATCH 3/3] Added permission to see all plot chat plots.admin.command.chat --- .../com/intellectualcrafters/plot/listeners/PlayerEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 7239ac8b8..19aadae39 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -410,7 +410,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi final Set recipients = event.getRecipients(); recipients.clear(); for (final Player p : Bukkit.getOnlinePlayers()) { - if (plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(p)))) { + if (p.hasPermission("plots.admin.command.chat") || plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(p)))) { recipients.add(p); } }