From c774e8b375c232b89eafc3a47f41a38af7a88afc Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 25 Jun 2015 05:06:47 +1000 Subject: [PATCH] Added flag reservation --- PlotSquared/pom.xml | 2 +- .../plot/PlotSquared.java | 1 + .../plot/commands/FlagCmd.java | 4 ++ .../plot/commands/Set.java | 2 +- .../plot/flag/FlagManager.java | 46 ++++++++++++++++++- 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index b2efb340b..1a1db655a 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.11.23 + 2.11.24 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index f86e96ee7..777545427 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -718,6 +718,7 @@ public class PlotSquared { for (final String flag : intFlags) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); } + FlagManager.addFlag(new AbstractFlag("modified-blocks", new FlagValue.IntegerValue()), true); FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("fly", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("explosion", new FlagValue.BooleanValue())); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index 4414a483a..8503b914e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -71,6 +71,10 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other"); return false; } + if (args.length > 1 && FlagManager.isReserved(args[1])) { + MainUtil.sendMessage(player, C.NOT_VALID_FLAG); + return false; + } switch (args[0].toLowerCase()) { case "info": { if (!Permissions.hasPermission(player, "plots.set.flag")) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index fe718a0dd..1fa044b8b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -106,7 +106,7 @@ public class Set extends SubCommand { } catch (final Exception e) { af = new AbstractFlag(args[1].toLowerCase()); } - if (!FlagManager.getFlags().contains(af)) { + if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey())) { MainUtil.sendMessage(plr, C.NOT_VALID_FLAG); return false; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 837c8ad61..3e8b9181a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -50,8 +50,44 @@ public class FlagManager { // - Plot clear interval // - Mob cap // - customized plot composition + + private final static HashSet reserved = new HashSet<>(); + private final static HashSet flags = new HashSet<>(); + /** + * Reserve a flag so that it cannot be set by players + * @param flag + */ + public static void reserveFlag(String flag) { + reserved.add(flag); + } + + /** + * Get if a flag is reserved + * @param flag + * @return + */ + public static boolean isReserved(String flag) { + return reserved.contains(flag); + } + + /** + * Get the reserved flags + * @return + */ + public static HashSet getReservedFlags() { + return (HashSet) reserved.clone(); + } + + /** + * Unreserve a flag + * @param flag + */ + public static void unreserveFlag(String flag) { + reserved.remove(flag); + } + /** * Register an AbstractFlag with PlotSquared * @@ -60,6 +96,10 @@ public class FlagManager { * @return boolean success */ public static boolean addFlag(AbstractFlag af) { + return addFlag(af, false); + } + + public static boolean addFlag(AbstractFlag af, boolean reserved) { PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af); for (PlotWorld plotworld : PlotSquared.getPlotWorldObjects()) { Flag flag = plotworld.DEFAULT_FLAGS.get(af.getKey()); @@ -75,7 +115,11 @@ public class FlagManager { } } } - return (getFlag(af.getKey()) == null) && flags.add(af); + if ((getFlag(af.getKey()) == null) && flags.add(af)) { + if (reserved) reserveFlag(af.getKey()); + return true; + } + return false; } public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) {