From 404933c3a7a09e75b8c4f094605eb57b3cd15599 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sun, 19 Jul 2015 14:52:59 +1000 Subject: [PATCH] Fixes Fix plot time / gamemode on teleport to another plot. Fix gamemode bypass on plot leave --- .../intellectualcrafters/plot/config/C.java | 2 +- .../plot/listeners/PlayerEvents.java | 22 ++++++------- .../plot/listeners/PlotListener.java | 32 ++++++++++++------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index dc14f16f6..7965791c2 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -105,7 +105,7 @@ public enum C { WORLDEDIT_UNMASKED("$1Your WorldEdit is now unrestricted.", "WorldEdit Masks"), WORLDEDIT_RESTRICTED("$1Your WorldEdit is now restricted.", "WorldEdit Masks"), - GAMEMODE_WAS_BYPASSED("$1You bypassed the gamemode ($2{gamemode}$1) $1set for this plot", "Gamemode"), + GAMEMODE_WAS_BYPASSED("$1You bypassed the gamemode ($2{gamemode}$1) $1set for $2{plot}", "Gamemode"), HEIGHT_LIMIT("$1This plot world has a height limit of $2{limit}", "Height Limit"), /* * Records diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 91a62c926..0ac241175 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -453,15 +453,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); - PlotId lastId = (PlotId) pp.getMeta("lastplotid"); + Plot lastPlot = (Plot) pp.getMeta("lastplot"); if (id == null) { - if (lastId == null) { + if (lastPlot == null) { return; } - Plot plot = MainUtil.getPlot(worldname, lastId); - if (!plotExit(pp, plot)) { + if (!plotExit(pp, lastPlot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.exit.denied"); - if (plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { + if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { player.teleport(from); } else { @@ -471,7 +470,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } } - else if (id.equals(lastId)) { + else if (lastPlot != null && id.equals(lastPlot.id)) { return; } else { @@ -516,15 +515,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); - PlotId lastId = (PlotId) pp.getMeta("lastplotid"); + Plot lastPlot = (Plot) pp.getMeta("lastplot"); if (id == null) { - if (lastId == null) { + if (lastPlot == null) { return; } - Plot plot = MainUtil.getPlot(worldname, lastId); - if (!plotExit(pp, plot)) { + if (!plotExit(pp, lastPlot)) { MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.exit.denied"); - if (plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { + if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { player.teleport(from); } else { @@ -534,7 +532,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi return; } } - else if (id.equals(lastId)) { + else if (lastPlot != null && id.equals(lastPlot.id)) { return; } else { diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java b/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java index 63995f27f..94265a97a 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -104,7 +104,11 @@ public class PlotListener extends APlotListener { if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) { return false; } - pp.setMeta("lastplotid", plot.id); + Plot last = (Plot) pp.getMeta("lastplot"); + if (last != null && !last.id.equals(plot.id)) { + plotExit(pp, last); + } + pp.setMeta("lastplot", plot); final Player player = ((BukkitPlayer) pp).player; if (plot.hasOwner()) { final PlayerEnterPlotEvent callEvent = new PlayerEnterPlotEvent(player, plot); @@ -130,14 +134,13 @@ public class PlotListener extends APlotListener { final Flag gamemodeFlag = flags.get("gamemode"); if (gamemodeFlag != null) { - if (!player.hasPermission("plots.gamemode.bypass")) { - player.setGameMode(getGameMode(gamemodeFlag.getValueString())); - } else { - MainUtil.sendMessage( - pp, - C.GAMEMODE_WAS_BYPASSED.s().replace("{plot}", plot.getId().toString()).replace("{gamemode}", gamemodeFlag.getValueString()), - true - ); + if (player.getGameMode() != getGameMode(gamemodeFlag.getValueString())) { + if (!player.hasPermission("plots.gamemode.bypass")) { + player.setGameMode(getGameMode(gamemodeFlag.getValueString())); + } + else { + MainUtil.sendMessage(pp, StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.id, "{gamemode}", gamemodeFlag.getValue())); + } } } final Flag flyFlag = flags.get("fly"); @@ -221,7 +224,7 @@ public class PlotListener extends APlotListener { } public boolean plotExit(final PlotPlayer pp, final Plot plot) { - pp.deleteMeta("lastplotid"); + pp.deleteMeta("lastplot"); Player player = ((BukkitPlayer) pp).player; final PlayerLeavePlotEvent callEvent = new PlayerLeavePlotEvent(player, plot); Bukkit.getPluginManager().callEvent(callEvent); @@ -229,7 +232,14 @@ public class PlotListener extends APlotListener { player.setAllowFlight(Bukkit.getAllowFlight()); } if (FlagManager.getPlotFlag(plot, "gamemode") != null) { - player.setGameMode(Bukkit.getDefaultGameMode()); + if (player.getGameMode() != Bukkit.getDefaultGameMode()) { + if (!player.hasPermission("plots.gamemode.bypass")) { + player.setGameMode(Bukkit.getDefaultGameMode()); + } + else { + MainUtil.sendMessage(pp, StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.world, "{gamemode}", Bukkit.getDefaultGameMode().name().toLowerCase())); + } + } } if (FlagManager.getPlotFlag(plot, "time") != null) { player.resetPlayerTime();