From 5478e70576d243c3d34c6d14ca42e182de8acd15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 17 Jul 2020 21:46:15 +0200 Subject: [PATCH] Fix some more captions --- .../core/backup/SimpleBackupManager.java | 10 +++-- .../com/plotsquared/core/command/Area.java | 22 +++++---- .../com/plotsquared/core/command/Chat.java | 3 +- .../plotsquared/core/command/DebugExec.java | 1 - .../com/plotsquared/core/command/ListCmd.java | 18 ++++++-- .../plotsquared/core/command/SubCommand.java | 6 --- .../com/plotsquared/core/command/Trust.java | 3 +- .../com/plotsquared/core/command/Visit.java | 45 +++++++++++-------- .../configuration/caption/CaptionMap.java | 4 +- .../java/com/plotsquared/core/plot/Plot.java | 1 - .../core/plot/expiration/ExpireManager.java | 13 +++--- Core/src/main/resources/lang/messages_en.json | 3 ++ 12 files changed, 73 insertions(+), 56 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java index 27f6efd38..7c957b286 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java @@ -30,8 +30,9 @@ import com.google.common.cache.CacheBuilder; import com.google.inject.Inject; import com.google.inject.Singleton; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.Templates; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -94,17 +95,18 @@ import java.util.concurrent.TimeUnit; whenDone.run(); } else { if (player != null) { - Captions.BACKUP_AUTOMATIC_STARTED.send(player); + player.sendMessage(TranslatableCaption.of("backups.backup_automatic_started")); } profile.createBackup().whenComplete((backup, throwable) -> { if (throwable != null) { if (player != null) { - Captions.BACKUP_AUTOMATIC_FAILURE.send(player, throwable.getMessage()); + player.sendMessage(TranslatableCaption.of("backups.backup_automatic_failure"), + Templates.of("reason", throwable.getMessage())); } throwable.printStackTrace(); } else { if (player != null) { - Captions.BACKUP_AUTOMATIC_FINISHED.send(player); + player.sendMessage(TranslatableCaption.of("backups.backup_automatic_finished")); TaskManager.runTaskAsync(whenDone); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 705b3917c..352265cca 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; +import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.events.TeleportCause; @@ -45,7 +46,6 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaTerrainType; import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; -import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.util.MainUtil; @@ -244,8 +244,8 @@ public class Area extends SubCommand { PlotSquared.get().loadWorld(world, null); player.sendMessage(TranslatableCaption.of("single.single_area_created")); } else { - player.sendMessage(TranslatableCaption.of("errors.error_create", - Template.of("world", hybridPlotWorld.getWorldName()))); + player.sendMessage(TranslatableCaption.of("errors.error_create"), + Template.of("world", hybridPlotWorld.getWorldName())); } }; singleRun.run(); @@ -260,16 +260,16 @@ public class Area extends SubCommand { } switch (args.length) { case 1: - Captions.COMMAND_SYNTAX - .send(player, "/plot area create [world[:id]] [=]..."); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", "/plot area create [world[:id]] [=]...")); return false; case 2: switch (args[1].toLowerCase()) { case "pos1": { // Set position 1 HybridPlotWorld area = player.getMeta("area_create_area"); if (area == null) { - Captions.COMMAND_SYNTAX.send(player, - "/plot area create [world[:id]] [=]..."); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", "/plot area create [world[:id]] [=]...")); return false; } Location location = player.getLocation(); @@ -277,16 +277,14 @@ public class Area extends SubCommand { player.sendMessage(TranslatableCaption.of("set.set_attribute"), Template.of("attribute", "area_pos1"), Template.of("value", location.getX() + "," + location.getZ())); - MainUtil.sendMessage(player, - "You will now set pos2: /plot area create pos2" - + "\nNote: The chosen plot size may result in the created area not exactly matching your second position."); + player.sendMessage(TranslatableCaption.of("area.set_pos2")); return true; } case "pos2": // Set position 2 and finish creation for type=2 (partial) final HybridPlotWorld area = player.getMeta("area_create_area"); if (area == null) { - Captions.COMMAND_SYNTAX.send(player, - "/plot area create [world[:id]] [=]..."); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", "/plot area create [world[:id]] [=]...")); return false; } Location pos1 = player.getLocation(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Chat.java b/Core/src/main/java/com/plotsquared/core/command/Chat.java index 3bf04f223..ca0765510 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Chat.java +++ b/Core/src/main/java/com/plotsquared/core/command/Chat.java @@ -26,6 +26,7 @@ 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.util.MainUtil; @@ -39,7 +40,7 @@ public class Chat extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] args) { if (player.getPlotAreaAbs().isForcingPlotChat()) { - MainUtil.sendMessage(player, Captions.PLOT_CHAT_FORCED); + player.sendMessage(TranslatableCaption.of("chat.plot_chat_forced")); return true; } MainCommand.getInstance().toggle.chat(this, player, args, null, null); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 2c2ba2989..0a5c6c4ed 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -44,7 +44,6 @@ import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.expiration.PlotAnalysis; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; -import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChunkManager; 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 d39bd75d7..7e7da1704 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -37,7 +37,6 @@ import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag; -import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.MainUtil; @@ -56,6 +55,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -391,7 +391,7 @@ public class ListCmd extends SubCommand { final List names = PlotSquared.get().getImpromptuUUIDPipeline() .getNames(plot.getOwners()).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS); for (final UUIDMapping uuidMapping : names) { - PlotPlayer pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()); + PlotPlayer pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()); if (pp != null) { message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1") .tooltip(new PlotMessage("Online").color("$4")); @@ -402,9 +402,19 @@ public class ListCmd extends SubCommand { prefix = ", "; } } catch (InterruptedException | ExecutionException e) { - MainUtil.sendMessage(player, Captions.INVALID_PLAYER); + final StringBuilder playerBuilder = new StringBuilder(); + final Iterator uuidIterator = plot.getOwners().iterator(); + while (uuidIterator.hasNext()) { + final UUID uuid = uuidIterator.next(); + playerBuilder.append(uuid); + if (uuidIterator.hasNext()) { + playerBuilder.append(", "); + } + } + player.sendMessage(TranslatableCaption.of("errors.invalid_player"), + Templates.of("value", playerBuilder.toString())); } catch (TimeoutException e) { - MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT); + player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); } } }, "/plot list " + args[0], Captions.PLOT_LIST_HEADER_PAGED.getTranslated()); diff --git a/Core/src/main/java/com/plotsquared/core/command/SubCommand.java b/Core/src/main/java/com/plotsquared/core/command/SubCommand.java index 8692d1cae..ad7665522 100644 --- a/Core/src/main/java/com/plotsquared/core/command/SubCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/SubCommand.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; @@ -48,11 +47,6 @@ public abstract class SubCommand extends Command { setRequiredArguments(arguments); } - public static boolean sendMessage(PlotPlayer player, Captions message, Object... args) { - message.send(player, args); - return true; - } - @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, diff --git a/Core/src/main/java/com/plotsquared/core/command/Trust.java b/Core/src/main/java/com/plotsquared/core/command/Trust.java index 616df92cc..fba82938c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trust.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trust.java @@ -27,6 +27,7 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -125,7 +126,7 @@ public class Trust extends Command { } currentPlot.addTrusted(uuid); this.eventDispatcher.callTrusted(player, currentPlot, uuid, true); - MainUtil.sendMessage(player, Captions.TRUSTED_ADDED); + player.sendMessage(TranslatableCaption.of("trusted.trusted_added")); } }, null); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Visit.java b/Core/src/main/java/com/plotsquared/core/command/Visit.java index b843ae3c3..b0e715311 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Visit.java +++ b/Core/src/main/java/com/plotsquared/core/command/Visit.java @@ -28,6 +28,8 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.configuration.caption.Templates; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -68,11 +70,6 @@ public class Visit extends Command { this.plotAreaManager = plotAreaManager; } - private void visit(@Nonnull final PlotPlayer player, @Nonnull final PlotQuery query, final PlotArea sortByArea, - final RunnableVal3 confirm, final RunnableVal2 whenDone) { - this.visit(player, query, sortByArea, confirm, whenDone, 1); - } - private void visit(@Nonnull final PlotPlayer player, @Nonnull final PlotQuery query, final PlotArea sortByArea, final RunnableVal3 confirm, final RunnableVal2 whenDone, int page) { // We get the query once, @@ -80,7 +77,7 @@ public class Visit extends Command { final List unsorted = query.asList(); if (unsorted.isEmpty()) { - Captions.FOUND_NO_PLOTS.send(player); + player.sendMessage(TranslatableCaption.of("invalid.found_no_plots")); return; } @@ -93,7 +90,8 @@ public class Visit extends Command { } if (page < 1 || page > unsorted.size()) { - MainUtil.sendMessage(player, String.format("(1, %d)", unsorted.size())); + // TODO: Huh? + // MainUtil.sendMessage(player, String.format("(1, %d)", unsorted.size())); return; } @@ -108,28 +106,33 @@ public class Visit extends Command { final Plot plot = plots.get(page - 1); if (!plot.hasOwner()) { if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_UNOWNED)) { - Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_UNOWNED); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Templates.of("node", "plots.visit.unowned")); return; } } else if (plot.isOwner(player.getUUID())) { if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions .hasPermission(player, Captions.PERMISSION_HOME)) { - Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Templates.of("node", "plots.visit.owned")); return; } } else if (plot.isAdded(player.getUUID())) { if (!Permissions.hasPermission(player, Captions.PERMISSION_SHARED)) { - Captions.NO_PERMISSION.send(player, Captions.PERMISSION_SHARED); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Templates.of("node", "plots.visit.shared")); return; } } else { if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) { - Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Templates.of("node", "plots.visit.other")); return; } if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) { - Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), + Templates.of("node", "plots.admin.visit.untrusted")); return; } } @@ -160,8 +163,10 @@ public class Visit extends Command { // /p v case 3: if (!MathMan.isInteger(args[2])) { - Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)"); - Captions.COMMAND_SYNTAX.send(player, getUsage()); + player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"), + Templates.of("value", "(1, ∞)")); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", getUsage())); return CompletableFuture.completedFuture(false); } page = Integer.parseInt(args[2]); @@ -171,8 +176,10 @@ public class Visit extends Command { if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) { sortByArea = this.plotAreaManager.getPlotAreaByString(args[1]); if (sortByArea == null) { - Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)"); - Captions.COMMAND_SYNTAX.send(player, getUsage()); + player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"), + Templates.of("value", "(1, ∞)")); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", getUsage())); return CompletableFuture.completedFuture(false); } @@ -182,7 +189,8 @@ public class Visit extends Command { if (throwable instanceof TimeoutException) { Captions.FETCHING_PLAYERS_TIMEOUT.send(player); } else if (throwable != null || uuids.size() != 1) { - Captions.COMMAND_SYNTAX.send(player, getUsage()); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", getUsage())); } else { final UUID uuid = uuids.toArray(new UUID[0])[0]; this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), finalSortByArea, confirm, whenDone, finalPage1); @@ -227,7 +235,8 @@ public class Visit extends Command { break; case 0: // /p v is invalid - Captions.COMMAND_SYNTAX.send(player, getUsage()); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), + Templates.of("value", getUsage())); return CompletableFuture.completedFuture(false); default: } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java index 7886c33c4..1b3efbbb8 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionMap.java @@ -25,14 +25,12 @@ */ package com.plotsquared.core.configuration.caption; -import net.kyori.text.Component; - import javax.annotation.Nonnull; import java.util.Locale; /** * Map containing mappings between {@link TranslatableCaption captions} and - * {@link Component components} + * {@link net.kyori.adventure.text.Component components} */ public interface CaptionMap { 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 002ea1bea..50fbe9dde 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -104,7 +104,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.stream.Collectors; -import static com.plotsquared.core.command.SubCommand.sendMessage; import static com.plotsquared.core.util.entity.EntityCategories.CAP_ANIMAL; import static com.plotsquared.core.util.entity.EntityCategories.CAP_ENTITY; import static com.plotsquared.core.util.entity.EntityCategories.CAP_MISC; diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java index 68f2c4b89..c8ee8ff6e 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java @@ -27,6 +27,8 @@ package com.plotsquared.core.plot.expiration; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; +import com.plotsquared.core.configuration.caption.Templates; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.PlotFlagAddEvent; import com.plotsquared.core.events.PlotUnlinkEvent; @@ -40,7 +42,6 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.plot.flag.implementations.KeepFlag; -import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.query.PlotQuery; @@ -417,15 +418,17 @@ public class ExpireManager { } } for (UUID helper : plot.getTrusted()) { - PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper); + PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper); if (player != null) { - MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString()); + player.sendMessage(TranslatableCaption.of("trusted.plot_removed_user"), + Templates.of("plot", plot.toString())); } } for (UUID helper : plot.getMembers()) { - PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper); + PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper); if (player != null) { - MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString()); + player.sendMessage(TranslatableCaption.of("trusted.plot_removed_user"), + Templates.of("plot", plot.toString())); } } plot.deletePlot(whenDone); diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 19445d541..9d8fcb2c4 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -15,6 +15,8 @@ "debug.plot_debug": "[Plot Debug] (): ", "set.set_attribute": "Successfully set to .", + + "area.set_pos2": "You will now set pos2: /plot area create pos2. Note: The chosen plot size may result in the created area not exactly matching your second position.", "web.generating_link": "Processing plot...", "web.generating_link_failed": "Failed to generate download link!", @@ -223,6 +225,7 @@ "invalid.not_a_number": " is not a valid number.", "errors.invalid_player": "Player not found: .", + "errors.invalid_player_offline": "The player must be online: .", "errors.invalid_command_flag": "Invalid command flag: ", "errors.error": "An error occurred: ",