diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index d371d6105..ee0ad82ad 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -247,7 +247,7 @@ import java.util.zip.ZipInputStream; if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { if (this.IMP.initWorldEdit()) { - PlotSquared.log(Captions.PREFIX + "&6" + IMP.getPluginName() + PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName() + " hooked into WorldEdit."); this.worldedit = WorldEdit.getInstance(); WorldEdit.getInstance().getEventBus().register(new WESubscriber()); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java index c17d85bd7..1c43a3568 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCommand.java @@ -35,11 +35,22 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "flag", aliases = {"f", "flag"}, usage = "/plot flag ", description = "Manage plot flags", category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag") -@SuppressWarnings("unused") public final class FlagCommand extends SubCommand { +@SuppressWarnings("unused") public final class FlagCommand extends Command { + + public FlagCommand() { + super(MainCommand.getInstance(), true); + } + + private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { + message.send(player, args); + return true; + } private static boolean checkPermValue(@Nonnull final PlotPlayer player, @NotNull final PlotFlag flag, @NotNull String key, @NotNull String value) { @@ -156,10 +167,17 @@ import java.util.Map; return null; } - @Override public boolean onCommand(final PlotPlayer player, final String[] args) { - new HelpMenu(player).setCategory(CommandCategory.SETTINGS).setCommands(this.getCommands()) - .generateMaxPages().generatePage(0, getParent().toString()).render(); - return true; + @Override public CompletableFuture execute(PlotPlayer player, String[] args, + RunnableVal3 confirm, + RunnableVal2 whenDone) throws CommandException { + if (args.length == 0 || !Arrays.asList("set", "s", "list", "l", "delete", "remove", "r", "add", "a", + "info", "i").contains(args[0].toLowerCase( + Locale.ENGLISH))) { + new HelpMenu(player).setCategory(CommandCategory.SETTINGS).setCommands(this.getCommands()) + .generateMaxPages().generatePage(0, getParent().toString()).render(); + return CompletableFuture.completedFuture(true); + } + return super.execute(player, args, confirm, whenDone); } @Override public Collection tab(final PlotPlayer player, final String[] args, @@ -268,7 +286,7 @@ import java.util.Map; String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " "); final ListFlag listFlag = (ListFlag) flag; final List list = - plot.getFlag((Class>) listFlag.getClass()); + new ArrayList(plot.getFlag((Class>) listFlag.getClass())); final PlotFlag parsedFlag; try { parsedFlag = listFlag.parse(value); @@ -382,7 +400,8 @@ import java.util.Map; .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player); // Flag example new PlotMessage(Captions.FLAG_INFO_EXAMPLE.getTranslated()) - .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(plotFlag.getExample()) + .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text("/plot flag set " + + plotFlag.getName() + " " + plotFlag.getExample()) .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()) .suggest("/plot flag set " + plotFlag.getName() + " " + plotFlag.getExample()) .send(player); @@ -392,8 +411,8 @@ import java.util.Map; new PlotMessage(Captions.FLAG_INFO_DEFAULT_VALUE.getTranslated()) .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()).text(defaultValue) .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).send(player); - // Footer - Captions.FLAG_INFO_FOOTER.send(player); + // Footer. Done this way to prevent the duplicate-message-thingy from catching it + MainUtil.sendMessage(player, "&r" + Captions.FLAG_INFO_FOOTER.getTranslated()); } } 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 b7a98b8f2..58d32ebd7 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 @@ -850,4 +850,8 @@ public enum Captions implements Caption { return this.category; } + @Override public String toString() { + return this.getTranslated(); + } + } 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 134c6008e..c82919ab2 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 @@ -52,7 +52,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Notif import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlaceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlayerInteractFlag; -import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.WeatherFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PriceFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PveFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.PvpFlag; @@ -145,7 +145,7 @@ public final class GlobalFlagContainer extends FlagContainer { this.addFlag(InvincibleFlag.INVINCIBLE_FALSE); // Enum Flags - this.addFlag(PlotWeatherFlag.PLOT_WEATHER_FLAG_OFF); + this.addFlag(WeatherFlag.PLOT_WEATHER_FLAG_OFF); this.addFlag(DenyTeleportFlag.DENY_TELEPORT_FLAG_NONE); this.addFlag(TitlesFlag.TITLES_NONE); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/PlotWeatherFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/WeatherFlag.java similarity index 66% rename from Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/PlotWeatherFlag.java rename to Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/WeatherFlag.java index dcc648a35..af69cfa78 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/PlotWeatherFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/implementations/WeatherFlag.java @@ -5,25 +5,25 @@ import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; import org.jetbrains.annotations.NotNull; -public class PlotWeatherFlag extends PlotFlag { +public class WeatherFlag extends PlotFlag { - public static final PlotWeatherFlag PLOT_WEATHER_FLAG_RAIN = - new PlotWeatherFlag(PlotWeather.RAIN); - public static final PlotWeatherFlag PLOT_WEATHER_FLAG_CLEAR = - new PlotWeatherFlag(PlotWeather.CLEAR); - public static final PlotWeatherFlag PLOT_WEATHER_FLAG_OFF = - new PlotWeatherFlag(PlotWeather.RESET); + public static final WeatherFlag PLOT_WEATHER_FLAG_RAIN = + new WeatherFlag(PlotWeather.RAIN); + public static final WeatherFlag PLOT_WEATHER_FLAG_CLEAR = + new WeatherFlag(PlotWeather.CLEAR); + public static final WeatherFlag PLOT_WEATHER_FLAG_OFF = + new WeatherFlag(PlotWeather.RESET); /** * Construct a new flag instance. * * @param value Flag value */ - protected PlotWeatherFlag(@NotNull PlotWeather value) { + protected WeatherFlag(@NotNull PlotWeather value) { super(value, Captions.FLAG_CATEGORY_WEATHER, Captions.FLAG_DESCRIPTION_WEATHER); } - @Override public PlotWeatherFlag parse(@NotNull String input) { + @Override public WeatherFlag parse(@NotNull String input) { switch (input.toLowerCase()) { case "rain": case "storm": @@ -40,7 +40,7 @@ public class PlotWeatherFlag extends PlotFlag { } } - @Override public PlotWeatherFlag merge(@NotNull PlotWeather newValue) { + @Override public WeatherFlag merge(@NotNull PlotWeather newValue) { return flagOf(newValue); } @@ -52,7 +52,7 @@ public class PlotWeatherFlag extends PlotFlag { return "storm"; } - @Override protected PlotWeatherFlag flagOf(@NotNull PlotWeather value) { + @Override protected WeatherFlag flagOf(@NotNull PlotWeather value) { switch (value) { case RAIN: return PLOT_WEATHER_FLAG_RAIN; 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 e524f8388..98c76a6e2 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 @@ -11,7 +11,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.implementations.Guest import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyEnterFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.NotifyLeaveFlag; -import com.github.intellectualsites.plotsquared.plot.flags.implementations.PlotWeatherFlag; +import com.github.intellectualsites.plotsquared.plot.flags.implementations.WeatherFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TimeFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.TitlesFlag; import com.github.intellectualsites.plotsquared.plot.object.Location; @@ -135,7 +135,7 @@ public class PlotListener { } } - player.setWeather(plot.getFlag(PlotWeatherFlag.class)); + player.setWeather(plot.getFlag(WeatherFlag.class)); ItemType musicFlag = plot.getFlag(MusicFlag.class); if (musicFlag != null) { @@ -267,9 +267,9 @@ public class PlotListener { player.setTime(Long.MAX_VALUE); } - final PlotWeather plotWeather = plot.getFlag(PlotWeatherFlag.class); + final PlotWeather plotWeather = plot.getFlag(WeatherFlag.class); if (plotWeather != PlotWeather.RESET) { - player.setWeather(plotWeather); + player.setWeather(PlotWeather.RESET); } Location lastLoc = player.getMeta("music"); 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 4295097de..e8e570949 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 @@ -789,9 +789,11 @@ public class MainUtil { } else { String prefix = ""; for (final PlotFlag flag : flagCollection) { - Object value = flag.getValue(); + Object value; if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) { - value = FLAG_DECIMAL_FORMAT.format(value); + value = FLAG_DECIMAL_FORMAT.format(flag.getValue()); + } else { + value = flag.toString(); } flags.append(prefix).append(CaptionUtility.format(Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(), value));