From b7d5fd4eaf9cb6cb71279df57e2381fdc4dd792a Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Sat, 18 Dec 2021 00:44:32 +0100 Subject: [PATCH] Fix more MM builder issues (#3373) * fix unpair of signed IDs * Fix MM builder issues + invalid translation * Remove disrupting line breaks for help page and inbox list * Fix loop of mm parsing in /plot f set * de-clutter help page --- .../plotsquared/core/command/FlagCommand.java | 4 +-- .../com/plotsquared/core/command/Inbox.java | 31 ++++++++----------- .../com/plotsquared/core/command/ListCmd.java | 16 +++++----- .../configuration/caption/Placeholders.java | 4 +-- .../java/com/plotsquared/core/plot/Plot.java | 12 +++---- .../com/plotsquared/core/plot/PlotId.java | 2 +- .../plotsquared/core/util/PlayerManager.java | 29 ++++++++++------- .../core/util/helpmenu/HelpObject.java | 2 +- .../core/util/helpmenu/HelpPage.java | 4 +-- Core/src/main/resources/lang/messages_en.json | 8 ++--- 10 files changed, 58 insertions(+), 54 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 1507da319..4d16c62f1 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -327,7 +327,7 @@ public final class FlagCommand extends Command { if (args.length < 2) { player.sendMessage( TranslatableCaption.miniMessage("commandconfig.command_syntax"), - Placeholder.miniMessage("value", "/plot flag set ") + Placeholder.component("value", Component.text("/plot flag set ")) ); return; } @@ -628,7 +628,7 @@ public final class FlagCommand extends Command { // Flag category player.sendMessage( TranslatableCaption.miniMessage("flag.flag_info_category"), - Placeholders.miniMessage(player, "value", plotFlag.getFlagCategory()) + Placeholder.component("value", MINI_MESSAGE.parse(plotFlag.getFlagCategory().getComponent(player))) ); // Flag description // TODO maybe merge and \n instead? diff --git a/Core/src/main/java/com/plotsquared/core/command/Inbox.java b/Core/src/main/java/com/plotsquared/core/command/Inbox.java index 39c8ae5ff..a141509fc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Inbox.java +++ b/Core/src/main/java/com/plotsquared/core/command/Inbox.java @@ -90,27 +90,18 @@ public class Inbox extends SubCommand { // This might work xD for (int x = page * 12; x < max; x++) { PlotComment comment = comments[x]; - Component commentColored; - if (player.getName().equals(comment.senderName)) { - commentColored = MINI_MESSAGE - .deserialize( - TranslatableCaption.miniMessage("list.comment_list_by_lister").getComponent(player), - PlaceholderResolver.placeholders( - Placeholder.miniMessage("comment", comment.comment) - )); - } else { - commentColored = MINI_MESSAGE - .deserialize( - TranslatableCaption.miniMessage("list.comment_list_by_other").getComponent(player), - PlaceholderResolver.placeholders( - Placeholder.miniMessage("comment", comment.comment) - )); - } + String localeKey = player.getName().equals(comment.senderName) ? + "list.comment_list_by_lister" : "list.comment_list_by_other"; + + Placeholder commentColored = Placeholder.component("comment", MINI_MESSAGE.deserialize( + TranslatableCaption.miniMessage(localeKey).getComponent(player), PlaceholderResolver.placeholders( + Placeholder.miniMessage("comment", comment.comment) + )) + ); Placeholder number = Placeholder.miniMessage("number", String.valueOf(x)); Placeholder world = Placeholder.miniMessage("world", comment.world); Placeholder plot_id = Placeholder.miniMessage("plot_id", comment.id.getX() + ";" + comment.id.getY()); Placeholder commenter = Placeholder.miniMessage("commenter", comment.senderName); - Placeholder commentTemplate = Placeholder.miniMessage("comment", commentColored.toString()); builder.append(MINI_MESSAGE .deserialize( TranslatableCaption.miniMessage("list.comment_list_comment").getComponent(player), @@ -119,8 +110,12 @@ public class Inbox extends SubCommand { world, plot_id, commenter, - commentTemplate + commentColored ))); + // Apply line break if not last entry + if (x != max - 1) { + builder.append(Component.newline()); + } } player.sendMessage(StaticCaption.miniMessage(MINI_MESSAGE.serialize(builder.build()))); } diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index 39581977a..883107eeb 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -429,13 +429,13 @@ public class ListCmd extends SubCommand { } Component trusted = MINI_MESSAGE.deserialize( TranslatableCaption.miniMessage("info.plot_info_trusted").getComponent(player), - PlaceholderResolver.placeholders(Placeholder.miniMessage("trusted", - PlayerManager.getPlayerList(plot.getTrusted(), player).toString())) + PlaceholderResolver.placeholders(Placeholder.component("trusted", + PlayerManager.getPlayerList(plot.getTrusted(), player))) ); Component members = MINI_MESSAGE.deserialize( TranslatableCaption.miniMessage("info.plot_info_members").getComponent(player), - PlaceholderResolver.placeholders(Placeholder.miniMessage("trusted", - PlayerManager.getPlayerList(plot.getTrusted(), player).toString())) + PlaceholderResolver.placeholders(Placeholder.component("members", + PlayerManager.getPlayerList(plot.getTrusted(), player))) ); Placeholder command_tp = Placeholder.miniMessage("command_tp", "/plot visit " + plot.getArea() + ";" + plot.getId()); Placeholder command_info = Placeholder.miniMessage("command_info", "/plot info " + plot.getArea() + ";" + plot.getId()); @@ -450,10 +450,12 @@ public class ListCmd extends SubCommand { .asComponent()) ); Placeholder numberTemplate = Placeholder.miniMessage("number", String.valueOf(i)); - Placeholder plotTemplate = Placeholder.miniMessage( + Placeholder plotTemplate = Placeholder.component( "plot", MINI_MESSAGE.deserialize(color.getComponent(player), - PlaceholderResolver.placeholders(Placeholder.miniMessage("plot", plot.toString()))).toString() + PlaceholderResolver.placeholders( + Placeholder.component("plot", Component.text(plot.toString())) + )) ); String prefix = ""; @@ -491,7 +493,7 @@ public class ListCmd extends SubCommand { } catch (TimeoutException e) { player.sendMessage(TranslatableCaption.miniMessage("players.fetching_players_timeout")); } - Placeholder players = Placeholder.miniMessage("players", builder.asComponent().toString()); + Placeholder players = Placeholder.component("players", builder.asComponent()); caption.set(TranslatableCaption.miniMessage("info.plot_list_item")); caption.parsePlaceholders(command_tp, command_info, hover_info, numberTemplate, plotTemplate, players); } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/Placeholders.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/Placeholders.java index c65171bc0..b8b7ffc6a 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/Placeholders.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/Placeholders.java @@ -61,8 +61,8 @@ public final class Placeholders { final @NonNull String key, final @NonNull Caption caption, final @NonNull Placeholder... replacements ) { - return Placeholder.miniMessage(key, MINI_MESSAGE.deserialize(caption.getComponent(localeHolder), - PlaceholderResolver.placeholders(replacements)).toString()); + return Placeholder.component(key, MINI_MESSAGE.deserialize(caption.getComponent(localeHolder), + PlaceholderResolver.placeholders(replacements))); } /** diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 993550196..041c2b48b 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -2901,14 +2901,14 @@ public class Plot { Placeholder numTemplate = Placeholder.miniMessage("num", String.valueOf(num)); Placeholder descTemplate = Placeholder.miniMessage("desc", description); Placeholder biomeTemplate = Placeholder.miniMessage("biome", biome.toString().toLowerCase()); - Placeholder ownerTemplate = Placeholder.miniMessage("owner", owner.toString()); - Placeholder membersTemplate = Placeholder.miniMessage("members", members.toString()); + Placeholder ownerTemplate = Placeholder.component("owner", owner); + Placeholder membersTemplate = Placeholder.component("members", members); Placeholder playerTemplate = Placeholder.miniMessage("player", player.getName()); - Placeholder trustedTemplate = Placeholder.miniMessage("trusted", trusted.toString()); - Placeholder helpersTemplate = Placeholder.miniMessage("helpers", members.toString()); - Placeholder deniedTemplate = Placeholder.miniMessage("denied", denied.toString()); + Placeholder trustedTemplate = Placeholder.component("trusted", trusted); + Placeholder helpersTemplate = Placeholder.component("helpers", members); + Placeholder deniedTemplate = Placeholder.component("denied", denied); Placeholder seenTemplate = Placeholder.miniMessage("seen", seen); - Placeholder flagsTemplate = Placeholder.miniMessage("flags", flags.toString()); + Placeholder flagsTemplate = Placeholder.component("flags", flags); Placeholder creationTemplate = Placeholder.miniMessage("creationdate", newDate); Placeholder buildTemplate = Placeholder.miniMessage("build", String.valueOf(build)); if (iInfo.getComponent(player).contains("")) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotId.java b/Core/src/main/java/com/plotsquared/core/plot/PlotId.java index 05c7f21b9..b5cb77502 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotId.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotId.java @@ -110,7 +110,7 @@ public final class PlotId { * @return Plot ID */ public static @NonNull PlotId unpair(final int hash) { - return PlotId.of(hash >> 16, hash & 0xFFFF); + return PlotId.of(hash >> 16, (short) (hash & 0xFFFF)); } /** diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index 751264db3..c3d2e6cce 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -30,7 +30,6 @@ import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.LocaleHolder; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; -import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.uuid.UUIDMapping; @@ -123,15 +122,19 @@ public abstract class PlayerManager

, T> { return MINI_MESSAGE.parse(TranslatableCaption.miniMessage("info.none").getComponent(localeHolder)); } + final List users = new LinkedList<>(); + final List players = new LinkedList<>(); - final List users = new LinkedList<>(); for (final UUID uuid : uuids) { if (uuid == null) { - users.add(MINI_MESSAGE.stripTokens(TranslatableCaption.miniMessage("info.none").getComponent(localeHolder))); + users.add(MINI_MESSAGE.deserialize(MINI_MESSAGE.stripTokens(TranslatableCaption + .miniMessage("info.none").getComponent(localeHolder)))); } else if (DBFunc.EVERYONE.equals(uuid)) { - users.add(MINI_MESSAGE.stripTokens(TranslatableCaption.miniMessage("info.everyone").getComponent(localeHolder))); + users.add(MINI_MESSAGE.deserialize(MINI_MESSAGE.stripTokens(TranslatableCaption + .miniMessage("info.everyone").getComponent(localeHolder)))); } else if (DBFunc.SERVER.equals(uuid)) { - users.add(MINI_MESSAGE.stripTokens(TranslatableCaption.miniMessage("info.console").getComponent(localeHolder))); + users.add(MINI_MESSAGE.deserialize(MINI_MESSAGE.stripTokens(TranslatableCaption + .miniMessage("info.console").getComponent(localeHolder)))); } else { players.add(uuid); } @@ -140,21 +143,25 @@ public abstract class PlayerManager

, T> { try { for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline() .getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) { - users.add(mapping.getUsername()); + users.add(Component.text(mapping.getUsername())); } } catch (final Exception e) { e.printStackTrace(); } - String c = TranslatableCaption.miniMessage("info.plot_user_list").getComponent(ConsolePlayer.getConsole()); + String c = TranslatableCaption.miniMessage("info.plot_user_list").getComponent(localeHolder); TextComponent.Builder list = Component.text(); for (int x = 0; x < users.size(); x++) { if (x + 1 == uuids.size()) { - list.append(MINI_MESSAGE.deserialize(c, - PlaceholderResolver.placeholders(Placeholder.miniMessage("user", users.get(x))))); + list.append(MINI_MESSAGE.deserialize( + c, + PlaceholderResolver.placeholders(Placeholder.component("user", users.get(x))) + )); } else { - list.append(MINI_MESSAGE.deserialize(c + ", ", - PlaceholderResolver.placeholders(Placeholder.miniMessage("user", users.get(x))))); + list.append(MINI_MESSAGE.deserialize( + c + ", ", + PlaceholderResolver.placeholders(Placeholder.component("user", users.get(x))) + )); } } return list.asComponent(); diff --git a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java index 53c0214eb..3e396e0c1 100644 --- a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java +++ b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java @@ -47,7 +47,7 @@ public class HelpObject { PlaceholderResolver.placeholders( Placeholder.miniMessage("usage", command.getUsage().replace("{label}", label)), Placeholder.miniMessage("alias", command.getAliases().isEmpty() ? "" : StringMan.join(command.getAliases(), " | ")), - Placeholders.miniMessage(audience, "desc", command.getDescription()), + Placeholder.miniMessage("desc", command.getDescription().getComponent(audience)), Placeholder.miniMessage("arguments", buildArgumentList(command.getRequiredArguments())), Placeholder.miniMessage("label", label) ) diff --git a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java index 5b29e57c6..d0e877fc4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java +++ b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpPage.java @@ -57,7 +57,7 @@ public class HelpPage { player.sendMessage(TranslatableCaption.miniMessage("help.no_permission")); } else { Placeholder header = Placeholder.miniMessage("header", TranslatableCaption.miniMessage("help.help_header").getComponent(player)); - Placeholder page_header = Placeholder.miniMessage( + Placeholder page_header = Placeholder.component( "page_header", MINI_MESSAGE.deserialize( TranslatableCaption.miniMessage("help.help_page_header").getComponent(player), @@ -66,7 +66,7 @@ public class HelpPage { curTemplate, maxTemplate ) - ).toString() + ) ); Placeholder help_objects = Placeholder.miniMessage("help_objects", StringMan.join(this.helpObjects, "\n")); Placeholder footer = Placeholder.miniMessage("footer", TranslatableCaption.miniMessage("help.help_footer").getComponent(player)); diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 9a0726c90..b3bbc54ab 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -390,7 +390,7 @@ "working.progress": "Current progress: %", "working.component_complete": "Component generation has finished for plot .", "list.comment_list_header_paged": "(Page /) List of comment(s):", - "list.comment_list_comment": "[#] [;] []: \n", + "list.comment_list_comment": "[#] [;] []: ", "list.comment_list_by_lister": "", "list.comment_list_by_other": "", "list.clickable": " (interactive)", @@ -426,10 +426,10 @@ "signs.owner_sign_line_3": "", "signs.owner_sign_line_4": "Claimed", "help.help_header": "--------- PlotSquared Help ---------", - "help.help_page_header": "\nCategory: , Page: /\n", + "help.help_page_header": "Category: , Page: /", "help.help_footer": "--------- PlotSquared Help ---------", "help.help_info_item": " - ", - "help.help_item": " []\n - \n", + "help.help_item": " []\n - ", "help.help_display_all_commands": "Display all commands.", "help.direction": "Current direction:

", "help.no_permission": "You have no permission to access commands of that sub category, hence you cannot access the help page.", @@ -504,7 +504,7 @@ "flag.flag_info_name": "Name: ", "flag.flag_info_category": "Category: ", "flag.flag_info_description": "Description: ", - "flag.flag_info_example": "Example: > ", + "flag.flag_info_example": "Example: > ", "flag.flag_info_default_value": "Default Value: ", "flags.flag_category_string": "String Flags", "flags.flag_category_integers": "Integer Flags",