From 0b19cc7d9dd3c2e07eb5fe65a334950d7c334c4e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 25 Jul 2016 08:02:17 +1000 Subject: [PATCH] Possible fix + add guest-gamemode flag --- .../com/intellectualcrafters/plot/flag/Flags.java | 10 +++++----- .../java/com/plotsquared/listener/PlotListener.java | 13 ++++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java index 7b8247d25..235b3f74a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java @@ -21,6 +21,7 @@ public final class Flags { public static final IntervalFlag FEED = new IntervalFlag("feed"); public static final IntervalFlag HEAL = new IntervalFlag("heal"); public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode"); + public static final GameModeFlag GUEST_GAMEMODE = new GameModeFlag("guest-gamemode"); public static final StringFlag DONE = (StringFlag) new StringFlag("done").reserve(); public static final BooleanFlag REDSTONE = new BooleanFlag("redstone"); public static final BooleanFlag FLY = new BooleanFlag("fly"); @@ -147,8 +148,8 @@ public final class Flags { } public static Flag getFlag(String flag) { - return flags.get(flag); - } + return flags.get(flag); +} public static void registerFlag(final Flag flag) { final Flag duplicate = flags.put(flag.getName(), flag); @@ -164,11 +165,10 @@ public final class Flags { }); PS.get().foreachPlotRaw(new RunnableVal() { @Override public void run(Plot value) { - Object remove = null; if (value.getFlags().containsKey(duplicate)) { - remove = value.getFlags().remove(duplicate); + Object remove = value.getFlags().remove(duplicate); + value.getFlags().put(flag,flag.parseValue("" + remove)); } - value.getFlags().put(flag,flag.parseValue("" + remove)); } }); } diff --git a/Core/src/main/java/com/plotsquared/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/listener/PlotListener.java index 25197fc5f..17f3eee63 100644 --- a/Core/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/listener/PlotListener.java @@ -94,6 +94,17 @@ public class PlotListener { } } } + Optional guestGamemodeFlag = plot.getFlag(Flags.GUEST_GAMEMODE); + if (gamemodeFlag.isPresent()) { + if (player.getGameMode() != gamemodeFlag.get() && !plot.isAdded(player.getUUID())) { + if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) { + player.setGameMode(gamemodeFlag.get()); + } else { + MainUtil.sendMessage(player, + StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.get())); + } + } + } Optional timeFlag = plot.getFlag(Flags.TIME); if (timeFlag.isPresent()) { try { @@ -171,7 +182,7 @@ public class PlotListener { if (pw == null) { return true; } - if (plot.getFlag(Flags.GAMEMODE).isPresent()) { + if (plot.getFlag(Flags.GAMEMODE).isPresent() || plot.getFlag(Flags.GUEST_GAMEMODE).isPresent()) { if (player.getGameMode() != pw.GAMEMODE) { if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) { player.setGameMode(pw.GAMEMODE);