From 1723d8266b985e7ec9857d4035fe3c3ff2d4f927 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sat, 18 Jul 2015 16:49:13 +0200 Subject: [PATCH] Add plot descriptions & hide reserved flags from /plot info --- .../com/intellectualcrafters/plot/PS.java | 2 ++ .../plot/commands/Info.java | 9 +++-- .../plot/commands/Set.java | 24 +++++++++++++ .../intellectualcrafters/plot/config/C.java | 4 +++ .../plot/flag/FlagManager.java | 36 +++++++++++-------- 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 3e969f115..7123df4a3 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1120,6 +1120,7 @@ public class PS { FlagManager.addFlag(new AbstractFlag("break", new FlagValue.PlotBlockListValue())); FlagManager.addFlag(new AbstractFlag("use", new FlagValue.PlotBlockListValue())); FlagManager.addFlag(new AbstractFlag("blocked-cmds", new FlagValue.StringListValue())); + FlagManager.addFlag(new AbstractFlag("ice-met", new FlagValue.BooleanValue())); FlagManager.addFlag(new AbstractFlag("gamemode") { public String parseValueRaw(final String value) { @@ -1173,6 +1174,7 @@ public class PS { return "Flag value must be weather type: 'clear' or 'rain'"; } }); + FlagManager.addFlag(new AbstractFlag("description", new FlagValue.StringValue()), true); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 78596cd44..aab7524f1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.UUID; import java.util.regex.Matcher; +import com.intellectualcrafters.plot.flag.Flag; import org.apache.commons.lang.StringUtils; import com.intellectualcrafters.plot.config.C; @@ -199,13 +200,16 @@ public class Info extends SubCommand { final int num = MainUtil.getPlotSelectionIds(id, id2).size(); final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : C.NONE.s(); Location top = MainUtil.getPlotTopLoc(world, plot.id); - Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1,0,1); + Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1); final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2)); final String trusted = getPlayerList(plot.trusted); final String members = getPlayerList(plot.members); final String denied = getPlayerList(plot.denied); - final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot).values(), "$1, $2") : C.NONE.s()), C.replacements); + Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description"); + final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString(); + + final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.settings, true).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.settings, true).values(), "$1, $2") : C.NONE.s()), C.replacements); final boolean build = (player == null) || plot.isAdded(player.getUUID()); String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners()); @@ -214,6 +218,7 @@ public class Info extends SubCommand { info = info.replaceAll("%id%", id.toString()); info = info.replaceAll("%id2%", id2.toString()); info = info.replaceAll("%num%", num + ""); + info = info.replaceAll("%desc%", description); info = info.replaceAll("%biome%", biome); info = info.replaceAll("%owner%", owner); info = info.replaceAll("%members%", members); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/src/main/java/com/intellectualcrafters/plot/commands/Set.java index d1827f3ad..87e0b7f62 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -168,6 +168,30 @@ public class Set extends SubCommand { plot.setHome(blockloc); return MainUtil.sendMessage(plr, C.POSITION_SET); } + if (args[0].equalsIgnoreCase("desc")) { + if (!Permissions.hasPermission(plr, "plots.set.desc")) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.desc"); + return false; + } + if (args.length < 2) { + MainUtil.sendMessage(plr, C.MISSING_DESC); + return false; + } + final StringBuilder desc = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + desc.append(args[i]).append(" "); + } + String descValue = desc.substring(0, desc.length() - 1); + + Flag flag = new Flag(FlagManager.getFlag("description"), descValue); + final boolean result = FlagManager.addPlotFlag(plot, flag); + if (!result) { + MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED); + return false; + } + MainUtil.sendMessage(plr, C.DESC_SET); + return true; + } if (args[0].equalsIgnoreCase("alias")) { if (!Permissions.hasPermission(plr, "plots.set.alias")) { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.alias"); diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 4cccced2d..5be216dbf 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -227,6 +227,10 @@ public enum C { * BarAPI */ BOSSBAR_CLEARING("$2Clearing plot: $1%id%", "Bar API"), + + DESC_SET("$2Plot description set", "Desc"), + MISSING_DESC("$2You need to specify a description", "Desc"), + /* * Alias */ diff --git a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 9a847ebea..677b72d10 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -20,11 +20,7 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.flag; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; @@ -237,16 +233,28 @@ public class FlagManager { return getSettingFlags(plot.world, plot.settings); } + public static HashMap getPlotFlags(final String world, final PlotSettings settings, final boolean ignorePluginflags) { + HashMap flags = new HashMap<>(); + + PlotWorld plotWorld = PS.get().getPlotWorld(world); + if (plotWorld != null && plotWorld.DEFAULT_FLAGS.size() != 0) { + flags.putAll(plotWorld.DEFAULT_FLAGS); + } + + if (ignorePluginflags) { + for (final Map.Entry flag : settings.flags.entrySet()) { + if (isReserved(flag.getValue().getAbstractFlag().getKey())) continue; + flags.put(flag.getKey(), flag.getValue()); + } + } else { + flags.putAll(settings.flags); + } + + return flags; + } + public static HashMap getSettingFlags(final String world, final PlotSettings settings) { - PlotWorld plotworld = PS.get().getPlotWorld(world); - if (plotworld == null || plotworld.DEFAULT_FLAGS.size() == 0) { - return settings.flags; - } - else { - HashMap map = (HashMap) plotworld.DEFAULT_FLAGS.clone(); - map.putAll(settings.flags); - return map; - } + return getPlotFlags(world, settings, false); } public static boolean removePlotFlag(final Plot plot, final String id) {