From 18f630ba15aec60aece0984a33f11bea230248a2 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 6 Aug 2020 14:06:19 +0100 Subject: [PATCH] Bit more json --- .../plotsquared/core/command/FlagCommand.java | 45 +++++++++---------- .../core/util/LegacyConverter.java | 21 ++++----- Core/src/main/resources/lang/messages_en.json | 6 +-- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java index 43063ba9a..7287470f5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -26,9 +26,10 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.caption.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.CaptionUtility; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlotFlagAddEvent; import com.plotsquared.core.events.PlotFlagRemoveEvent; @@ -49,6 +50,7 @@ import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.helpmenu.HelpMenu; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; @@ -80,7 +82,7 @@ public final class FlagCommand extends Command { super(MainCommand.getInstance(), true); } - private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { + private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { player.sendMessage( TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot flag ") @@ -88,7 +90,7 @@ public final class FlagCommand extends Command { return true; } - private static boolean checkPermValue(@Nonnull final PlotPlayer player, + private static boolean checkPermValue(@Nonnull final PlotPlayer player, @Nonnull final PlotFlag flag, @Nonnull String key, @Nonnull String value) { key = key.toLowerCase(); value = value.toLowerCase(); @@ -156,7 +158,7 @@ public final class FlagCommand extends Command { * * @return true if the player is allowed to modify the flags at their current location */ - private static boolean checkRequirements(@Nonnull final PlotPlayer player) { + private static boolean checkRequirements(@Nonnull final PlotPlayer player) { final Location location = player.getLocation(); final Plot plot = location.getPlotAbs(); if (plot == null) { @@ -186,9 +188,9 @@ public final class FlagCommand extends Command { * @param arg String to extract flag from * @return The flag, if found, else null */ - @Nullable private static PlotFlag getFlag(@Nonnull final PlotPlayer player, + @Nullable private static PlotFlag getFlag(@Nonnull final PlotPlayer player, @Nonnull final String arg) { - if (arg != null && arg.length() > 0) { + if (arg.length() > 0) { final PlotFlag flag = GlobalFlagContainer.getInstance().getFlagFromString(arg); if (flag instanceof InternalFlag || flag == null) { boolean suggested = false; @@ -231,7 +233,7 @@ public final class FlagCommand extends Command { } @Override - public Collection tab(final PlotPlayer player, final String[] args, + public Collection tab(final PlotPlayer player, final String[] args, final boolean space) { if (args.length == 1) { return Stream @@ -293,7 +295,7 @@ public final class FlagCommand extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.set.flag") - public void set(final Command command, final PlotPlayer player, final String[] args, + public void set(final Command command, final PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { if (!checkRequirements(player)) { @@ -346,7 +348,7 @@ public final class FlagCommand extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag.add") - public void add(final Command command, PlotPlayer player, final String[] args, + public void add(final Command command, PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { if (!checkRequirements(player)) { @@ -410,7 +412,7 @@ public final class FlagCommand extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag.add") - public void remove(final Command command, PlotPlayer player, final String[] args, + public void remove(final Command command, PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { if (!checkRequirements(player)) { @@ -517,7 +519,7 @@ public final class FlagCommand extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag.list") - public void list(final Command command, final PlotPlayer player, final String[] args, + public void list(final Command command, final PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { if (!checkRequirements(player)) { @@ -529,7 +531,7 @@ public final class FlagCommand extends Command { if (plotFlag instanceof InternalFlag) { continue; } - final String category = plotFlag.getFlagCategory().getTranslated(); + final String category = MINI_MESSAGE.stripTokens(plotFlag.getFlagCategory().getComponent(player)); final Collection flagList = flags.computeIfAbsent(category, k -> new ArrayList<>()); flagList.add(plotFlag.getName()); @@ -537,21 +539,16 @@ public final class FlagCommand extends Command { for (final Map.Entry> entry : flags.entrySet()) { Collections.sort(entry.getValue()); - PlotMessage plotMessage = new PlotMessage(entry.getKey() + ": ") - .color(Captions.FLAG_INFO_COLOR_KEY.getTranslated()); + Component category = + MINI_MESSAGE.parse(TranslatableCaption.of("flag.flag_list_categories").getComponent(player), Template.of("category", entry.getKey())); final Iterator flagIterator = entry.getValue().iterator(); while (flagIterator.hasNext()) { final String flag = flagIterator.next(); - plotMessage = plotMessage.text(flag).command("/plot flag info " + flag) - .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()).tooltip( - new PlotMessage(Captions.FLAG_LIST_SEE_INFO.getTranslated()) - .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated())); - if (flagIterator.hasNext()) { - plotMessage = plotMessage.text(", ") - .color(Captions.FLAG_INFO_COLOR_VALUE.getTranslated()); - } + category.append(MINI_MESSAGE + .parse(TranslatableCaption.of("flag.flag_list_flag").getComponent(player), Template.of("command", "/plot flag info " + flag), + Template.of("flag", flag), Template.of("suffix", flagIterator.hasNext() ? ", " : ""))); } - plotMessage.send(player); + player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(category))); } } @@ -562,7 +559,7 @@ public final class FlagCommand extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.NONE, permission = "plots.flag.info") - public void info(final Command command, final PlotPlayer player, final String[] args, + public void info(final Command command, final PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { if (!checkRequirements(player)) { diff --git a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java index eac04929c..4f1e5fe43 100644 --- a/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java +++ b/Core/src/main/java/com/plotsquared/core/util/LegacyConverter.java @@ -26,12 +26,12 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.caption.CaptionUtility; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.plot.BlockBucket; import com.sk89q.worldedit.world.block.BlockState; +import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -108,23 +108,20 @@ public final class LegacyConverter { .toArray(BlockState[]::new); } - private void convertBlock(@Nonnull final ConfigurationSection section, - @Nonnull final String key, @Nonnull final String block) { + private void convertBlock(@Nonnull final ConfigurationSection section, @Nonnull final String key, @Nonnull final String block) { final BlockBucket bucket = this.blockToBucket(block); this.setString(section, key, bucket); - logger.info(CaptionUtility - .format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), - block, bucket.toString())); + ConsolePlayer.getConsole().sendMessage(TranslatableCaption.of("legacyconfig.legacy_config_replaced"), Template.of("value1", block), + Template.of("value2", bucket.toString())); } - private void convertBlockList(@Nonnull final ConfigurationSection section, - @Nonnull final String key, @Nonnull final List blockList) { + private void convertBlockList(@Nonnull final ConfigurationSection section, @Nonnull final String key, @Nonnull final List blockList) { final BlockState[] blocks = this.splitBlockList(blockList); final BlockBucket bucket = this.blockListToBucket(blocks); this.setString(section, key, bucket); - logger.info(CaptionUtility - .format(ConsolePlayer.getConsole(), Captions.LEGACY_CONFIG_REPLACED.getTranslated(), - plotBlockArrayString(blocks), bucket.toString())); + ConsolePlayer.getConsole() + .sendMessage(TranslatableCaption.of("legacyconfig.legacy_config_replaced"), Template.of("value1", plotBlockArrayString(blocks)), + Template.of("value2", bucket.toString())); } private String plotBlockArrayString(@Nonnull final BlockState[] blocks) { diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index f5173f9fa..023543f38 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -494,7 +494,7 @@ "legacyconfig.legacy_config_found": "A legacy configuration file was detected. Conversion will be attempted.", "legacyconfig.legacy_config_backup": "A copy of worlds.yml has been saved in the file worlds.yml.old.", - "legacyconfig.legacy_config_replaced": "> has been replaced with ", + "legacyconfig.legacy_config_replaced": " has been replaced with ", "legacyconfig.legacy_config_done": "The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.", "legacyconfig.legacy_config_conversion_failed": "Failed to convert the legacy configuration file. See stack trace for information.", @@ -512,8 +512,8 @@ "flag.flag_parse_error": "Failed to parse flag , value : ", "flag.flag_info_header": "--------- PlotSquared Flags ---------", "flag.flag_info_footer": "--------- PlotSquared Flags ---------", - "flag.flag_info_color_key": "", - "flag.flag_info_color_value": "", + "flag.flag_list_categories": ": ", + "flag.flag_list_flag": ">Click to view information about the flag.>", "flag.flag_info_name": "Name: ", "flag.flag_info_category": "Category: ", "flag.flag_info_description": "Description: ",