From 70e965d5cb24803819f49c759300bafd08e50504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 16 Feb 2020 15:46:06 +0100 Subject: [PATCH] Port greeting and farewell flags --- .../plotsquared/plot/config/Captions.java | 1 + .../plotsquared/plot/flag/Flags.java | 2 -- .../plot/flags/GlobalFlagContainer.java | 4 +++ .../plotsquared/plot/flags/InternalFlag.java | 4 +++ .../implementations/DescriptionFlag.java | 2 +- .../flags/implementations/ExplosionFlag.java | 1 + .../flags/implementations/FarewellFlag.java | 35 +++++++++++++++++++ .../flags/implementations/FlightFlag.java | 1 + .../flags/implementations/GreetingFlag.java | 35 +++++++++++++++++++ .../implementations/UntrustedVisitFlag.java | 1 + .../plot/listener/PlotListener.java | 32 +++++++++-------- .../plotsquared/plot/object/PlotSettings.java | 25 ------------- 12 files changed, 101 insertions(+), 42 deletions(-) create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/InternalFlag.java create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FarewellFlag.java create mode 100644 Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/GreetingFlag.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 a0b951286..86d39129a 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 @@ -554,6 +554,7 @@ public enum Captions implements Caption { 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_DESCRIPTION_FAREWELL("Message sent to players when leaving the plot. 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 4a52a3509..23913614f 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 @@ -8,8 +8,6 @@ public final class Flags { public static final IntegerListFlag ANALYSIS = (IntegerListFlag) new IntegerListFlag("analysis").reserve(); - public static final StringFlag GREETING = new StringFlag("greeting"); - public static final StringFlag FAREWELL = new StringFlag("farewell"); public static final IntervalFlag FEED = new IntervalFlag("feed"); public static final IntervalFlag HEAL = new IntervalFlag("heal"); public static final GameModeFlag GAMEMODE = new GameModeFlag("gamemode"); 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 4bfa394f9..1c105612c 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 @@ -3,7 +3,9 @@ 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.FarewellFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.UntrustedVisitFlag; import lombok.Getter; @@ -31,6 +33,8 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(UntrustedVisitFlag.UNTRUSTED_VISIT_FLAG_TRUE); this.addFlag(DenyExitFlag.DENY_EXIT_FLAG_TRUE); this.addFlag(DescriptionFlag.DESCRIPTION_FLAG_EMPTY); + this.addFlag(GreetingFlag.GREETING_FLAG_EMPTY); + this.addFlag(FarewellFlag.FAREWELL_FLAG_EMPTY); } @Override public PlotFlag getFlagErased(Class flagClass) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/InternalFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/InternalFlag.java new file mode 100644 index 000000000..7c396d5be --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/InternalFlag.java @@ -0,0 +1,4 @@ +package com.github.intellectualsites.plotsquared.plot.flags; + +public interface InternalFlag { +} 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 index c0c39f3f9..eddd908df 100644 --- 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 @@ -25,7 +25,7 @@ public class DescriptionFlag extends PlotFlag { } @Override public String getExample() { - return "&6Welcome to my plot!"; + return "&6This is my plot!"; } @Override protected DescriptionFlag flagOf(@NotNull String value) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/ExplosionFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/ExplosionFlag.java index 9b7f6858e..9233a266b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/ExplosionFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/ExplosionFlag.java @@ -20,4 +20,5 @@ public class ExplosionFlag extends BooleanFlag { @Override protected ExplosionFlag flagOf(@NotNull Boolean value) { return value ? EXPLOSION_TRUE : EXPLOSION_FALSE; } + } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FarewellFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FarewellFlag.java new file mode 100644 index 000000000..b2ddebef3 --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FarewellFlag.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 FarewellFlag extends PlotFlag { + + public static final FarewellFlag FAREWELL_FLAG_EMPTY = new FarewellFlag(""); + + protected FarewellFlag(@NotNull String value) { + super(value, Captions.FLAG_CATEGORY_STRING, Captions.FLAG_DESCRIPTION_FAREWELL); + } + + @Override public FarewellFlag parse(@NotNull String input) { + return flagOf(input); + } + + @Override public FarewellFlag merge(@NotNull String newValue) { + return flagOf(this.getValue() + " " + newValue); + } + + @Override public String toString() { + return this.getValue(); + } + + @Override public String getExample() { + return "&cBye :("; + } + + @Override protected FarewellFlag flagOf(@NotNull String value) { + return new FarewellFlag(value); + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java index 099145165..e14fd8e5f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/FlightFlag.java @@ -19,4 +19,5 @@ public class FlightFlag extends BooleanFlag { @Override protected FlightFlag flagOf(@NotNull Boolean value) { return new FlightFlag(value); } + } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/GreetingFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/GreetingFlag.java new file mode 100644 index 000000000..736ce6d2a --- /dev/null +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/GreetingFlag.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 GreetingFlag extends PlotFlag { + + public static final GreetingFlag GREETING_FLAG_EMPTY = new GreetingFlag(""); + + protected GreetingFlag(@NotNull String value) { + super(value, Captions.FLAG_CATEGORY_STRING, Captions.FLAG_DESCRIPTION_GREETING); + } + + @Override public GreetingFlag parse(@NotNull String input) { + return flagOf(input); + } + + @Override public GreetingFlag 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 GreetingFlag flagOf(@NotNull String value) { + return new GreetingFlag(value); + } + +} diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java index 9d587f626..b0628cf20 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/UntrustedVisitFlag.java @@ -19,4 +19,5 @@ public class UntrustedVisitFlag extends BooleanFlag { @Override protected UntrustedVisitFlag flagOf(@NotNull Boolean value) { return new UntrustedVisitFlag(value); } + } 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 e5d762e74..041d78d43 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 @@ -6,7 +6,9 @@ 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.DenyExitFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.FarewellFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.FlightFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.GreetingFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.Plot; @@ -60,7 +62,7 @@ public class PlotListener { } else { titles = Settings.TITLES; } - final String greeting; + String greeting; if (flags.isEmpty()) { if (titles) { greeting = ""; @@ -69,9 +71,9 @@ public class PlotListener { } } else { titles = plot.getFlag(Flags.TITLES, titles); - Optional greetingFlag = plot.getFlag(Flags.GREETING); - if (greetingFlag.isPresent()) { - greeting = greetingFlag.get(); + + greeting = plot.getFlag(GreetingFlag.class); + if (!greeting.isEmpty()) { MainUtil .format(Captions.PREFIX_GREETING.getTranslated() + greeting, plot, player, false, @@ -80,8 +82,6 @@ public class PlotListener { MainUtil.sendMessage(player, value); } }); - } else { - greeting = ""; } Optional enter = plot.getFlag(Flags.NOTIFY_ENTER); if (enter.isPresent() && enter.get()) { @@ -234,14 +234,18 @@ public class PlotListener { } } } - Optional farewell = plot.getFlag(Flags.FAREWELL); - farewell.ifPresent(s -> MainUtil - .format(Captions.PREFIX_FAREWELL.getTranslated() + s, plot, player, false, - new RunnableVal() { - @Override public void run(String value) { - MainUtil.sendMessage(player, value); - } - })); + + final String farewell = plot.getFlag(FarewellFlag.class); + if (!farewell.isEmpty()) { + MainUtil + .format(Captions.PREFIX_FAREWELL.getTranslated() + farewell, plot, player, false, + new RunnableVal() { + @Override public void run(String value) { + MainUtil.sendMessage(player, value); + } + }); + } + Optional leave = plot.getFlag(Flags.NOTIFY_LEAVE); if (leave.isPresent() && leave.get()) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java index 36e140d42..7e79da6a2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java @@ -1,8 +1,5 @@ package com.github.intellectualsites.plotsquared.plot.object; -import com.github.intellectualsites.plotsquared.plot.flag.Flag; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.flags.FlagContainer; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.google.common.collect.ImmutableList; @@ -118,28 +115,6 @@ public class PlotSettings { this.alias = alias; } - public String getJoinMessage(PlotArea area) { - if (flags.containsKey(Flags.GREETING)) { - return (String) flags.get(Flags.GREETING); - } else { - return ""; - } - } - - /** - * Get the "farewell" flag value. - * - * @param plotArea The PlotArea - * @return Farewell flag - */ - public String getLeaveMessage(PlotArea plotArea) { - if (flags.containsKey(Flags.FAREWELL)) { - return (String) flags.get(Flags.FAREWELL); - } else { - return ""; - } - } - @SuppressWarnings({"UnstableApiUsage"}) public List getComments(String inbox) { if (this.comments == null) { return Collections.emptyList();