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) {
player.sendMessage(
TranslatableCaption.miniMessage("commandconfig.command_syntax"),
Placeholder.miniMessage("value", "/plot flag set <flag> <value>")
Placeholder.component("value", Component.text("/plot flag set <flag> <value>"))
);
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?

View File

@ -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(
String localeKey = player.getName().equals(comment.senderName) ?
"list.comment_list_by_lister" : "list.comment_list_by_other";
Placeholder<Component> commentColored = Placeholder.component("comment", MINI_MESSAGE.deserialize(
TranslatableCaption.miniMessage(localeKey).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)
));
}
))
);
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())));
}

View File

@ -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);
}

View File

@ -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)));
}
/**

View File

@ -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("<rating>")) {

View File

@ -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));
}
/**

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.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<P extends PlotPlayer<? extends T>, T> {
return MINI_MESSAGE.parse(TranslatableCaption.miniMessage("info.none").getComponent(localeHolder));
}
final List<Component> users = new LinkedList<>();
final List<UUID> players = new LinkedList<>();
final List<String> 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<P extends PlotPlayer<? extends T>, 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();

View File

@ -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)
)

View File

@ -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));

View File

@ -390,7 +390,7 @@
"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>",
"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_other": "<gray><comment></gray>",
"list.clickable": "<gray> (interactive)</gray>",
@ -426,10 +426,10 @@
"signs.owner_sign_line_3": "<gray><owner></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_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_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.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>",
@ -504,7 +504,7 @@
"flag.flag_info_name": "<gray>Name: <gold><flag></gold></gray>",
"flag.flag_info_category": "<gray>Category: </gray><gold><value></gold>",
"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>",
"flags.flag_category_string": "<gray>String Flags</gray>",
"flags.flag_category_integers": "<gray>Integer Flags</gray>",