From a601739fbd9151bc5a93bdd9a6efdfccd6a813a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Oct 2019 11:25:33 +0100 Subject: [PATCH 1/7] Improve handling of list flags, which in turn resolves issues where add and remove would allow players to add flags with unrecognized values. --- .../plotsquared/plot/commands/FlagCmd.java | 46 ++++++++++--------- .../plot/flag/PlotBlockListFlag.java | 16 +++---- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index 84446aa00..833c0b780 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -197,25 +197,26 @@ public class FlagCmd extends SubCommand { } if (args.length == 3 && flag instanceof ListFlag) { String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - Optional flag1 = - plot.getFlag((Flag>) flag); - if (flag1.isPresent()) { - boolean o = flag1.get().removeAll((Collection) flag.parseValue(value)); - if (o) { - if (flag1.get().isEmpty()) { - final boolean result = plot.removeFlag(flag); - if (result) { - MainUtil.sendMessage(player, Captions.FLAG_REMOVED); + final ListFlag listFlag = (ListFlag) flag; + final Optional collectionOptional = plot.getFlag(listFlag); + if (collectionOptional.isPresent()) { + final Collection parsedCollection = (Collection) flag.parseValue(value); + if (parsedCollection.isEmpty()) { + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + } + final Collection flagCollection = collectionOptional.get(); + if (flagCollection.removeAll(parsedCollection)) { + if (flagCollection.isEmpty()) { + if (plot.removeFlag(flag)) { + return MainUtil.sendMessage(player, Captions.FLAG_REMOVED); } else { - MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); } - return true; } else { MainUtil.sendMessage(player, Captions.FLAG_REMOVED); } } else { - MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); - return false; + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); } } DBFunc.setFlags(plot, plot.getFlags()); @@ -259,16 +260,19 @@ public class FlagCmd extends SubCommand { } Object val = parsed; if (flag instanceof ListFlag) { - Optional flag1 = - plot.getFlag((Flag>) flag); - if (flag1.isPresent()) { - boolean o = flag1.get().addAll((Collection) parsed); - if (o) { + final Collection parsedCollection = (Collection) parsed; + if (parsedCollection.isEmpty()) { + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); + } + final ListFlag listFlag = (ListFlag) flag; + final Optional collectionOptional = plot.getFlag(listFlag); + if (collectionOptional.isPresent()) { + final Collection flagCollection = collectionOptional.get(); + if (flagCollection.addAll(parsedCollection)) { MainUtil.sendMessage(player, Captions.FLAG_ADDED); - val = flag1.get(); + val = flagCollection; } else { - MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - return false; + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java index 56cd0e901..4be8ac475 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java @@ -2,9 +2,14 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import java.util.Arrays; import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; public class PlotBlockListFlag extends ListFlag> { @@ -17,14 +22,9 @@ public class PlotBlockListFlag extends ListFlag> { } @Override public HashSet parseValue(final String value) { - final HashSet list = new HashSet<>(); - for (final String item : value.split(",")) { - final PlotBlock block = PlotSquared.get().IMP.getLegacyMappings().fromAny(item); - if (block != null) { - list.add(block); - } - } - return list; + final LegacyMappings legacyMappings = PlotSquared.get().IMP.getLegacyMappings(); + return Arrays.stream(value.split(",")).map(legacyMappings::fromAny).filter(Objects::nonNull) + .collect(Collectors.toCollection(HashSet::new)); } @Override public String getValueDescription() { From 01eee306f10b8220dfd47d6419cefa74ef1aac46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Oct 2019 11:45:18 +0100 Subject: [PATCH 2/7] Fixes #2462 by making flag categories translatable. This reflects (somewhat) recent changes to command categories. --- .../plotsquared/plot/commands/FlagCmd.java | 9 ++++---- .../plotsquared/plot/config/Captions.java | 21 ++++++++++++++++--- .../plotsquared/plot/flag/BooleanFlag.java | 3 ++- .../plotsquared/plot/flag/DoubleFlag.java | 4 +++- .../plotsquared/plot/flag/EnumFlag.java | 4 +++- .../plotsquared/plot/flag/Flag.java | 17 ++++++++++++++- .../plotsquared/plot/flag/Flags.java | 3 ++- .../plotsquared/plot/flag/GameModeFlag.java | 3 ++- .../plotsquared/plot/flag/IntegerFlag.java | 3 ++- .../plot/flag/IntegerListFlag.java | 3 ++- .../plotsquared/plot/flag/IntervalFlag.java | 3 ++- .../plotsquared/plot/flag/ListFlag.java | 5 +++++ .../plotsquared/plot/flag/LongFlag.java | 4 +++- .../plot/flag/PlotBlockListFlag.java | 3 ++- .../plot/flag/PlotWeatherFlag.java | 3 ++- .../plotsquared/plot/flag/StringFlag.java | 4 +++- .../plotsquared/plot/flag/StringListFlag.java | 3 ++- .../plot/flag/TeleportDenyFlag.java | 1 + 18 files changed, 75 insertions(+), 21 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index 833c0b780..35888fdde 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -293,11 +293,12 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot flag list"); return false; } - HashMap> flags = new HashMap<>(); + final Map> flags = new HashMap<>(); for (Flag flag1 : Flags.getFlags()) { - String type = flag1.getClass().getSimpleName(); - flags.computeIfAbsent(type, k -> new ArrayList<>()); - flags.get(type).add(flag1.getName()); + final String category = flag1.getCategoryCaption(); + final Collection flagList = + flags.computeIfAbsent(category, k -> new ArrayList<>()); + flagList.add(flag1.getName()); } StringBuilder message = new StringBuilder(); String prefix = ""; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index 35538a637..d0e386ea3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -567,9 +567,7 @@ public enum Captions { // BUCKET_ENTRIES_IGNORED("$2Total bucket values add up to 1 or more. Blocks without a specified chance will be ignored","Generator_Bucket"), - /** - * Command Categories - */ + // COMMAND_CATEGORY_CLAIMING("Claiming", "Category"), COMMAND_CATEGORY_TELEPORT("Teleport", "Category"), COMMAND_CATEGORY_SETTINGS("Protection", "Category"), @@ -579,6 +577,7 @@ public enum Captions { COMMAND_CATEGORY_INFO("Info", "Category"), COMMAND_CATEGORY_DEBUG("Debug", "Category"), COMMAND_CATEGORY_ADMINISTRATION("Admin", "Category"), + // // GRANTED_PLOTS("$1Result: $2%s $1grants left", "Grants"), @@ -586,6 +585,22 @@ public enum Captions { GRANTED_PLOT_FAILED("$1Grant failed: $2%s", "Grants"), // + // + FLAG_CATEGORY_STRING("String Flags", "Flags"), + FLAG_CATEGORY_INTEGERS("Integer Flags", "Flags"), + FLAG_CATEGORY_TELEPORT_DENY("Teleport Deny Flag", "Flags"), + FLAG_CATEGORY_STRING_LIST("String List Flags", "Flags"), + FLAG_CATEGORY_WEATHER("Weather Flags", "Flags"), + FLAG_CATEGORY_BLOCK_LIST("Material Flags", "Flags"), + FLAG_CATEGORY_INTERVALS("Interval Flags", "Flags"), + FLAG_CATEGORY_INTEGER_LIST("Integer List Flags", "Flags"), + FLAG_CATEGORY_GAMEMODE("Game Mode Flags", "Flags"), + FLAG_CATEGORY_ENUM("Generic Enum Flags", "Flags"), + FLAG_CATEGORY_DECIMAL("Decimal Flags", "Flags"), + FLAG_CATEGORY_BOOLEAN("Boolean Flags", "Flags"), + FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"), + // + /** * Legacy Configuration Conversion */ diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BooleanFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BooleanFlag.java index a492c9c0f..841df766c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BooleanFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/BooleanFlag.java @@ -1,11 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Plot; public class BooleanFlag extends Flag { public BooleanFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_BOOLEAN, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/DoubleFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/DoubleFlag.java index 9b46a2cde..8cc665471 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/DoubleFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/DoubleFlag.java @@ -1,9 +1,11 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; + public class DoubleFlag extends Flag { public DoubleFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_DECIMAL, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/EnumFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/EnumFlag.java index 3ba6b2457..88119bbaa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/EnumFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/EnumFlag.java @@ -1,15 +1,17 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.util.Arrays; import java.util.HashSet; public class EnumFlag extends Flag { + private final HashSet values; public EnumFlag(String name, String... values) { - super(name); + super(Captions.FLAG_CATEGORY_ENUM, name); this.values = new HashSet<>(Arrays.asList(values)); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flag.java index 3b247d87a..21047d9cd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flag.java @@ -1,13 +1,21 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.util.StringComparison; +import lombok.Getter; public abstract class Flag implements StringComparison.StringComparable { + @Getter private final Captions typeCaption; private final String name; private boolean reserved = false; + public Flag(Captions typeCaption, String name) { + this.typeCaption = typeCaption; + this.name = name; + } + /** * Flag object used to store basic information for a Plot. Flags are a * key/value pair. For a flag to be usable by a player, you need to @@ -16,7 +24,7 @@ public abstract class Flag implements StringComparison.StringComparable { * @param name the flag name */ public Flag(String name) { - this.name = name; + this(null, name); } public Flag reserve() { @@ -57,4 +65,11 @@ public abstract class Flag implements StringComparison.StringComparable { @Override public String getComparableString() { return getName(); } + + public String getCategoryCaption() { + return this.typeCaption == null ? + getClass().getSimpleName() : + this.typeCaption.getTranslated(); + } + } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index fc203a00b..ed5560f09 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan; @@ -95,7 +96,7 @@ public final class Flags { public static final IntegerFlag ANIMAL_CAP = new IntegerFlag("animal-cap"); public static final IntegerFlag HOSTILE_CAP = new IntegerFlag("hostile-cap"); public static final IntegerFlag VEHICLE_CAP = new IntegerFlag("vehicle-cap"); - public static final Flag KEEP = new Flag("keep") { + public static final Flag KEEP = new Flag(Captions.FLAG_CATEGORY_MIXED, "keep") { @Override public String valueToString(Object value) { return value.toString(); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java index 80225c2aa..26510b35b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java @@ -1,11 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; public class GameModeFlag extends Flag { public GameModeFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_GAMEMODE, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerFlag.java index 2cafed4d1..ced532cd1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerFlag.java @@ -1,11 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Plot; public class IntegerFlag extends Flag { public IntegerFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_INTEGERS, name); } @Override public String getValueDescription() { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerListFlag.java index e46071b86..1f24cb4a3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntegerListFlag.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.util.ArrayList; @@ -9,7 +10,7 @@ import java.util.List; public class IntegerListFlag extends ListFlag> { public IntegerListFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_INTEGER_LIST, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java index c8f490591..0468c59b2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/IntervalFlag.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -7,7 +8,7 @@ import lombok.RequiredArgsConstructor; public class IntervalFlag extends Flag { public IntervalFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_INTERVALS, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ListFlag.java index 518c3df11..3085288b1 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/ListFlag.java @@ -1,11 +1,16 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.Plot; import java.util.Collection; public abstract class ListFlag> extends Flag { + public ListFlag(Captions typeCaption, String name) { + super(typeCaption, name); + } + public ListFlag(String name) { super(name); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/LongFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/LongFlag.java index 464780af8..8d57e8865 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/LongFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/LongFlag.java @@ -1,9 +1,11 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; + public class LongFlag extends Flag { public LongFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_INTEGERS, name); } @Override public Long parseValue(String value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java index 4be8ac475..93bd8c56f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.PlotSquared; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; import com.github.intellectualsites.plotsquared.plot.util.StringMan; @@ -14,7 +15,7 @@ import java.util.stream.Collectors; public class PlotBlockListFlag extends ListFlag> { public PlotBlockListFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_BLOCK_LIST, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotWeatherFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotWeatherFlag.java index e6f93ee2d..43544748f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotWeatherFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotWeatherFlag.java @@ -1,11 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; public class PlotWeatherFlag extends Flag { public PlotWeatherFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_WEATHER, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java index 36a68f66b..6438ec938 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringFlag.java @@ -1,10 +1,12 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; + public class StringFlag extends Flag { public StringFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_STRING, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringListFlag.java index 8f02a3801..a1e28aa3d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/StringListFlag.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.flag; +import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import java.util.ArrayList; @@ -9,7 +10,7 @@ import java.util.List; public class StringListFlag extends ListFlag> { public StringListFlag(String name) { - super(name); + super(Captions.FLAG_CATEGORY_STRING_LIST, name); } @Override public String valueToString(Object value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/TeleportDenyFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/TeleportDenyFlag.java index 90f6c292c..6c02516fd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/TeleportDenyFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/TeleportDenyFlag.java @@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; public class TeleportDenyFlag extends EnumFlag { + public TeleportDenyFlag(String name) { super(name, "trusted", "members", "nonmembers", "nontrusted", "nonowners"); } From cb52ee8cfb0e48b36d291be0a7a43d053494d537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Oct 2019 11:55:15 +0100 Subject: [PATCH 3/7] Make the flag list output message configurable. --- .../plotsquared/plot/commands/FlagCmd.java | 20 ++++++----- .../plotsquared/plot/config/Captions.java | 33 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index 35888fdde..18976edac 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -300,15 +300,19 @@ public class FlagCmd extends SubCommand { flags.computeIfAbsent(category, k -> new ArrayList<>()); flagList.add(flag1.getName()); } - StringBuilder message = new StringBuilder(); - String prefix = ""; - for (Map.Entry> entry : flags.entrySet()) { - String category = entry.getKey(); - List flagNames = entry.getValue(); + + final StringBuilder message = new StringBuilder(); + final Iterator>> iterator = + flags.entrySet().iterator(); + while (iterator.hasNext()) { + final Map.Entry> flagsEntry = iterator.next(); + final List flagNames = flagsEntry.getValue(); Collections.sort(flagNames); - message.append(prefix).append("&6").append(category).append(": &7") - .append(StringMan.join(flagNames, ", ")); - prefix = "\n"; + message.append(String.format(Captions.FLAG_LIST_ENTRY.formatted(), + flagsEntry.getKey(), StringMan.join(flagNames, ", "))); + if (iterator.hasNext()) { + message.append("\n"); + } } MainUtil.sendMessage(player, message.toString()); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index d0e386ea3..f148d445b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -532,7 +532,24 @@ public enum Captions { FLAG_REMOVED("$4Successfully removed flag", "Flag"), FLAG_ADDED("$4Successfully added flag", "Flag"), FLAG_TUTORIAL_USAGE("$1Have an admin set the flag: $2%s", "CommandConfig"), + FLAG_LIST_ENTRY("$2%s: $1%s", "Flag"), // + // + FLAG_CATEGORY_STRING("String Flags", "Flags"), + FLAG_CATEGORY_INTEGERS("Integer Flags", "Flags"), + FLAG_CATEGORY_TELEPORT_DENY("Teleport Deny Flag", "Flags"), + FLAG_CATEGORY_STRING_LIST("String List Flags", "Flags"), + FLAG_CATEGORY_WEATHER("Weather Flags", "Flags"), + FLAG_CATEGORY_BLOCK_LIST("Material Flags", "Flags"), + FLAG_CATEGORY_INTERVALS("Interval Flags", "Flags"), + FLAG_CATEGORY_INTEGER_LIST("Integer List Flags", "Flags"), + FLAG_CATEGORY_GAMEMODE("Game Mode Flags", "Flags"), + FLAG_CATEGORY_ENUM("Generic Enum Flags", "Flags"), + FLAG_CATEGORY_DECIMAL("Decimal Flags", "Flags"), + FLAG_CATEGORY_BOOLEAN("Boolean Flags", "Flags"), + FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"), + // + // TRUSTED_ADDED("$4You successfully trusted a user to the plot", "Trusted"), WAS_NOT_ADDED("$2That player was not trusted on this plot", "Trusted"), @@ -585,22 +602,6 @@ public enum Captions { GRANTED_PLOT_FAILED("$1Grant failed: $2%s", "Grants"), // - // - FLAG_CATEGORY_STRING("String Flags", "Flags"), - FLAG_CATEGORY_INTEGERS("Integer Flags", "Flags"), - FLAG_CATEGORY_TELEPORT_DENY("Teleport Deny Flag", "Flags"), - FLAG_CATEGORY_STRING_LIST("String List Flags", "Flags"), - FLAG_CATEGORY_WEATHER("Weather Flags", "Flags"), - FLAG_CATEGORY_BLOCK_LIST("Material Flags", "Flags"), - FLAG_CATEGORY_INTERVALS("Interval Flags", "Flags"), - FLAG_CATEGORY_INTEGER_LIST("Integer List Flags", "Flags"), - FLAG_CATEGORY_GAMEMODE("Game Mode Flags", "Flags"), - FLAG_CATEGORY_ENUM("Generic Enum Flags", "Flags"), - FLAG_CATEGORY_DECIMAL("Decimal Flags", "Flags"), - FLAG_CATEGORY_BOOLEAN("Boolean Flags", "Flags"), - FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"), - // - /** * Legacy Configuration Conversion */ From 2e15934666faa7e765e281cb5de83e2bdbbd123b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Oct 2019 12:01:04 +0100 Subject: [PATCH 4/7] Fix `/plot flag set` allowing for invalid flag values. (Fixes #2519) --- .../intellectualsites/plotsquared/plot/commands/FlagCmd.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index 18976edac..af0389dec 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -163,6 +163,11 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, "&c" + flag.getValueDescription()); return false; } + if (flag instanceof ListFlag) { + if (!(parsed instanceof Collection) || ((Collection) parsed).isEmpty()) { + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); + } + } boolean result = plot.setFlag(flag, parsed); if (!result) { MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); From 3be0be1b604c8b58bbbb98e17a0b3fa0dd040083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Oct 2019 12:11:48 +0100 Subject: [PATCH 5/7] Make sure DENY_EXIT checks for the admin override permission. Fixes #2411. --- .../plotsquared/plot/listener/PlotListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java index 4911f9f47..ce1007e15 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlotListener.java @@ -200,7 +200,9 @@ public class PlotListener { if (pw == null) { return true; } - if (Flags.DENY_EXIT.isTrue(plot) && !player.getMeta("kick", false)) { + if (Flags.DENY_EXIT.isTrue(plot) + && !Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_EXIT_DENIED) + && !player.getMeta("kick", false)) { if (previous != null) { player.setMeta(PlotPlayer.META_LAST_PLOT, previous); } From 1f89948948ed63d73f6151b1decbd9728ce7b228 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sun, 27 Oct 2019 16:01:57 +0100 Subject: [PATCH 6/7] Remove unused flags --- .../intellectualsites/plotsquared/plot/config/Captions.java | 1 - .../github/intellectualsites/plotsquared/plot/flag/Flags.java | 3 --- .../intellectualsites/plotsquared/plot/util/EventUtil.java | 3 +-- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java index f148d445b..c319303b6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/config/Captions.java @@ -28,7 +28,6 @@ public enum Captions { FLAG_PVP("pvp", "static.flags"), FLAG_HANGING_PLACE("hanging-place", "static.flags"), FLAG_HANGING_BREAK("hanging-break", "static.flags"), - FLAG_HANGING_INTERACT("hanging-interact", "static.flags"), FLAG_MISC_INTERACT("misc-interact", "static.flags"), FLAG_MISC_BREAK("misc-break", "static.flags"), FLAG_MISC_PLACE("misc-place", "static.flags"), diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index ed5560f09..74b83d887 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -53,7 +53,6 @@ public final class Flags { public static final BooleanFlag SNOW_MELT = new BooleanFlag("snow-melt"); public static final BooleanFlag SNOW_FORM = new BooleanFlag("snow-form"); public static final BooleanFlag ICE_MELT = new BooleanFlag("ice-melt"); - public static final BooleanFlag FIRE_SPREAD = new BooleanFlag("fire-spread"); public static final BooleanFlag BLOCK_BURN = new BooleanFlag("block-burn"); public static final BooleanFlag ICE_FORM = new BooleanFlag("ice-form"); public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition"); @@ -68,7 +67,6 @@ public final class Flags { public static final BooleanFlag VEHICLE_USE = new BooleanFlag("vehicle-use"); public static final BooleanFlag HANGING_BREAK = new BooleanFlag("hanging-break"); public static final BooleanFlag HANGING_PLACE = new BooleanFlag("hanging-place"); - public static final BooleanFlag HANGING_INTERACT = new BooleanFlag("hanging-interact"); public static final BooleanFlag MISC_PLACE = new BooleanFlag("misc-place"); public static final BooleanFlag MISC_BREAK = new BooleanFlag("misc-break"); public static final BooleanFlag MISC_INTERACT = new BooleanFlag("misc-interact"); @@ -119,7 +117,6 @@ public final class Flags { return "Flag value must a timestamp or a boolean"; } }; - public static final BooleanFlag SLEEP = new BooleanFlag("sleep"); public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("deny-teleport"); public static final BooleanFlag DENY_EXIT = new BooleanFlag("deny-exit"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index b2b88d342..fcb376355 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -302,8 +302,7 @@ public abstract class EventUtil { } return !(!notifyPerms || MainUtil .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_USE.getTranslated() + '/' + Captions.FLAG_HANGING_INTERACT - .getTranslated())); + Captions.FLAG_USE.getTranslated())); } return true; } From e29727827d154915e375ad13e1ee9d098353eb90 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sun, 27 Oct 2019 16:02:34 +0100 Subject: [PATCH 7/7] Fix missing word --- .../github/intellectualsites/plotsquared/plot/flag/Flags.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index 74b83d887..1da139665 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -114,7 +114,7 @@ public final class Flags { } @Override public String getValueDescription() { - return "Flag value must a timestamp or a boolean"; + return "Flag value must be a timestamp or a boolean"; } }; public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("deny-teleport");