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
This commit is contained in:
Pierre Maurice Schwang 2021-12-18 00:44:32 +01:00 committed by GitHub
parent 0886f9ccd3
commit b7d5fd4eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 54 deletions

View File

@ -327,7 +327,7 @@ public final class FlagCommand extends Command {
if (args.length < 2) { if (args.length < 2) {
player.sendMessage( player.sendMessage(
TranslatableCaption.miniMessage("commandconfig.command_syntax"), TranslatableCaption.miniMessage("commandconfig.command_syntax"),
Placeholder.miniMessage("value", "/plot flag set <flag> <value>") Placeholder.component("value", Component.text("/plot flag set <flag> <value>"))
); );
return; return;
} }
@ -628,7 +628,7 @@ public final class FlagCommand extends Command {
// Flag category // Flag category
player.sendMessage( player.sendMessage(
TranslatableCaption.miniMessage("flag.flag_info_category"), TranslatableCaption.miniMessage("flag.flag_info_category"),
Placeholders.miniMessage(player, "value", plotFlag.getFlagCategory()) Placeholder.component("value", MINI_MESSAGE.parse(plotFlag.getFlagCategory().getComponent(player)))
); );
// Flag description // Flag description
// TODO maybe merge and \n instead? // TODO maybe merge and \n instead?

View File

@ -90,27 +90,18 @@ public class Inbox extends SubCommand {
// This might work xD // This might work xD
for (int x = page * 12; x < max; x++) { for (int x = page * 12; x < max; x++) {
PlotComment comment = comments[x]; PlotComment comment = comments[x];
Component commentColored; String localeKey = player.getName().equals(comment.senderName) ?
if (player.getName().equals(comment.senderName)) { "list.comment_list_by_lister" : "list.comment_list_by_other";
commentColored = MINI_MESSAGE
.deserialize( Placeholder<Component> commentColored = Placeholder.component("comment", MINI_MESSAGE.deserialize(
TranslatableCaption.miniMessage("list.comment_list_by_lister").getComponent(player), TranslatableCaption.miniMessage(localeKey).getComponent(player), PlaceholderResolver.placeholders(
PlaceholderResolver.placeholders(
Placeholder.miniMessage("comment", comment.comment) 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)
));
}
Placeholder<?> number = Placeholder.miniMessage("number", String.valueOf(x)); Placeholder<?> number = Placeholder.miniMessage("number", String.valueOf(x));
Placeholder<?> world = Placeholder.miniMessage("world", comment.world); Placeholder<?> world = Placeholder.miniMessage("world", comment.world);
Placeholder<?> plot_id = Placeholder.miniMessage("plot_id", comment.id.getX() + ";" + comment.id.getY()); Placeholder<?> plot_id = Placeholder.miniMessage("plot_id", comment.id.getX() + ";" + comment.id.getY());
Placeholder<?> commenter = Placeholder.miniMessage("commenter", comment.senderName); Placeholder<?> commenter = Placeholder.miniMessage("commenter", comment.senderName);
Placeholder<?> commentTemplate = Placeholder.miniMessage("comment", commentColored.toString());
builder.append(MINI_MESSAGE builder.append(MINI_MESSAGE
.deserialize( .deserialize(
TranslatableCaption.miniMessage("list.comment_list_comment").getComponent(player), TranslatableCaption.miniMessage("list.comment_list_comment").getComponent(player),
@ -119,8 +110,12 @@ public class Inbox extends SubCommand {
world, world,
plot_id, plot_id,
commenter, 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()))); player.sendMessage(StaticCaption.miniMessage(MINI_MESSAGE.serialize(builder.build())));
} }

View File

@ -429,13 +429,13 @@ public class ListCmd extends SubCommand {
} }
Component trusted = MINI_MESSAGE.deserialize( Component trusted = MINI_MESSAGE.deserialize(
TranslatableCaption.miniMessage("info.plot_info_trusted").getComponent(player), TranslatableCaption.miniMessage("info.plot_info_trusted").getComponent(player),
PlaceholderResolver.placeholders(Placeholder.miniMessage("trusted", PlaceholderResolver.placeholders(Placeholder.component("trusted",
PlayerManager.getPlayerList(plot.getTrusted(), player).toString())) PlayerManager.getPlayerList(plot.getTrusted(), player)))
); );
Component members = MINI_MESSAGE.deserialize( Component members = MINI_MESSAGE.deserialize(
TranslatableCaption.miniMessage("info.plot_info_members").getComponent(player), TranslatableCaption.miniMessage("info.plot_info_members").getComponent(player),
PlaceholderResolver.placeholders(Placeholder.miniMessage("trusted", PlaceholderResolver.placeholders(Placeholder.component("members",
PlayerManager.getPlayerList(plot.getTrusted(), player).toString())) PlayerManager.getPlayerList(plot.getTrusted(), player)))
); );
Placeholder<?> command_tp = Placeholder.miniMessage("command_tp", "/plot visit " + plot.getArea() + ";" + plot.getId()); 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()); Placeholder<?> command_info = Placeholder.miniMessage("command_info", "/plot info " + plot.getArea() + ";" + plot.getId());
@ -450,10 +450,12 @@ public class ListCmd extends SubCommand {
.asComponent()) .asComponent())
); );
Placeholder<?> numberTemplate = Placeholder.miniMessage("number", String.valueOf(i)); Placeholder<?> numberTemplate = Placeholder.miniMessage("number", String.valueOf(i));
Placeholder<?> plotTemplate = Placeholder.miniMessage( Placeholder<?> plotTemplate = Placeholder.component(
"plot", "plot",
MINI_MESSAGE.deserialize(color.getComponent(player), 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 = ""; String prefix = "";
@ -491,7 +493,7 @@ public class ListCmd extends SubCommand {
} catch (TimeoutException e) { } catch (TimeoutException e) {
player.sendMessage(TranslatableCaption.miniMessage("players.fetching_players_timeout")); 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.set(TranslatableCaption.miniMessage("info.plot_list_item"));
caption.parsePlaceholders(command_tp, command_info, hover_info, numberTemplate, plotTemplate, players); caption.parsePlaceholders(command_tp, command_info, hover_info, numberTemplate, plotTemplate, players);
} }

View File

@ -61,8 +61,8 @@ public final class Placeholders {
final @NonNull String key, final @NonNull Caption caption, final @NonNull String key, final @NonNull Caption caption,
final @NonNull Placeholder<?>... replacements final @NonNull Placeholder<?>... replacements
) { ) {
return Placeholder.miniMessage(key, MINI_MESSAGE.deserialize(caption.getComponent(localeHolder), return Placeholder.component(key, MINI_MESSAGE.deserialize(caption.getComponent(localeHolder),
PlaceholderResolver.placeholders(replacements)).toString()); PlaceholderResolver.placeholders(replacements)));
} }
/** /**

View File

@ -2901,14 +2901,14 @@ public class Plot {
Placeholder<?> numTemplate = Placeholder.miniMessage("num", String.valueOf(num)); Placeholder<?> numTemplate = Placeholder.miniMessage("num", String.valueOf(num));
Placeholder<?> descTemplate = Placeholder.miniMessage("desc", description); Placeholder<?> descTemplate = Placeholder.miniMessage("desc", description);
Placeholder<?> biomeTemplate = Placeholder.miniMessage("biome", biome.toString().toLowerCase()); Placeholder<?> biomeTemplate = Placeholder.miniMessage("biome", biome.toString().toLowerCase());
Placeholder<?> ownerTemplate = Placeholder.miniMessage("owner", owner.toString()); Placeholder<?> ownerTemplate = Placeholder.component("owner", owner);
Placeholder<?> membersTemplate = Placeholder.miniMessage("members", members.toString()); Placeholder<?> membersTemplate = Placeholder.component("members", members);
Placeholder<?> playerTemplate = Placeholder.miniMessage("player", player.getName()); Placeholder<?> playerTemplate = Placeholder.miniMessage("player", player.getName());
Placeholder<?> trustedTemplate = Placeholder.miniMessage("trusted", trusted.toString()); Placeholder<?> trustedTemplate = Placeholder.component("trusted", trusted);
Placeholder<?> helpersTemplate = Placeholder.miniMessage("helpers", members.toString()); Placeholder<?> helpersTemplate = Placeholder.component("helpers", members);
Placeholder<?> deniedTemplate = Placeholder.miniMessage("denied", denied.toString()); Placeholder<?> deniedTemplate = Placeholder.component("denied", denied);
Placeholder<?> seenTemplate = Placeholder.miniMessage("seen", seen); 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<?> creationTemplate = Placeholder.miniMessage("creationdate", newDate);
Placeholder<?> buildTemplate = Placeholder.miniMessage("build", String.valueOf(build)); Placeholder<?> buildTemplate = Placeholder.miniMessage("build", String.valueOf(build));
if (iInfo.getComponent(player).contains("<rating>")) { if (iInfo.getComponent(player).contains("<rating>")) {

View File

@ -110,7 +110,7 @@ public final class PlotId {
* @return Plot ID * @return Plot ID
*/ */
public static @NonNull PlotId unpair(final int hash) { public static @NonNull PlotId unpair(final int hash) {
return PlotId.of(hash >> 16, hash & 0xFFFF); return PlotId.of(hash >> 16, (short) (hash & 0xFFFF));
} }
/** /**

View File

@ -30,7 +30,6 @@ import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.LocaleHolder; import com.plotsquared.core.configuration.caption.LocaleHolder;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.uuid.UUIDMapping; import com.plotsquared.core.uuid.UUIDMapping;
@ -123,15 +122,19 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
return MINI_MESSAGE.parse(TranslatableCaption.miniMessage("info.none").getComponent(localeHolder)); return MINI_MESSAGE.parse(TranslatableCaption.miniMessage("info.none").getComponent(localeHolder));
} }
final List<Component> users = new LinkedList<>();
final List<UUID> players = new LinkedList<>(); final List<UUID> players = new LinkedList<>();
final List<String> users = new LinkedList<>();
for (final UUID uuid : uuids) { for (final UUID uuid : uuids) {
if (uuid == null) { 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)) { } 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)) { } 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 { } else {
players.add(uuid); players.add(uuid);
} }
@ -140,21 +143,25 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
try { try {
for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline() for (final UUIDMapping mapping : PlotSquared.get().getImpromptuUUIDPipeline()
.getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) { .getNames(players).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS)) {
users.add(mapping.getUsername()); users.add(Component.text(mapping.getUsername()));
} }
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); 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(); TextComponent.Builder list = Component.text();
for (int x = 0; x < users.size(); x++) { for (int x = 0; x < users.size(); x++) {
if (x + 1 == uuids.size()) { if (x + 1 == uuids.size()) {
list.append(MINI_MESSAGE.deserialize(c, list.append(MINI_MESSAGE.deserialize(
PlaceholderResolver.placeholders(Placeholder.miniMessage("user", users.get(x))))); c,
PlaceholderResolver.placeholders(Placeholder.component("user", users.get(x)))
));
} else { } else {
list.append(MINI_MESSAGE.deserialize(c + ", ", list.append(MINI_MESSAGE.deserialize(
PlaceholderResolver.placeholders(Placeholder.miniMessage("user", users.get(x))))); c + ", ",
PlaceholderResolver.placeholders(Placeholder.component("user", users.get(x)))
));
} }
} }
return list.asComponent(); return list.asComponent();

View File

@ -47,7 +47,7 @@ public class HelpObject {
PlaceholderResolver.placeholders( PlaceholderResolver.placeholders(
Placeholder.miniMessage("usage", command.getUsage().replace("{label}", label)), Placeholder.miniMessage("usage", command.getUsage().replace("{label}", label)),
Placeholder.miniMessage("alias", command.getAliases().isEmpty() ? "" : StringMan.join(command.getAliases(), " | ")), 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("arguments", buildArgumentList(command.getRequiredArguments())),
Placeholder.miniMessage("label", label) Placeholder.miniMessage("label", label)
) )

View File

@ -57,7 +57,7 @@ public class HelpPage {
player.sendMessage(TranslatableCaption.miniMessage("help.no_permission")); player.sendMessage(TranslatableCaption.miniMessage("help.no_permission"));
} else { } else {
Placeholder<?> header = Placeholder.miniMessage("header", TranslatableCaption.miniMessage("help.help_header").getComponent(player)); Placeholder<?> header = Placeholder.miniMessage("header", TranslatableCaption.miniMessage("help.help_header").getComponent(player));
Placeholder<?> page_header = Placeholder.miniMessage( Placeholder<?> page_header = Placeholder.component(
"page_header", "page_header",
MINI_MESSAGE.deserialize( MINI_MESSAGE.deserialize(
TranslatableCaption.miniMessage("help.help_page_header").getComponent(player), TranslatableCaption.miniMessage("help.help_page_header").getComponent(player),
@ -66,7 +66,7 @@ public class HelpPage {
curTemplate, curTemplate,
maxTemplate maxTemplate
) )
).toString() )
); );
Placeholder<?> help_objects = Placeholder.miniMessage("help_objects", StringMan.join(this.helpObjects, "\n")); Placeholder<?> help_objects = Placeholder.miniMessage("help_objects", StringMan.join(this.helpObjects, "\n"));
Placeholder<?> footer = Placeholder.miniMessage("footer", TranslatableCaption.miniMessage("help.help_footer").getComponent(player)); Placeholder<?> footer = Placeholder.miniMessage("footer", TranslatableCaption.miniMessage("help.help_footer").getComponent(player));

View File

@ -390,7 +390,7 @@
"working.progress": "<prefix><gray>Current progress: </gray><gold><progress></gold><gray>%</gray>", "working.progress": "<prefix><gray>Current progress: </gray><gold><progress></gold><gray>%</gray>",
"working.component_complete": "<prefix><gold>Component generation has finished for plot <plot>.</gold>", "working.component_complete": "<prefix><gold>Component generation has finished for plot <plot>.</gold>",
"list.comment_list_header_paged": "<gray>(Page </gray><gold><cur></gold><gray>/</gray><gold><max></gold><gray>) </gray><gold>List of <amount> comment(s):</gold>", "list.comment_list_header_paged": "<gray>(Page </gray><gold><cur></gold><gray>/</gray><gold><max></gold><gray>) </gray><gold>List of <amount> comment(s):</gold>",
"list.comment_list_comment": "<dark_gray>[</dark_gray><gray>#<number></gray><dark_gray>] [</dark_gray><gray><world>;<plot_id></gray><dark_gray>] [</dark_gray><gold><commenter></gold><dark_gray>]: </dark_gray><comment>\n", "list.comment_list_comment": "<dark_gray>[</dark_gray><gray>#<number></gray><dark_gray>] [</dark_gray><gray><world>;<plot_id></gray><dark_gray>] [</dark_gray><gold><commenter></gold><dark_gray>]: </dark_gray><comment>",
"list.comment_list_by_lister": "<green><comment></green>", "list.comment_list_by_lister": "<green><comment></green>",
"list.comment_list_by_other": "<gray><comment></gray>", "list.comment_list_by_other": "<gray><comment></gray>",
"list.clickable": "<gray> (interactive)</gray>", "list.clickable": "<gray> (interactive)</gray>",
@ -426,10 +426,10 @@
"signs.owner_sign_line_3": "<gray><owner></gray>", "signs.owner_sign_line_3": "<gray><owner></gray>",
"signs.owner_sign_line_4": "<dark_gray>Claimed</dark_gray>", "signs.owner_sign_line_4": "<dark_gray>Claimed</dark_gray>",
"help.help_header": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Help </gold><dark_gray><strikethrough>---------<reset>", "help.help_header": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Help </gold><dark_gray><strikethrough>---------<reset>",
"help.help_page_header": "\n<gold>Category: </gold><gray><category>,</gray><gold> Page: </gold><gray><current></gray><dark_gray>/</dark_gray><gray><max></gray>\n", "help.help_page_header": "<gold>Category: </gold><gray><category>,</gray><gold> Page: </gold><gray><current></gray><dark_gray>/</dark_gray><gray><max></gray>",
"help.help_footer": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Help </gold><dark_gray><strikethrough>---------<reset>", "help.help_footer": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Help </gold><dark_gray><strikethrough>---------<reset>",
"help.help_info_item": "<gold><command> <gray><category> </gray><dark_gray>- </dark_gray><gray><category_desc></gray>", "help.help_info_item": "<gold><command> <gray><category> </gray><dark_gray>- </dark_gray><gray><category_desc></gray>",
"help.help_item": "<gold><usage> <gray>[<gold><alias></gold>]</gray>\n <dark_gray>- </dark_gray><gray><desc></gray>\n", "help.help_item": "<gold><usage> <gray>[<gold><alias></gold>]</gray>\n <dark_gray>- </dark_gray><gray><desc></gray>",
"help.help_display_all_commands": "<prefix><gray>Display all commands.</gray>", "help.help_display_all_commands": "<prefix><gray>Display all commands.</gray>",
"help.direction": "<prefix><gold>Current direction: </gold><gray><dir></gray>", "help.direction": "<prefix><gold>Current direction: </gold><gray><dir></gray>",
"help.no_permission": "<prefix><red>You have no permission to access commands of that sub category, hence you cannot access the help page.</red>", "help.no_permission": "<prefix><red>You have no permission to access commands of that sub category, hence you cannot access the help page.</red>",
@ -504,7 +504,7 @@
"flag.flag_info_name": "<gray>Name: <gold><flag></gold></gray>", "flag.flag_info_name": "<gray>Name: <gold><flag></gold></gray>",
"flag.flag_info_category": "<gray>Category: </gray><gold><value></gold>", "flag.flag_info_category": "<gray>Category: </gray><gold><value></gold>",
"flag.flag_info_description": "<gray>Description: </gray>", "flag.flag_info_description": "<gray>Description: </gray>",
"flag.flag_info_example": "<gray>Example: <click:suggest_command:<command> <flag> <value>><gold><command> <flag> <value></click></gold></gray>", "flag.flag_info_example": "<gray>Example: <click:suggest_command:<command> <flag> <value>><gold><command> <flag> <value></gold></click></gray>",
"flag.flag_info_default_value": "<gray>Default Value: <value></gray>", "flag.flag_info_default_value": "<gray>Default Value: <value></gray>",
"flags.flag_category_string": "<gray>String Flags</gray>", "flags.flag_category_string": "<gray>String Flags</gray>",
"flags.flag_category_integers": "<gray>Integer Flags</gray>", "flags.flag_category_integers": "<gray>Integer Flags</gray>",