From 20d64508a59cccd2fff7934e1f84e3a264e3fe7d Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 17 Mar 2015 19:17:15 +1100 Subject: [PATCH] More piston fixes, potential chunk send fix, home teleport fix --- .../plot/listeners/PlayerEvents.java | 5 +++- .../plot/util/MainUtil.java | 25 +++++++++++++++---- .../plot/util/bukkit/BukkitChunkManager.java | 2 +- .../plot/util/bukkit/BukkitUtil.java | 2 +- .../plot/util/bukkit/SetBlockFast.java | 4 +-- .../plot/util/bukkit/SetBlockFast_1_8.java | 4 +-- 6 files changed, 30 insertions(+), 12 deletions(-) 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 561707039..d19e50aea 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -62,6 +62,7 @@ import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.plugin.Plugin; +import org.bukkit.util.Vector; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; @@ -522,8 +523,10 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } Plot plot = MainUtil.getPlot(loc); if (plot != null) { + BlockFace face = event.getDirection(); + Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); for (final Block b : event.getBlocks()) { - Location bloc = BukkitUtil.getLocation(b.getLocation()); + Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative)); Plot newPlot = MainUtil.getPlot(bloc); if (!plot.equals(newPlot)) { event.setCancelled(true); 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 fd130fbdd..3a3b92e32 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -95,18 +95,33 @@ public class MainUtil { } return count; } + + public static Location getPlotFront(Plot plot) { + final Location top = getPlotTopLoc(plot.world, plot.id); + final Location bot = getPlotBottomLoc(plot.world, plot.id); + final int x = ((top.getX() - bot.getX()) / 2) + bot.getX(); + final int z = 0; + 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); + } public static boolean teleportPlayer(final PlotPlayer player, final Location from, final Plot plot) { final Plot bot = MainUtil.getBottomPlot(plot); // TODO // boolean result = PlotSquared.IMP.callPlayerTeleportToPlotEvent(player, from, plot); - - final boolean result = false; + boolean result = EventUtil.manager.callTeleport(player, from, plot); // TOOD ^ remove that - if (!result) { - final Location location = MainUtil.getPlotHome(bot.world, bot); + if (result) { + final Location location; + if (plot.isAdded(player.getUUID())) { + location = MainUtil.getPlotHome(bot.world, bot); + } + else { + location = getPlotFront(plot); + } if ((Settings.TELEPORT_DELAY == 0) || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) { sendMessage(player, C.TELEPORTED_TO_PLOT); player.teleport(location); @@ -132,7 +147,7 @@ public class MainUtil { }, Settings.TELEPORT_DELAY * 20); return true; } - return !result; + return result; } public static int getBorder(final String worldname) { 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 f96679c86..7dde64ef3 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 @@ -765,7 +765,7 @@ public class BukkitChunkManager extends ChunkManager { if (plot.id.equals(id)) { if (entity instanceof Player) { final Player player = (Player) entity; - MainUtil.teleportPlayer(BukkitUtil.getPlayer(player), BukkitUtil.getLocation(entity), plot); + BukkitUtil.getPlayer(player).teleport(MainUtil.getPlotFront(plot)); PlotListener.plotExit(player, plot); } else { entity.remove(); 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 3b8f20348..b76150681 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 @@ -147,7 +147,7 @@ public class BukkitUtil extends BlockManager { public static void refreshChunk(final String name, final int x, final int z) { World world = getWorld(name); - world.unloadChunk(x, z); + world.refreshChunk(x, z); world.loadChunk(x, z); } 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 ddca18980..d149ce32b 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 @@ -90,8 +90,8 @@ public class SetBlockFast extends BukkitSetBlockManager { if (!MainUtil.canSendChunk) { final World world = chunks.get(0).getWorld(); for (final Chunk chunk : chunks) { - world.unloadChunk(chunk); - world.loadChunk(chunk); + world.refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(false); } 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 2d86c5cb0..8f871a61b 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 @@ -294,8 +294,8 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager { if (!MainUtil.canSendChunk) { final World world = chunks.get(0).getWorld(); for (final Chunk chunk : chunks) { - world.unloadChunk(chunk); - world.loadChunk(chunk); + world.refreshChunk(chunk.getX(), chunk.getZ()); + chunk.load(false); } return; }