From 50cfecb3fdecdaec9171d5a1408fc27ccc4f3f33 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 7 Aug 2020 11:08:03 +0100 Subject: [PATCH] Several minor progress. Couple of bigger (inboxes and help) --- .../core/backup/PlayerBackupProfile.java | 9 +++-- .../com/plotsquared/core/command/Backup.java | 13 ++++--- .../com/plotsquared/core/command/Biome.java | 5 ++- .../plotsquared/core/command/Continue.java | 4 +-- .../com/plotsquared/core/command/Debug.java | 32 ++++++++--------- .../plotsquared/core/command/FlagCommand.java | 4 +-- .../com/plotsquared/core/command/Help.java | 27 +++++++------- .../com/plotsquared/core/command/Inbox.java | 35 +++++++++++-------- .../com/plotsquared/core/command/Set.java | 8 ++--- Core/src/main/resources/lang/messages_en.json | 5 ++- 10 files changed, 76 insertions(+), 66 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java index bd99da015..84feafee4 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java +++ b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java @@ -27,12 +27,14 @@ package com.plotsquared.core.backup; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; -import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.schematic.Schematic; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import net.kyori.adventure.text.minimessage.MiniMessage; import javax.annotation.Nonnull; import java.io.IOException; @@ -54,6 +56,8 @@ import java.util.concurrent.CompletableFuture; */ public class PlayerBackupProfile implements BackupProfile { + static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); + private final UUID owner; private final Plot plot; private final BackupManager backupManager; @@ -182,7 +186,8 @@ public class PlayerBackupProfile implements BackupProfile { if (value) { future.complete(null); } else { - future.completeExceptionally(new RuntimeException(Captions.SCHEMATIC_PASTE_FAILED.toString())); + future.completeExceptionally(new RuntimeException(MINI_MESSAGE.stripTokens( + TranslatableCaption.of("schematics.schematic_paste_failed").getComponent(ConsolePlayer.getConsole())))); } } }); diff --git a/Core/src/main/java/com/plotsquared/core/command/Backup.java b/Core/src/main/java/com/plotsquared/core/command/Backup.java index ec65364b8..9c0f459fd 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Backup.java +++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java @@ -30,7 +30,6 @@ import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.backup.BackupProfile; import com.plotsquared.core.backup.NullBackupProfile; import com.plotsquared.core.backup.PlayerBackupProfile; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -71,7 +70,7 @@ public final class Backup extends Command { this.backupManager = backupManager; } - private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { + private static boolean sendMessage(PlotPlayer player) { player.sendMessage( TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot backup ") @@ -85,12 +84,12 @@ public final class Backup extends Command { RunnableVal2 whenDone) throws CommandException { if (args.length == 0 || !Arrays.asList("save", "list", "load") .contains(args[0].toLowerCase(Locale.ENGLISH))) { - return CompletableFuture.completedFuture(sendMessage(player, Captions.BACKUP_USAGE)); + return CompletableFuture.completedFuture(sendMessage(player)); } return super.execute(player, args, confirm, whenDone); } - @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { + @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { if (args.length == 1) { return Stream.of("save", "list", "load") .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) @@ -128,7 +127,7 @@ public final class Backup extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER, permission = "plots.backup.save") - public void save(final Command command, final PlotPlayer player, final String[] args, + public void save(final Command command, final PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { final Plot plot = player.getCurrentPlot(); @@ -179,7 +178,7 @@ public final class Backup extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER, permission = "plots.backup.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) { final Plot plot = player.getCurrentPlot(); @@ -246,7 +245,7 @@ public final class Backup extends Command { category = CommandCategory.SETTINGS, requiredType = RequiredType.PLAYER, permission = "plots.backup.load") - public void load(final Command command, final PlotPlayer player, final String[] args, + public void load(final Command command, final PlotPlayer player, final String[] args, final RunnableVal3 confirm, final RunnableVal2 whenDone) { final Plot plot = player.getCurrentPlot(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Biome.java b/Core/src/main/java/com/plotsquared/core/command/Biome.java index 4fff60db7..ffe5b0139 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Biome.java +++ b/Core/src/main/java/com/plotsquared/core/command/Biome.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -55,8 +54,8 @@ public class Biome extends SetCommand { } catch (final Exception ignore) { } if (biome == null) { - String biomes = StringMan - .join(BiomeType.REGISTRY.values(), Captions.BLOCK_LIST_SEPARATOR.toString()); + String biomes = StringMan.join(BiomeType.REGISTRY.values(), + MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("blocklist.block_list_separator").getComponent(player)))); player.sendMessage(TranslatableCaption.of("biome.need_biome")); player.sendMessage( TranslatableCaption.of("commandconfig.subcommand_set_options_header"), diff --git a/Core/src/main/java/com/plotsquared/core/command/Continue.java b/Core/src/main/java/com/plotsquared/core/command/Continue.java index d4c44abd0..000f675d2 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Continue.java +++ b/Core/src/main/java/com/plotsquared/core/command/Continue.java @@ -53,7 +53,7 @@ public class Continue extends SubCommand { @Inject public Continue(@Nonnull final EventDispatcher eventDispatcher) { this.eventDispatcher = eventDispatcher; } - + @Override public boolean onCommand(PlotPlayer player, String[] args) { Plot plot = player.getCurrentPlot(); if ((plot == null) || !plot.hasOwner()) { @@ -64,7 +64,7 @@ public class Continue extends SubCommand { .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_CONTINUE)) { player.sendMessage( TranslatableCaption.of("permission.no_permission"), - Template.of("node", Captions.NO_PLOT_PERMS.toString()) + Template.of("node", TranslatableCaption.of("permission.no_plot_perms").getComponent(player)) ); return false; } diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java index 1c3d9a51d..e3d5a532b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Debug.java +++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java @@ -40,6 +40,8 @@ import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.uuid.UUIDMapping; import com.sk89q.worldedit.world.entity.EntityType; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,27 +141,21 @@ public class Debug extends SubCommand { player.sendMessage(StaticCaption.of(msg.toString())); return true; } - StringBuilder information = new StringBuilder(); - String header = Captions.DEBUG_HEADER.getTranslated(); - String line = Captions.DEBUG_LINE.getTranslated(); - String section = Captions.DEBUG_SECTION.getTranslated(); + TextComponent.Builder information = TextComponent.builder(); + Component header = MINI_MESSAGE.parse(TranslatableCaption.of("debug.debug_header").getComponent(player) + "\n"); + String line = TranslatableCaption.of("debug.debug_line").getComponent(player) + "\n"; + String section = TranslatableCaption.of("debug.debug_section").getComponent(player) + "\n"; information.append(header); - information.append(getSection(section, "PlotArea")); + information.append(MINI_MESSAGE.parse(section, Template.of("val", "PlotArea"))); + information.append(MINI_MESSAGE + .parse(line, Template.of("var", "Plot Worlds"), Template.of("val", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", ")))); information.append( - getLine(line, "Plot Worlds", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", "))); - information.append(getLine(line, "Owned Plots", PlotQuery.newQuery().allPlots().count())); - information.append(getSection(section, "Messages")); - information.append(getLine(line, "Total Messages", Captions.values().length)); - information.append(getLine(line, "View all captions", "/plot debug msg")); + MINI_MESSAGE.parse(line, Template.of("var", "Owned Plots"), Template.of("val", String.valueOf(PlotQuery.newQuery().allPlots().count())))); + information.append(MINI_MESSAGE.parse(section, Template.of("val", "Messages"))); + information + .append(MINI_MESSAGE.parse(line, Template.of("var", "Total Messages"), Template.of("val", String.valueOf(Captions.values().length)))); + information.append(MINI_MESSAGE.parse(line, Template.of("var", "View all captions"), Template.of("val", "/plot debug msg"))); player.sendMessage(StaticCaption.of(information.toString())); return true; } - - private String getSection(String line, String val) { - return line.replaceAll("%val%", val) + "\n"; - } - - private String getLine(String line, String var, Object val) { - return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n"; - } } 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 b0ac7ec99..c5246608c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java @@ -83,7 +83,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) { player.sendMessage( TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot flag ") @@ -167,7 +167,7 @@ public final class FlagCommand extends Command { return false; } if (!plot.hasOwner()) { - sendMessage(player, Captions.PLOT_NOT_CLAIMED); + player.sendMessage(TranslatableCaption.of("working.plot_not_claimed")); return false; } if (!plot.isOwner(player.getUUID()) && !Permissions diff --git a/Core/src/main/java/com/plotsquared/core/command/Help.java b/Core/src/main/java/com/plotsquared/core/command/Help.java index e50b3d01b..8c654ad60 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Help.java +++ b/Core/src/main/java/com/plotsquared/core/command/Help.java @@ -25,14 +25,16 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.caption.StaticCaption; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.MathMan; 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.TextComponent; +import net.kyori.adventure.text.minimessage.Template; import java.util.concurrent.CompletableFuture; @@ -104,22 +106,21 @@ public class Help extends Command { } } if (cat == null && page == 0) { - StringBuilder builder = new StringBuilder(); - builder.append(Captions.HELP_HEADER.getTranslated()); + TextComponent.Builder builder = TextComponent.builder(); + builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_header").getComponent(player))); for (CommandCategory c : CommandCategory.values()) { - builder.append("\n").append(StringMan - .replaceAll(Captions.HELP_INFO_ITEM.getTranslated(), "%category%", - c.toString().toLowerCase(), "%category_desc%", c.toString())); + builder.append("\n").append(MINI_MESSAGE + .parse(TranslatableCaption.of("help.help_info_item").getComponent(player), Template.of("category", c.name().toLowerCase()), + Template.of("category_desc", c.getComponent(player)))); } - builder.append("\n").append( - Captions.HELP_INFO_ITEM.getTranslated().replaceAll("%category%", "all") - .replaceAll("%category_desc%", "Display all commands")); - builder.append("\n").append(Captions.HELP_FOOTER.getTranslated()); - player.sendMessage(StaticCaption.of(builder.toString())); + builder.append("\n").append(MINI_MESSAGE + .parse(TranslatableCaption.of("help.help_info_item").getComponent(player), Template.of("category", "all"), + Template.of("category_desc", "Display all commands"))); + builder.append("\n").append(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_footer").getComponent(player))); + player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.asComponent()))); return true; } - new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages() - .generatePage(page - 1, getParent().toString()).render(); + new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page - 1, getParent().toString()).render(); return true; }); } 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 3aa8fd9b1..aa177b427 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Inbox.java +++ b/Core/src/main/java/com/plotsquared/core/command/Inbox.java @@ -26,10 +26,10 @@ package com.plotsquared.core.command; import com.google.inject.TypeLiteral; -import com.plotsquared.core.configuration.Captions; -import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.player.MetaDataAccess; +import com.plotsquared.core.player.MetaDataKey; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.comment.CommentInbox; @@ -37,7 +37,8 @@ import com.plotsquared.core.plot.comment.CommentManager; import com.plotsquared.core.plot.comment.PlotComment; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal; -import com.plotsquared.core.player.MetaDataKey; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.Template; import java.util.List; @@ -70,25 +71,31 @@ public class Inbox extends SubCommand { if (max > comments.length) { max = comments.length; } - StringBuilder string = new StringBuilder(); - string.append(StringMan - .replaceAll(Captions.COMMENT_LIST_HEADER_PAGED.getTranslated(), "%amount%", - comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + '\n'); + TextComponent.Builder builder = TextComponent.builder(); + builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("list.comment_list_header_paged").getComponent(player) + '\n', + Template.of("amount", String.valueOf(comments.length)), Template.of("cur", String.valueOf(page + 1)), + Template.of("max", String.valueOf(totalPages + 1)), Template.of("word", "all"))); // This might work xD for (int x = page * 12; x < max; x++) { PlotComment comment = comments[x]; - String color; + Component commentColored; if (player.getName().equals(comment.senderName)) { - color = "&a"; + commentColored = MINI_MESSAGE + .parse(TranslatableCaption.of("list.comment_list_by_lister").getComponent(player), Template.of("comment", comment.comment)); } else { - color = "&7"; + commentColored = MINI_MESSAGE + .parse(TranslatableCaption.of("list.comment_list_by_other").getComponent(player), Template.of("comment", comment.comment)); } - string.append("&8[&7#").append(x + 1).append("&8][&7").append(comment.world).append(';') - .append(comment.id).append("&8][&6").append(comment.senderName).append("&8]") - .append(color).append(comment.comment).append('\n'); + Template number = Template.of("number", String.valueOf(x)); + Template world = Template.of("world", comment.world); + Template plot_id = Template.of("plot_id", comment.id.getX() + "" + comment.id.getY()); + Template commenter = Template.of("commenter", comment.senderName); + Template commentTemplate = Template.of("comment", commentColored); + builder.append(MINI_MESSAGE + .parse(TranslatableCaption.of("list.comment_list_comment").getComponent(player), number, world, plot_id, commenter, commentTemplate)); } - player.sendMessage(StaticCaption.of(string.toString())); + player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.build()))); } @Override public boolean onCommand(final PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index 36847c800..b723325b6 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -27,9 +27,10 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.backup.BackupManager; -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.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -187,9 +188,8 @@ public class Set extends SubCommand { if (plot != null) { newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getId()))); } - MainUtil.sendMessage(player, - Captions.SUBCOMMAND_SET_OPTIONS_HEADER.getTranslated() + StringMan - .join(newValues, Captions.BLOCK_LIST_SEPARATOR.formatted())); + player.sendMessage(StaticCaption.of(TranslatableCaption.of("commandconfig.subcommand_set_options_header").getComponent(player) + StringMan + .join(newValues, TranslatableCaption.of("blocklist.block_list_separator").getComponent(player)))); return false; } diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 4c46bfb15..f161e179f 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -330,7 +330,7 @@ "trim.trim_done": "Trim done.", "trim.trim_starting": "Collecting region data...", - "blocklist.block_list_separator": ", ", + "blocklist.block_list_separator": ", ", "biome.need_biome": "You need to specify a valid biome.", "biome.biome_set_to": "Plot biome set to ", @@ -398,6 +398,9 @@ "working.claimed": "You successfully claimed the plot.", "list.comment_list_header_paged": "(Page /) List of comments", + "list.comment_list_comment": "[#[;][]\n", + "list.comment_list_by_lister": "", + "list.comment_list_by_other": "", "list.clickable": " (interactive)", "list.area_list_header_paged": "(Page /) List of areas", "list.plot_list_header_paged": "(Page /) List of plots",