From a3192c9668a13980f989475b799126eec2ee58d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 16 Feb 2020 15:34:10 +0100 Subject: [PATCH] Port description flag --- .../plotsquared/plot/config/Captions.java | 12 ++++--- .../plotsquared/plot/flag/Flags.java | 1 - .../plot/flags/GlobalFlagContainer.java | 2 ++ .../implementations/DescriptionFlag.java | 35 +++++++++++++++++++ .../plotsquared/plot/util/MainUtil.java | 9 +++-- 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/DescriptionFlag.java 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 3b1fbc494..a0b951286 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 @@ -547,11 +547,13 @@ public enum Captions implements Caption { FLAG_CATEGORY_MIXED("Mixed Value Flags", "Flags"), // // - FLAG_DESCRIPTION_EXPLOSION("Set to 'true' to enable explosions in the plot, and 'false' to disable them", "Flags"), - FLAG_DESCRIPTION_MUSIC("Set to a music disk ID (item name) to play the music disc inside of the plot", "Flags"), - FLAG_DESCRIPTION_FLIGHT("Set to 'true' to enable flight within the plot when in survival or adventure mode", "Flags"), - FLAG_DESCRIPTION_UNTRUSTED("Set to 'false' to disallow untrusted players from visiting the plot", "Flags"), - FLAG_DESCRIPTION_DENY_EXIT("Set to 'true' to disallow players from exiting the plot", "Flags"), + FLAG_DESCRIPTION_EXPLOSION("Set to 'true' to enable explosions in the plot, and 'false' to disable them.", "Flags"), + FLAG_DESCRIPTION_MUSIC("Set to a music disk ID (item name) to play the music disc inside of the plot.", "Flags"), + FLAG_DESCRIPTION_FLIGHT("Set to 'true' to enable flight within the plot when in survival or adventure mode.", "Flags"), + FLAG_DESCRIPTION_UNTRUSTED("Set to 'false' to disallow untrusted players from visiting the plot.", "Flags"), + FLAG_DESCRIPTION_DENY_EXIT("Set to 'true' to disallow players from exiting the plot.", "Flags"), + FLAG_DESCRIPTION_DESCRIPTION("Plot description. Supports '&' color codes.", "Flags"), + FLAG_DESCRIPTION_GREETING("Message sent to players on plot entry. Supports '&' color codes.", "Flags"), // // FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "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 ad30bd0bd..4a52a3509 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 @@ -6,7 +6,6 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; public final class Flags { - public static final StringFlag DESCRIPTION = new StringFlag("description"); public static final IntegerListFlag ANALYSIS = (IntegerListFlag) new IntegerListFlag("analysis").reserve(); public static final StringFlag GREETING = new StringFlag("greeting"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java index de8b38ba0..4bfa394f9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/GlobalFlagContainer.java @@ -1,6 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.flags; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DenyExitFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag; @@ -29,6 +30,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(FlightFlag.FLIGHT_FLAG_FALSE); this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE); this.addFlag(DenyExitFlag.DENY_EXIT_FLAG_TRUE); + this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY); } @Override public PlotFlag getFlagErased(Class flagClass) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/DescriptionFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/DescriptionFlag.java new file mode 100644 index 000000000..c0c39f3f9 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/DescriptionFlag.java @@ -0,0 +1,35 @@ +package com.github.intellectualsites.plotsquared.plot.flags.implementations; + +import com.github.intellectualsites.plotsquared.plot.config.Captions; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; +import org.jetbrains.annotations.NotNull; + +public class DescriptionFlag extends PlotFlag { + + public static final DescriptionFlag DESCRIPTION_FLAG_EMPTY = new DescriptionFlag(""); + + protected DescriptionFlag(@NotNull String value) { + super(value, Captions.FLAG_CATEGORY_STRING, Captions.FLAG_DESCRIPTION_DESCRIPTION); + } + + @Override public DescriptionFlag parse(@NotNull String input) { + return flagOf(input); + } + + @Override public DescriptionFlag merge(@NotNull String newValue) { + return flagOf(this.getValue() + " " + newValue); + } + + @Override public String toString() { + return this.getValue(); + } + + @Override public String getExample() { + return "&6Welcome to my plot!"; + } + + @Override protected DescriptionFlag flagOf(@NotNull String value) { + return new DescriptionFlag(value); + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index 460124ef7..05faf46aa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -12,6 +12,7 @@ import com.github.intellectualsites.plotsquared.plot.flag.DoubleFlag; import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.Flags; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.DescriptionFlag; import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; @@ -772,9 +773,11 @@ public class MainUtil { } else { seen = Captions.NEVER.getTranslated(); } - Optional descriptionFlag = plot.getFlag(Flags.DESCRIPTION); - String description = !descriptionFlag.isPresent() ? Captions.NONE.getTranslated() : - Flags.DESCRIPTION.valueToString(descriptionFlag.get()); + + String description = plot.getFlag(DescriptionFlag.class); + if (description.isEmpty()) { + description = Captions.NONE.getTranslated(); + } StringBuilder flags = new StringBuilder(); HashMap, Object> flagMap =