From 2aa5c276c98055d5c11d2668a83d1ede24beaa70 Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Tue, 21 Jul 2020 21:39:52 +0200 Subject: [PATCH] Some more work done towards json --- .../com/plotsquared/core/command/Add.java | 2 +- .../com/plotsquared/core/command/Area.java | 87 ++-- .../com/plotsquared/core/command/Auto.java | 35 +- .../com/plotsquared/core/command/Backup.java | 135 ++++-- .../com/plotsquared/core/command/Claim.java | 38 +- .../com/plotsquared/core/command/Cluster.java | 389 ++++++++++++------ .../plotsquared/core/command/Condense.java | 93 +++-- .../plotsquared/core/command/Continue.java | 17 +- .../com/plotsquared/core/command/Copy.java | 21 +- .../core/command/CreateRoadSchematic.java | 4 +- .../core/command/DatabaseCommand.java | 67 +-- .../core/command/DebugAllowUnsafe.java | 5 +- .../plotsquared/core/command/DebugExec.java | 39 +- Core/src/main/resources/lang/messages_en.json | 100 ++++- 14 files changed, 698 insertions(+), 334 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Add.java b/Core/src/main/java/com/plotsquared/core/command/Add.java index 88c304b3e..4850addf7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Add.java +++ b/Core/src/main/java/com/plotsquared/core/command/Add.java @@ -49,7 +49,7 @@ import java.util.concurrent.TimeoutException; @CommandDeclaration(command = "add", description = "Allow a user to build in a plot while the plot owner is online.", - usage = "/plot add ", + usage = "/plot add ", category = CommandCategory.SETTINGS, permission = "plots.add", requiredType = RequiredType.PLAYER) 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 1698d68ec..995ddba32 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -72,6 +72,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; @@ -346,9 +347,10 @@ public class Area extends SubCommand { }, null); } } else { - MainUtil.sendMessage(player, - "An error occurred while creating the world: " + area - .getWorldName()); + player.sendMessage( + TranslatableCaption.of("errors.error_create"), + Template.of("world", area.getWorldName()) + ); } }; if (hasConfirmation(player)) { @@ -386,8 +388,11 @@ public class Area extends SubCommand { for (int i = 2; i < args.length; i++) { String[] pair = args[i].split("="); if (pair.length != 2) { - Captions.COMMAND_SYNTAX.send(player, getCommandString() - + " create [world[:id]] [=]..."); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1,", getCommandString()), + Template.of("value2", " create [world[:id]] [=]...") + ); return false; } switch (pair[0].toLowerCase()) { @@ -441,8 +446,11 @@ public class Area extends SubCommand { builder.plotAreaType(pa.getType()); break; default: - Captions.COMMAND_SYNTAX.send(player, getCommandString() - + " create [world[:id]] [=]..."); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1", getCommandString()), + Template.of("value2", " create [world[:id]] [=]...") + ); return false; } } @@ -468,9 +476,10 @@ public class Area extends SubCommand { player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND); } else { - MainUtil.sendMessage(player, - "An error occurred while creating the world: " + pa - .getWorldName()); + player.sendMessage( + TranslatableCaption.of("errors.error_create"), + Template.of("world", pa.getWorldName()) + ); } try { this.worldConfiguration.save(this.worldFile); @@ -487,8 +496,15 @@ public class Area extends SubCommand { return true; } if (pa.getId() == null) { - Captions.COMMAND_SYNTAX.send(player, getCommandString() - + " create [world[:id]] [=]..."); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", getCommandString + ) + ); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1", getCommandString()), + Template.of("value2", " create [world[:id]] [=]...") + ); return false; } if (this.worldUtil.isWorld(pa.getWorldName())) { @@ -504,9 +520,10 @@ public class Area extends SubCommand { TeleportCause.COMMAND); } player.setMeta("area_create_area", pa); - MainUtil.sendMessage(player, - "$1Go to the first corner and use: $2 " + getCommandString() - + " create pos1"); + player.sendMessage( + TranslatableCaption.of("single.get_position"), + Template.of("command", getCommandString()) + ); break; } return true; @@ -526,7 +543,11 @@ public class Area extends SubCommand { area = this.plotAreaManager.getPlotAreaByString(args[1]); break; default: - Captions.COMMAND_SYNTAX.send(player, getCommandString() + " info [area]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1", getCommandString()), + Template.of("value2", " info [area]") + ); return false; } if (area == null) { @@ -584,7 +605,11 @@ public class Area extends SubCommand { break; } default: - Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1", getCommandString()), + Template.of("value2", " list [#]") + ); return false; } final List areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas())); @@ -640,12 +665,16 @@ public class Area extends SubCommand { } final PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage( + TranslatableCaption.of("errors.not_in_plot_world") + ); return false; } if (area.getType() != PlotAreaType.PARTIAL) { - MainUtil.sendMessage(player, - "$4Stop the server and delete: " + area.getWorldName() + "/region"); + player.sendMessage( + TranslatableCaption.of("single.delete_world_region"), + Template.of("world", area.getWorldName()) + ); return false; } this.regionManager.largeRegionTask(area.getWorldName(), area.getRegion(), @@ -655,7 +684,9 @@ public class Area extends SubCommand { .generate(null, area.getWorldName(), value.getX(), value.getZ(), null); } - }, () -> player.sendMessage("Regen complete")); + }, () -> player.sendMessage( + TranslatableCaption.of("single.regeneration_complete")) + ); return true; } case "goto": @@ -669,7 +700,10 @@ public class Area extends SubCommand { return false; } if (args.length != 2) { - Captions.COMMAND_SYNTAX.send(player, "/plot visit [area]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot visit [area]") + ); return false; } PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]); @@ -694,12 +728,9 @@ public class Area extends SubCommand { return true; case "delete": case "remove": - MainUtil.sendMessage(player, - "$1World creation settings may be stored in multiple locations:" - + "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2" + PlotSquared.platform() - .getPluginName() + " settings.yml" - + "\n$3 - $2Multiverse worlds.yml (or any world management plugin)" - + "\n$1Stop the server and delete it from these locations."); + player.sendMessage( + TranslatableCaption.of("single.worldcreation_location") + ); return true; } sendUsage(player); diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java index a168b8100..e822b90c9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Auto.java +++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java @@ -29,6 +29,7 @@ import com.google.common.collect.Lists; import com.google.common.primitives.Ints; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; @@ -64,7 +65,7 @@ import java.util.Set; requiredType = RequiredType.NONE, description = "Claim the nearest plot", aliases = "a", - usage = "/plot auto [length,width]") + usage = "/plot auto [length, width]") public class Auto extends SubCommand { private final PlotAreaManager plotAreaManager; @@ -213,11 +214,16 @@ public class Auto extends SubCommand { size_z = Integer.parseInt(split[1]); break; default: - MainUtil.sendMessage(player, "Correct use /plot auto [length,width]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", getUsage()) + ); return true; } if (size_x < 1 || size_z < 1) { - MainUtil.sendMessage(player, "Error: size<=0"); + player.sendMessage( + TranslatableCaption.of("error.plot_size") + ); } if (args.length > 1) { schematic = args[1]; @@ -261,16 +267,21 @@ public class Auto extends SubCommand { if (schematic != null && !schematic.isEmpty()) { if (!plotarea.hasSchematic(schematic)) { - sendMessage(player, Captions.SCHEMATIC_INVALID, "non-existent: " + schematic); + player.sendMessage( + TranslatableCaption.of("schematics.schematic_invalid_named"), + Template.of("schemname", schematic), + Template.of("reason", "non-existant") + ); return true; } if (!force && !Permissions.hasPermission(player, CaptionUtility .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility - .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), - schematic)); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated()) + ); return true; } } @@ -282,11 +293,17 @@ public class Auto extends SubCommand { cost = (size_x * size_z) * cost; if (cost > 0d) { if (!force && this.econHandler.getMoney(player) < cost) { - sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost); + player.sendMessage( + TranslatableCaption.of("economy.cannot_afford_plot"), + Template.of("money", String.valueOf(cost)) + ); return true; } this.econHandler.withdrawMoney(player, cost); - sendMessage(player, Captions.REMOVED_BALANCE, cost + ""); + player.sendMessage( + TranslatableCaption.of("economy.removed_balance"), + Template.of("money", String.valueOf(cost)) + ); } } // TODO handle type 2 (partial) the same as normal worlds! 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 ec758a2e4..634eb0579 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Backup.java +++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java @@ -37,6 +37,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; import java.nio.file.Files; @@ -131,26 +132,35 @@ public final class Backup extends Command { if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); } else if (!plot.hasOwner()) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_UNOWNED.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_unowned") + ); } else if (plot.isMerged()) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_MERGED.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_merged") + ); } else if (!plot.isOwner(player.getUUID()) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) { - sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_ADMIN_BACKUP_OTHER.getTranslated()) + ); } else { final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof NullBackupProfile) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_OTHER.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_other") + ); } else { backupProfile.createBackup().whenComplete((backup, throwable) -> { if (throwable != null) { sendMessage(player, Captions.BACKUP_SAVE_FAILED, throwable.getMessage()); throwable.printStackTrace(); } else { - sendMessage(player, Captions.BACKUP_SAVE_SUCCESS); + player.sendMessage(TranslatableCaption.of("backups.backup_save_success")); } }); } @@ -170,34 +180,50 @@ public final class Backup extends Command { if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); } else if (!plot.hasOwner()) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_UNOWNED.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_unowned") + ); } else if (plot.isMerged()) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_MERGED.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_merged") + ); } else if (!plot.isOwner(player.getUUID()) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) { - sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_ADMIN_BACKUP_OTHER.getTranslated()) + ); } else { final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof NullBackupProfile) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_OTHER.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_other") + ); } else { backupProfile.listBackups().whenComplete((backups, throwable) -> { if (throwable != null) { - sendMessage(player, Captions.BACKUP_LIST_FAILED, throwable.getMessage()); + player.sendMessage( + TranslatableCaption.of("backups.backup_list_failed"), + Template.of("reason", throwable.getMessage()) + ); throwable.printStackTrace(); } else { - sendMessage(player, Captions.BACKUP_LIST_HEADER, - plot.getId().toCommaSeparatedString()); + player.sendMessage( + TranslatableCaption.of("backups.backup_list_header"), + Template.of("plot", plot.getId().toCommaSeparatedString()) + ); try { for (int i = 0; i < backups.size(); i++) { - sendMessage(player, Captions.BACKUP_LIST_ENTRY, - Integer.toString(i + 1), DateTimeFormatter.RFC_1123_DATE_TIME - .format(ZonedDateTime.ofInstant( - Instant.ofEpochMilli(backups.get(i).getCreationTime()), - ZoneId.systemDefault()))); + player.sendMessage( + TranslatableCaption.of("backups.backup_list_entry"), + Template.of("number", Integer.toString(i + 1)), + Template.of("value", DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.ofInstant( + Instant.ofEpochMilli(backups.get(i).getCreationTime()), + ZoneId.systemDefault()))) + ); } } catch (final Exception e) { e.printStackTrace(); @@ -221,54 +247,81 @@ public final class Backup extends Command { if (plot == null) { player.sendMessage(TranslatableCaption.of("errors.not_in_plot")); } else if (!plot.hasOwner()) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_UNOWNED.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_unowned") + ); } else if (plot.isMerged()) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_MERGED.getTranslated()); - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, "merged"); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_merged") + ); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_merged") + ); } else if (!plot.isOwner(player.getUUID()) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) { - sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_ADMIN_BACKUP_OTHER.getTranslated()) + ); } else if (args.length == 0) { - sendMessage(player, Captions.BACKUP_LOAD_USAGE); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "Usage: /plot backup save/list/load") + ); } else { final int number; try { number = Integer.parseInt(args[0]); } catch (final Exception e) { - sendMessage(player, Captions.NOT_A_NUMBER, args[0]); + player.sendMessage( + TranslatableCaption.of("invalid.not_a_number"), + Template.of("value", args[0]) + ); return; } final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot)); if (backupProfile instanceof NullBackupProfile) { - sendMessage(player, Captions.BACKUP_IMPOSSIBLE, - Captions.GENERIC_OTHER.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_other") + ); } else { backupProfile.listBackups().whenComplete((backups, throwable) -> { if (throwable != null) { - sendMessage(player, Captions.BACKUP_LOAD_FAILURE, throwable.getMessage()); + player.sendMessage( + TranslatableCaption.of("backups.backup_load_failure"), + Template.of("reason", throwable.getMessage()) + ); throwable.printStackTrace(); } else { if (number < 1 || number > backups.size()) { - sendMessage(player, Captions.BACKUP_LOAD_FAILURE, - Captions.GENERIC_INVALID_CHOICE.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_invalid_choice") + ); } else { final com.plotsquared.core.backup.Backup backup = backups.get(number - 1); if (backup == null || backup.getFile() == null || !Files .exists(backup.getFile())) { - sendMessage(player, Captions.BACKUP_LOAD_FAILURE, - Captions.GENERIC_INVALID_CHOICE.getTranslated()); + player.sendMessage( + TranslatableCaption.of("backup_impossible"), + Template.of("plot", "generic.generic_invalid_choice") + ); } else { CmdConfirm.addPending(player, "/plot backup load " + number, () -> backupProfile.restoreBackup(backup) .whenComplete((n, error) -> { if (error != null) { - sendMessage(player, Captions.BACKUP_LOAD_FAILURE, - error.getMessage()); + player.sendMessage( + TranslatableCaption.of("backups.backup_load_failure"), + Template.of("reason", error.getMessage()) + ); } else { - sendMessage(player, Captions.BACKUP_LOAD_SUCCESS); + player.sendMessage(TranslatableCaption.of("backup_load_success")); } })); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index 27d601db1..d5b1c3501 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -96,27 +96,33 @@ public class Claim extends SubCommand { grants = Ints.fromByteArray(player.getPersistentMeta("grantedPlots")); if (grants <= 0) { player.removePersistentMeta("grantedPlots"); - return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS); + player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots")); } } else { - return sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS); + player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots")); } } if (!plot.canClaim(player)) { - return sendMessage(player, Captions.PLOT_IS_CLAIMED); + player.sendMessage(TranslatableCaption.of("working.plot_is_claimed")); } final PlotArea area = plot.getArea(); if (schematic != null && !schematic.isEmpty()) { if (area.isSchematicClaimSpecify()) { if (!area.hasSchematic(schematic)) { - return sendMessage(player, Captions.SCHEMATIC_INVALID, - "non-existent: " + schematic); + player.sendMessage( + TranslatableCaption.of("schematics.schematic_invalid_named"), + Template.of("schemname", schematic), + Template.of("reason", "non-existant") + ); } if (!Permissions.hasPermission(player, CaptionUtility .format(player, Captions.PERMISSION_CLAIM_SCHEMATIC.getTranslated(), schematic)) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SCHEMATIC) && !force) { - return sendMessage(player, Captions.NO_SCHEMATIC_PERMISSION, schematic); + player.sendMessage( + TranslatableCaption.of("permission.no_schematic_permission"), + Template.of("value", schematic) + ); } } } @@ -125,10 +131,16 @@ public class Claim extends SubCommand { double cost = costExr.evaluate((double) currentPlots); if (cost > 0d) { if (this.econHandler.getMoney(player) < cost) { - return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost); + player.sendMessage( + TranslatableCaption.of("economy.cannot_afford_plot"), + Template.of("money", String.valueOf(cost)) + ); } this.econHandler.withdrawMoney(player, cost); - sendMessage(player, Captions.REMOVED_BALANCE, cost + ""); + player.sendMessage( + TranslatableCaption.of("economy.removed_balance"), + Template.of("money", String.valueOf(cost)) + ); } } if (grants > 0) { @@ -137,7 +149,11 @@ public class Claim extends SubCommand { } else { player.setPersistentMeta("grantedPlots", Ints.toByteArray(grants - 1)); } - sendMessage(player, Captions.REMOVED_GRANTED_PLOT, "1", (grants - 1)); + player.sendMessage( + TranslatableCaption.of("economy.removed_granted_plot"), + Template.of("usedGrants", String.valueOf((grants -1))), + Template.of("remainingGrants", String.valueOf(grants)) + ); } int border = area.getBorder(); if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) { @@ -151,7 +167,7 @@ public class Claim extends SubCommand { if (!plot.claim(player, true, finalSchematic, false)) { logger.info(Captions.PREFIX.getTranslated() + String .format("Failed to claim plot %s", plot.getId().toCommaSeparatedString())); - sendMessage(player, Captions.PLOT_NOT_CLAIMED); + player.sendMessage(TranslatableCaption.of("working.plot_not_claimed")); plot.setOwnerAbs(null); } else if (area.isAutoMerge()) { PlotMergeEvent mergeEvent = Claim.this.eventDispatcher @@ -173,7 +189,7 @@ public class Claim extends SubCommand { logger.info(Captions.PREFIX.getTranslated() + String .format("Failed to add plot %s to the database", plot.getId().toCommaSeparatedString())); - sendMessage(player, Captions.PLOT_NOT_CLAIMED); + player.sendMessage(TranslatableCaption.of("working.plot_not_claimed")); plot.setOwnerAbs(null); }); return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java index 6affaf62f..0663d1b29 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java +++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java @@ -28,6 +28,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.location.BlockLoc; @@ -39,6 +40,8 @@ import com.plotsquared.core.plot.PlotCluster; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.query.PlotQuery; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.minimessage.Template; import java.util.HashSet; import java.util.Set; @@ -58,7 +61,7 @@ public class Cluster extends SubCommand { // list, create, delete, resize, invite, kick, leave, helpers, tp, sethome if (args.length == 0) { // return arguments - MainUtil.sendMessage(player, Captions.CLUSTER_AVAILABLE_ARGS); + player.sendMessage(TranslatableCaption.of("cluster.cluster_available_args")); return false; } String sub = args[0].toLowerCase(); @@ -66,33 +69,52 @@ public class Cluster extends SubCommand { case "l": case "list": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_LIST)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_LIST); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_LIST.getTranslated()) + ); return false; } if (args.length != 1) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot cluster list"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster list") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; } Set clusters = area.getClusters(); - MainUtil.sendMessage(player, Captions.CLUSTER_LIST_HEADING, clusters.size() + ""); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_list_heading"), + Template.of("amount", clusters.size() + "") + ); for (PlotCluster cluster : clusters) { // Ignore unmanaged clusters String name = "'" + cluster.getName() + "' : " + cluster.toString(); if (player.getUUID().equals(cluster.owner)) { - MainUtil.sendMessage(player, Captions.CLUSTER_LIST_ELEMENT, "&a" + name); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_list_element_owner"), + Template.of("cluster", name) + ); } else if (cluster.helpers.contains(player.getUUID())) { - MainUtil.sendMessage(player, Captions.CLUSTER_LIST_ELEMENT, "&3" + name); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_list_element_helpers"), + Template.of("cluster", name) + ); } else if (cluster.invited.contains(player.getUUID())) { - MainUtil.sendMessage(player, Captions.CLUSTER_LIST_ELEMENT, "&9" + name); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_list_element_invited"), + Template.of("cluster", name) + ); } else { - MainUtil - .sendMessage(player, Captions.CLUSTER_LIST_ELEMENT, cluster.toString()); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_list_element"), + Template.of("cluster", cluster.toString()) + ); } } return true; @@ -100,25 +122,29 @@ public class Cluster extends SubCommand { case "c": case "create": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_CREATE)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_CREATE); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_CREATE.getTranslated()) + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; } if (args.length != 4) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster create "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster create ") + ); return false; } int currentClusters = Settings.Limit.GLOBAL ? player.getClusterCount() : player.getPlotCount(player.getLocation().getWorldName()); if (currentClusters >= player.getAllowedPlots()) { - return sendMessage(player, Captions.CANT_CLAIM_MORE_CLUSTERS); + player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_clusters")); } PlotId pos1; PlotId pos2; @@ -127,13 +153,13 @@ public class Cluster extends SubCommand { pos1 = PlotId.fromString(args[2]); pos2 = PlotId.fromString(args[3]); } catch (IllegalArgumentException ignored) { - MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); + player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id")); return false; } // check if name is taken String name = args[1]; if (area.getCluster(name) != null) { - MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN); + player.sendMessage(TranslatableCaption.of("alias.alias_is_taken")); return false; } if (pos2.getX() < pos1.getX() || pos2.getY() < pos1.getY()) { @@ -144,12 +170,18 @@ public class Cluster extends SubCommand { //check if overlap PlotCluster cluster = area.getFirstIntersectingCluster(pos1, pos2); if (cluster != null) { - MainUtil.sendMessage(player, Captions.CLUSTER_INTERSECTION, cluster.getName()); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_intersection"), + Template.of("cluster", cluster.getName()) + ); return false; } // Check if it occupies existing plots if (!area.contains(pos1) || !area.contains(pos2)) { - Captions.CLUSTER_OUTSIDE.send(player, area); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_outside"), + Template.of("area", area) + ); return false; } Set plots = area.getPlotSelectionOwned(pos1, pos2); @@ -159,8 +191,10 @@ public class Cluster extends SubCommand { UUID uuid = player.getUUID(); for (Plot plot : plots) { if (!plot.isOwner(uuid)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_CREATE_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_CREATE_OTHER.getTranslated()) + ); return false; } } @@ -178,8 +212,10 @@ public class Cluster extends SubCommand { .hasPermissionRange(player, Captions.PERMISSION_CLUSTER_SIZE, Settings.Limit.MAX_PLOTS); if (current + cluster.getArea() > allowed) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_SIZE + "." + (current + cluster.getArea())); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_SIZE.getTranslated() + "." + (current + cluster.getArea())) + ); return false; } // create cluster @@ -195,63 +231,74 @@ public class Cluster extends SubCommand { } } } - MainUtil.sendMessage(player, Captions.CLUSTER_ADDED); + player.sendMessage(TranslatableCaption.of("cluster.cluster_added")); return true; } case "disband": case "del": case "delete": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_DELETE)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_DELETE); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_DELETE.getTranslated()) + ); return false; } if (args.length != 1 && args.length != 2) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster delete [name]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster delete [name]") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; } PlotCluster cluster; if (args.length == 2) { cluster = area.getCluster(args[1]); if (cluster == null) { - MainUtil.sendMessage(player, Captions.INVALID_CLUSTER, args[1]); + player.sendMessage( + TranslatableCaption.of("cluster.invalid_cluster_name"), + Template.of("cluster", args[1]) + ); return false; } } else { cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("cluster.not_in_cluster")); return false; } } if (!cluster.owner.equals(player.getUUID())) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_DELETE_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_DELETE_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_DELETE_OTHER.getTranslated())); return false; } } DBFunc.delete(cluster); - MainUtil.sendMessage(player, Captions.CLUSTER_DELETED); + player.sendMessage(TranslatableCaption.of("cluster.cluster_deleted")); return true; } case "res": case "resize": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_RESIZE)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_RESIZE); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_RESIZE.getTranslated())); return false; } if (args.length != 3) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster resize "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster delete [name]") + ); return false; } PlotId pos1; @@ -261,7 +308,7 @@ public class Cluster extends SubCommand { pos1 = PlotId.fromString(args[2]); pos2 = PlotId.fromString(args[3]); } catch (IllegalArgumentException ignored) { - MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); + player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id")); return false; } if (pos2.getX() < pos1.getX() || pos2.getY() < pos1.getY()) { @@ -271,27 +318,30 @@ public class Cluster extends SubCommand { // check if in cluster PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; } PlotCluster cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_pcluster")); return false; } if (!cluster.hasHelperRights(player.getUUID())) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_RESIZE_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_RESIZE_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission") + Template.of("node", Captions.PERMISSION_CLUSTER_RESIZE_OTHER.getTranslated())); return false; } } //check if overlap PlotCluster intersect = area.getFirstIntersectingCluster(pos1, pos2); if (intersect != null) { - MainUtil - .sendMessage(player, Captions.CLUSTER_INTERSECTION, intersect.getName()); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_intersection"), + Template.of("cluster", intersect.getName()) + ); return false; } Set existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2()); @@ -304,8 +354,10 @@ public class Cluster extends SubCommand { if (!removed.isEmpty()) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_RESIZE_SHRINK)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_RESIZE_SHRINK); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_RESIZE_SHRINK.getTranslated()) + ); return false; } } @@ -313,8 +365,10 @@ public class Cluster extends SubCommand { if (!newPlots.isEmpty()) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_RESIZE_EXPAND)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_RESIZE_EXPAND); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_RESIZE_EXPAND.getTranslated()) + ); return false; } } @@ -329,44 +383,52 @@ public class Cluster extends SubCommand { int allowed = Permissions.hasPermissionRange(player, Captions.PERMISSION_CLUSTER, Settings.Limit.MAX_PLOTS); if (current + cluster.getArea() > allowed) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER.getTranslated() + "." + (current + cluster - .getArea())); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER.getTranslated() + "." + (current + cluster + .getArea())) + ); return false; } // resize cluster DBFunc.resizeCluster(cluster, pos1, pos2); - MainUtil.sendMessage(player, Captions.CLUSTER_RESIZED); + player.sendMessage(TranslatableCaption.of("cluster.clister_resized")); return true; } case "add": case "inv": case "invite": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_INVITE)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_INVITE); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_INVITE.getTranslated()) + ); return false; } if (args.length != 2) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster invite "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster invite ") + ); return false; } // check if in cluster PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } PlotCluster cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_cluster")); return false; } if (!cluster.hasHelperRights(player.getUUID())) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_INVITE_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_INVITE_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_INVITE_OTHER.getTranslated()) + ); return false; } } @@ -374,23 +436,27 @@ public class Cluster extends SubCommand { PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(args[1], (uuid, throwable) -> { if (throwable instanceof TimeoutException) { - MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT); + player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); } else if (throwable != null) { - MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]); + player.sendMessage( + TranslatableCaption.of("errors.invalid_player"), + Template.of("value", args[1]) + ); } else { if (!cluster.isAdded(uuid)) { // add the user if not added cluster.invited.add(uuid); DBFunc.setInvited(cluster, uuid); - final PlotPlayer otherPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (otherPlayer != null) { - MainUtil.sendMessage(otherPlayer, Captions.CLUSTER_INVITED, - cluster.getName()); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_invited"), + Template.of("cluster", cluster.getName()) + ); } } - MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_USER); + player.sendMessage(TranslatableCaption.of("cluster.cluster_added_user")); } }); return true; @@ -399,29 +465,35 @@ public class Cluster extends SubCommand { case "remove": case "kick": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_KICK)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_KICK); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_KICK.getTranslated()) + ); return false; } if (args.length != 2) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster kick "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster kick ") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } PlotCluster cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_cluster")); return false; } if (!cluster.hasHelperRights(player.getUUID())) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_KICK_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_KICK_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_KICK_OTHER.getTranslated()) + ); return false; } } @@ -429,15 +501,20 @@ public class Cluster extends SubCommand { PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(args[1], (uuid, throwable) -> { if (throwable instanceof TimeoutException) { - MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT); + player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); } else if (throwable != null) { - MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]); + player.sendMessage( + TranslatableCaption.of("errors.invalid_player"), + Template.of("value", args[1]) + ); } else { // Can't kick if the player is yourself, the owner, or not added to the cluster if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) { - MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER, - cluster.getName()); + player.sendMessage( + TranslatableCaption.of("cluster.cannot_kick_player"), + Template.of("value", cluster.getName()) + ); } else { if (cluster.helpers.contains(uuid)) { cluster.helpers.remove(uuid); @@ -449,8 +526,10 @@ public class Cluster extends SubCommand { final PlotPlayer player2 = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid); if (player2 != null) { - MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED, - cluster.getName()); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_removed"), + Template.of("cluster", cluster.getName()) + ); } for (final Plot plot : PlotQuery.newQuery().inWorld(player2.getLocation() .getWorldName()).ownedBy(uuid)) { @@ -459,7 +538,7 @@ public class Cluster extends SubCommand { plot.unclaim(); } } - MainUtil.sendMessage(player2, Captions.CLUSTER_KICKED_USER); + player.sendMessage(TranslatableCaption.of("cluster.cluster_kicked_user")); } } }); @@ -468,40 +547,47 @@ public class Cluster extends SubCommand { case "quit": case "leave": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_LEAVE)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_LEAVE); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_LEAVE.getTranslated()) + ); return false; } if (args.length != 1 && args.length != 2) { - MainUtil - .sendMessage(player, Captions.COMMAND_SYNTAX, "/plot cluster leave [name]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster leave [name]") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } PlotCluster cluster; if (args.length == 2) { cluster = area.getCluster(args[1]); if (cluster == null) { - MainUtil.sendMessage(player, Captions.INVALID_CLUSTER, args[1]); + player.sendMessage( + TranslatableCaption.of("cluster.invalid_cluster_name"), + Template.of("cluster", args[1]) + ); return false; } } else { cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_cluster")); return false; } } UUID uuid = player.getUUID(); if (!cluster.isAdded(uuid)) { - MainUtil.sendMessage(player, Captions.CLUSTER_NOT_ADDED); + player.sendMessage(TranslatableCaption.of("cluster.cluster_not_added")); return false; } if (uuid.equals(cluster.owner)) { - MainUtil.sendMessage(player, Captions.CLUSTER_CANNOT_LEAVE); + player.sendMessage(TranslatableCaption.of("cluster.cluster_cannot_leave")); return false; } if (cluster.helpers.contains(uuid)) { @@ -510,7 +596,10 @@ public class Cluster extends SubCommand { } cluster.invited.remove(uuid); DBFunc.removeInvited(cluster, uuid); - MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED, cluster.getName()); + player.sendMessage( + TranslatableCaption.of("cluster.cluster_removed"), + Template.of("cluster", cluster.getName()) + ); for (final Plot plot : PlotQuery.newQuery().inWorld(player.getLocation().getWorldName()) .ownedBy(uuid)) { PlotCluster current = plot.getCluster(); @@ -525,43 +614,52 @@ public class Cluster extends SubCommand { case "helper": case "helpers": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_HELPERS)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_HELPERS); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_HELPERS.getTranslated()) + ); return false; } if (args.length != 3) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster helpers "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster helpers ") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } PlotCluster cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_cluster")); return false; } PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(args[2], (uuid, throwable) -> { if (throwable instanceof TimeoutException) { - MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT); + player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); } else if (throwable != null) { - MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]); + player.sendMessage( + TranslatableCaption.of("errors.invalid_player"), + Template.of("value", args[2]) + ); } else { if (args[1].equalsIgnoreCase("add")) { cluster.helpers.add(uuid); DBFunc.setHelper(cluster, uuid); - MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER); + player.sendMessage(TranslatableCaption.of("cluster.cluster_added_helper")); } else if (args[1].equalsIgnoreCase("remove")) { cluster.helpers.remove(uuid); DBFunc.removeHelper(cluster, uuid); - MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER); + player.sendMessage(TranslatableCaption.of("cluster.cluster_removed_helper")); } else { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot cluster helpers "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster helpers ") + ); } } }); @@ -571,65 +669,77 @@ public class Cluster extends SubCommand { case "home": case "tp": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_TP)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_TP); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_TP.getTranslated()) + ); return false; } if (args.length != 2) { - MainUtil - .sendMessage(player, Captions.COMMAND_SYNTAX, "/plot cluster tp "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster tp ") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; } PlotCluster cluster = area.getCluster(args[1]); if (cluster == null) { - MainUtil.sendMessage(player, Captions.INVALID_CLUSTER, args[1]); + player.sendMessage( + TranslatableCaption.of("cluster.invalid_cluster"), + Template.of("cluster", args[1]) + ); return false; } UUID uuid = player.getUUID(); if (!cluster.isAdded(uuid)) { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_TP_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_TP_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_TP_OTHER.getTranslated()) + ); return false; } } cluster.getHome(home -> player.teleport(home, TeleportCause.COMMAND)); - return MainUtil.sendMessage(player, Captions.CLUSTER_TELEPORTING); + player.sendMessage(TranslatableCaption.of("cluster.cluster_teleporting")); } case "i": case "info": case "show": case "information": { if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_INFO)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_INFO); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_TP.getTranslated()) + ); return false; } if (args.length != 1 && args.length != 2) { - MainUtil - .sendMessage(player, Captions.COMMAND_SYNTAX, "/plot cluster info [name]"); - return false; + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster info [name]") + ); } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } PlotCluster cluster; if (args.length == 2) { cluster = area.getCluster(args[1]); - if (cluster == null) { - MainUtil.sendMessage(player, Captions.INVALID_CLUSTER, args[1]); - return false; - } + player.sendMessage( + TranslatableCaption.of("cluster.invalid_cluster"), + Template.of("cluster", args[1]) + ); } else { cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_cluster")); return false; } } @@ -638,7 +748,7 @@ public class Cluster extends SubCommand { PlotSquared.get().getImpromptuUUIDPipeline() .getSingle(cluster.owner, (username, throwable) -> { if (throwable instanceof TimeoutException) { - MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT); + player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); } else { final String owner; if (username == null) { @@ -665,28 +775,35 @@ public class Cluster extends SubCommand { case "setspawn": case "sethome": if (!Permissions.hasPermission(player, Captions.PERMISSION_CLUSTER_SETHOME)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_SETHOME); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_SETHOME.getTranslated()) + ); return false; } if (args.length != 1 && args.length != 2) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, "/plot cluster sethome"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot cluster sethome") + ); return false; } PlotArea area = player.getApplicablePlotArea(); if (area == null) { - Captions.NOT_IN_PLOT_WORLD.send(player); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } PlotCluster cluster = area.getCluster(player.getLocation()); if (cluster == null) { - MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER); + player.sendMessage(TranslatableCaption.of("errors.not_in_cluster")); return false; } if (!cluster.hasHelperRights(player.getUUID())) { if (!Permissions .hasPermission(player, Captions.PERMISSION_CLUSTER_SETHOME_OTHER)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_CLUSTER_SETHOME_OTHER); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_CLUSTER_SETHOME_OTHER.getTranslated()) + ); return false; } } @@ -696,9 +813,9 @@ public class Cluster extends SubCommand { cluster.settings.setPosition(blockloc); DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ()); - return MainUtil.sendMessage(player, Captions.POSITION_SET); + player.sendMessage(TranslatableCaption.of("position.position_set")); } - MainUtil.sendMessage(player, Captions.CLUSTER_AVAILABLE_ARGS); + player.sendMessage(TranslatableCaption.of("cluster.cluster_available_args")); return false; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Condense.java b/Core/src/main/java/com/plotsquared/core/command/Condense.java index 31fe79a2c..f76469376 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Condense.java +++ b/Core/src/main/java/com/plotsquared/core/command/Condense.java @@ -26,6 +26,7 @@ package com.plotsquared.core.command; import com.google.inject.Inject; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -35,6 +36,7 @@ import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskTime; +import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -67,27 +69,32 @@ public class Condense extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length != 2 && args.length != 3) { - sendUsage(player); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot condense [radius]") + ); return false; } PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]); if (area == null || !this.worldUtil.isWorld(area.getWorldName())) { - MainUtil.sendMessage(player, "INVALID AREA"); + player.sendMessage(TranslatableCaption.of("invalid.invalid_area")); return false; } switch (args[1].toLowerCase()) { case "start": { if (args.length == 2) { - MainUtil.sendMessage(player, - "/plot condense " + area.toString() + " start "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot condense" + area.toString() + " start ") + ); return false; } if (Condense.TASK) { - MainUtil.sendMessage(player, "TASK ALREADY STARTED"); + player.sendMessage(TranslatableCaption.of("condense.task_already_started")); return false; } if (!MathMan.isInteger(args[2])) { - MainUtil.sendMessage(player, "INVALID RADIUS"); + player.sendMessage(TranslatableCaption.of("condense.invalid_radius")); return false; } int radius = Integer.parseInt(args[2]); @@ -131,7 +138,7 @@ public class Condense extends SubCommand { int size = allPlots.size(); int minimumRadius = (int) Math.ceil(Math.sqrt(size) / 2 + 1); if (radius < minimumRadius) { - MainUtil.sendMessage(player, "RADIUS TOO SMALL"); + player.sendMessage(TranslatableCaption.of("condense.radius_too_small")); return false; } List toMove = new ArrayList<>(getPlots(allPlots, radius)); @@ -145,20 +152,19 @@ public class Condense extends SubCommand { start = start.getNextId(); } if (free.isEmpty() || toMove.isEmpty()) { - MainUtil.sendMessage(player, "NO FREE PLOTS FOUND"); + player.sendMessage(TranslatableCaption.of("condense.no_free_plots_found")); return false; } - MainUtil.sendMessage(player, "TASK STARTED..."); + player.sendMessage(TranslatableCaption.of("condense.task_started")); Condense.TASK = true; Runnable run = new Runnable() { @Override public void run() { if (!Condense.TASK) { - MainUtil.sendMessage(player, "TASK CANCELLED."); + player.sendMessage(TranslatableCaption.of("condense.task_cancelled")); } if (allPlots.isEmpty()) { Condense.TASK = false; - MainUtil.sendMessage(player, - "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK."); + player.sendMessage(TranslatableCaption.of("condense.task_complete")); return; } final Runnable task = this; @@ -175,8 +181,11 @@ public class Condense extends SubCommand { try { result.set(origin.move(possible, () -> { if (result.get()) { - MainUtil.sendMessage(player, - "Moving: " + origin + " -> " + possible); + player.sendMessage( + TranslatableCaption.of("condense.moving"), + Template.of("origin", String.valueOf(origin)), + Template.of("possible", String.valueOf(possible)) + ); TaskManager.runTaskLater(task, TaskTime.ticks(1L)); } }, false).get()); @@ -189,11 +198,14 @@ public class Condense extends SubCommand { } if (free.isEmpty()) { Condense.TASK = false; - MainUtil.sendMessage(player, "TASK FAILED. NO FREE PLOTS FOUND!"); + player.sendMessage(TranslatableCaption.of("condense.task_failed")); return; } if (i >= free.size()) { - MainUtil.sendMessage(player, "SKIPPING COMPLEX PLOT: " + origin); + player.sendMessage( + TranslatableCaption.of("condense.skipping"), + Template.of("plot", String.valueOf(origin)) + ); } } }; @@ -202,20 +214,22 @@ public class Condense extends SubCommand { } case "stop": if (!Condense.TASK) { - MainUtil.sendMessage(player, "TASK ALREADY STOPPED"); + player.sendMessage(TranslatableCaption.of("condense.task_already_stopped")); return false; } Condense.TASK = false; - MainUtil.sendMessage(player, "TASK STOPPED"); + player.sendMessage(TranslatableCaption.of("condense.task_stopped")); return true; case "info": if (args.length == 2) { - MainUtil.sendMessage(player, - "/plot condense " + area.toString() + " info "); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot condense " + area.toString() + " info ") + ); return false; } if (!MathMan.isInteger(args[2])) { - MainUtil.sendMessage(player, "INVALID RADIUS"); + player.sendMessage(TranslatableCaption.of("condense.invalid_radius")); return false; } int radius = Integer.parseInt(args[2]); @@ -223,24 +237,37 @@ public class Condense extends SubCommand { int size = plots.size(); int minimumRadius = (int) Math.ceil(Math.sqrt(size) / 2 + 1); if (radius < minimumRadius) { - MainUtil.sendMessage(player, "RADIUS TOO SMALL"); + player.sendMessage(TranslatableCaption.of("condense.radius_too_small")); return false; } int maxMove = getPlots(plots, minimumRadius).size(); int userMove = getPlots(plots, radius).size(); - MainUtil.sendMessage(player, "=== DEFAULT EVAL ==="); - MainUtil.sendMessage(player, "MINIMUM RADIUS: " + minimumRadius); - MainUtil.sendMessage(player, "MAXIMUM MOVES: " + maxMove); - MainUtil.sendMessage(player, "=== INPUT EVAL ==="); - MainUtil.sendMessage(player, "INPUT RADIUS: " + radius); - MainUtil.sendMessage(player, "ESTIMATED MOVES: " + userMove); - MainUtil.sendMessage(player, - "ESTIMATED TIME: No idea, times will drastically change based on the system performance and load"); - MainUtil.sendMessage(player, "&e - Radius is measured in plot width"); + player.sendMessage(TranslatableCaption.of("condense.default_eval")); + player.sendMessage( + TranslatableCaption.of("condense.minimum_radius"), + Template.of("minimumRadius", String.valueOf(minimumRadius)) + ); + player.sendMessage( + TranslatableCaption.of("condense.minimum_radius"), + Template.of("maxMove", String.valueOf(maxMove)) + ); + player.sendMessage(TranslatableCaption.of("condense.input_eval")); + player.sendMessage( + TranslatableCaption.of("condense.input_radius"), + Template.of("radius", String.valueOf(radius)) + ); + player.sendMessage( + TranslatableCaption.of("condense.estimated_moves"), + Template.of("userMove", String.valueOf(userMove)) + ); + player.sendMessage(TranslatableCaption.of("condense.eta")); + player.sendMessage(TranslatableCaption.of("condense.radius_measured")); return true; } - MainUtil.sendMessage(player, - "/plot condense " + area.getWorldName() + " [radius]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value","/plot condense " + area.getWorldName() + " [radius]") + ); return false; } 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 8bf36d331..32b6344a5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Continue.java +++ b/Core/src/main/java/com/plotsquared/core/command/Continue.java @@ -62,22 +62,27 @@ public class Continue extends SubCommand { } if (!plot.isOwner(player.getUUID()) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_CONTINUE)) { - MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.NO_PLOT_PERMS.getTranslated()) + ); return false; } if (!DoneFlag.isDone(plot)) { - MainUtil.sendMessage(player, Captions.DONE_NOT_DONE); + player.sendMessage(TranslatableCaption.of("done.done_not_done")); return false; } int size = plot.getConnectedPlots().size(); if (Settings.Done.COUNTS_TOWARDS_LIMIT && (player.getAllowedPlots() < player.getPlotCount() + size)) { - MainUtil.sendMessage(player, Captions.NO_PERMISSION, - Captions.PERMISSION_ADMIN_COMMAND_CONTINUE); + player.sendMessage( + TranslatableCaption.of("permission.no_permission"), + Template.of("node", Captions.PERMISSION_ADMIN_COMMAND_CONTINUE.getTranslated()) + ); return false; } if (plot.getRunning() > 0) { - MainUtil.sendMessage(player, Captions.WAIT_FOR_TIMER); + player.sendMessage(TranslatableCaption.of("errors.wait_for_timer")); return false; } PlotFlag plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class); @@ -90,7 +95,7 @@ public class Continue extends SubCommand { return true; } plot.removeFlag(event.getFlag()); - MainUtil.sendMessage(player, Captions.DONE_REMOVED); + player.sendMessage(TranslatableCaption.of("done.done_removed")); return true; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Copy.java b/Core/src/main/java/com/plotsquared/core/command/Copy.java index 22d448e70..eecf4153e 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Copy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Copy.java @@ -31,6 +31,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.Permissions; +import net.kyori.adventure.text.minimessage.Template; @CommandDeclaration(command = "copy", permission = "plots.copy", @@ -50,11 +51,14 @@ public class Copy extends SubCommand { } if (!plot1.isOwner(player.getUUID()) && !Permissions .hasPermission(player, Captions.PERMISSION_ADMIN.getTranslated())) { - MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS); + player.sendMessage(TranslatableCaption.of("permission.no_plot_perms")); return false; } if (args.length != 1) { - sendUsage(player); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot copy ") + ); return false; } Plot plot2 = Plot.getPlotFromString(player, args[0], true); @@ -62,18 +66,21 @@ public class Copy extends SubCommand { return false; } if (plot1.equals(plot2)) { - MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID); - sendUsage(player); + player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id")); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot copy ") + ); return false; } if (!plot1.getArea().isCompatible(plot2.getArea())) { - Captions.PLOTWORLD_INCOMPATIBLE.send(player); + player.sendMessage(TranslatableCaption.of("errors.plotworld_incompatible")); return false; } - if (plot1.copy(plot2, () -> MainUtil.sendMessage(player, Captions.COPY_SUCCESS))) { + if (plot1.copy(plot2, () -> player.sendMessage(TranslatableCaption.of("move.copy_success")))) { return true; } else { - MainUtil.sendMessage(player, Captions.REQUIRES_UNOWNED); + player.sendMessage(TranslatableCaption.of("move.requires_unowned")); return false; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java index cbae625c8..0ab4d5a18 100644 --- a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java +++ b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java @@ -59,10 +59,10 @@ public class CreateRoadSchematic extends SubCommand { return false; } if (!(location.getPlotArea() instanceof HybridPlotWorld)) { - return sendMessage(player, Captions.NOT_IN_PLOT_WORLD); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } this.hybridUtils.setupRoadSchematic(plot); - MainUtil.sendMessage(player, Captions.SCHEMATIC_ROAD_CREATED); + player.sendMessage(TranslatableCaption.of("schematics.schematic_road_created")); return true; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index 6de83b92b..d96ed84c6 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -27,6 +27,8 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.caption.StaticCaption; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.Database; @@ -45,6 +47,8 @@ import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.FileUtils; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; +import net.kyori.adventure.text.minimessage.Template; +import sun.net.TransferProtocolClient; import javax.annotation.Nonnull; import java.io.File; @@ -84,14 +88,13 @@ public class DatabaseCommand extends SubCommand { TaskManager.runTaskAsync(() -> { try { ArrayList ps = new ArrayList<>(plots); - MainUtil.sendMessage(player, "&6Starting..."); + player.sendMessage(TranslatableCaption.of("database.starting_conversion")); manager.createPlotsAndData(ps, () -> { - MainUtil.sendMessage(player, "&6Database conversion finished!"); + player.sendMessage(TranslatableCaption.of("database.conversion_done")); manager.close(); }); } catch (Exception e) { - MainUtil - .sendMessage(player, "Failed to insert plot objects, see stacktrace for info"); + player.sendMessage(TranslatableCaption.of("database.conversion_failed")); e.printStackTrace(); } }); @@ -99,7 +102,10 @@ public class DatabaseCommand extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length < 1) { - sendUsage(player); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot database [area] ") + ); return false; } List plots; @@ -111,8 +117,11 @@ public class DatabaseCommand extends SubCommand { plots = PlotSquared.get().sortPlotsByTemp(PlotQuery.newQuery().allPlots().asList()); } if (args.length < 1) { - sendUsage(player); - MainUtil.sendMessage(player, "[arg] indicates an optional argument"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot database [area] ") + ); + player.sendMessage(TranslatableCaption.of("database.arg")); return false; } try { @@ -121,17 +130,22 @@ public class DatabaseCommand extends SubCommand { switch (args[0].toLowerCase()) { case "import": if (args.length < 2) { - MainUtil - .sendMessage(player, "/plot database import [prefix]"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot database import [prefix]") + ); return false; } File file = FileUtils.getFile(PlotSquared.platform().getDirectory(), args[1].endsWith(".db") ? args[1] : args[1] + ".db"); if (!file.exists()) { - MainUtil.sendMessage(player, "&6Database does not exist: " + file); + player.sendMessage( + TranslatableCaption.of("database.does_not_exist"), + Template.of("value", String.valueOf(file)) + ); return false; } - MainUtil.sendMessage(player, "&6Starting..."); + player.sendMessage(TranslatableCaption.of("database.starting_conversion")); implementation = new SQLite(file); SQLManager manager = new SQLManager(implementation, args.length == 3 ? args[2] : "", this.eventDispatcher, this.plotListener, this.worldConfiguration); @@ -164,8 +178,7 @@ public class DatabaseCommand extends SubCommand { continue; } } - MainUtil.sendMessage(player, - "Skipping duplicate plot: " + plot + " | id=" + plot.temp); + player.sendMessage(StaticCaption.of("Skipping duplicate plot: " + plot + " | id=" + plot.temp)); continue; } plot.setArea(pa); @@ -178,12 +191,11 @@ public class DatabaseCommand extends SubCommand { } } DBFunc.createPlotsAndData(plots, - () -> MainUtil.sendMessage(player, "&6Database conversion finished!")); + () -> player.sendMessage(TranslatableCaption.of("database.conversion_done"))); return true; case "mysql": if (args.length < 6) { - return MainUtil.sendMessage(player, - "/plot database mysql [host] [port] [username] [password] [database] {prefix}"); + player.sendMessage(StaticCaption.of("/plot database mysql [host] [port] [username] [password] [database] {prefix}")); } String host = args[1]; String port = args[2]; @@ -197,36 +209,33 @@ public class DatabaseCommand extends SubCommand { break; case "sqlite": if (args.length < 2) { - return MainUtil.sendMessage(player, "/plot database sqlite [file]"); + player.sendMessage(StaticCaption.of("/plot database sqlite [file]")); } File sqliteFile = FileUtils.getFile(PlotSquared.platform().getDirectory(), args[1] + ".db"); implementation = new SQLite(sqliteFile); break; default: - return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]"); + player.sendMessage(StaticCaption.of("/plot database [sqlite/mysql]")); } try { SQLManager manager = new SQLManager(implementation, prefix, this.eventDispatcher, this.plotListener, this.worldConfiguration); DatabaseCommand.insertPlots(manager, plots, player); return true; } catch (ClassNotFoundException | SQLException e) { - MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info"); - MainUtil.sendMessage(player, - "&d==== Here is an ugly stacktrace, if you are interested in those things ==="); + player.sendMessage(TranslatableCaption.of("database.failed_to_save_plots")); + player.sendMessage(StaticCaption.of(("=== Begin of stacktrace. ==="))); e.printStackTrace(); - MainUtil.sendMessage(player, "&d==== End of stacktrace ===="); - MainUtil - .sendMessage(player, "$1Please make sure you are using the correct arguments!"); + player.sendMessage(StaticCaption.of(("=== End of stacktrace. ==="))); + player.sendMessage(TranslatableCaption.of("database.invalid_args")); return false; } } catch (ClassNotFoundException | SQLException e) { - MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info"); - MainUtil.sendMessage(player, - "&d==== Here is an ugly stacktrace, if you are interested in those things ==="); + player.sendMessage(TranslatableCaption.of("database.failed_to_open")); + player.sendMessage(StaticCaption.of(("=== Begin of stacktrace. ==="))); e.printStackTrace(); - MainUtil.sendMessage(player, "&d==== End of stacktrace ===="); - MainUtil.sendMessage(player, "$1Please make sure you are using the correct arguments!"); + player.sendMessage(StaticCaption.of(("=== End of stacktrace. ==="))); + player.sendMessage(TranslatableCaption.of("database.invalid_args")); return false; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java b/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java index d424b809f..28c9f1ccc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.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 java.util.ArrayList; @@ -46,10 +47,10 @@ public class DebugAllowUnsafe extends SubCommand { if (unsafeAllowed.contains(player.getUUID())) { unsafeAllowed.remove(player.getUUID()); - sendMessage(player, Captions.DEBUGALLOWUNSAFE_OFF); + player.sendMessage(TranslatableCaption.of("unsafe.debugallowunsafe_off")); } else { unsafeAllowed.add(player.getUUID()); - sendMessage(player, Captions.DEBUGALLOWUNSAFE_ON); + player.sendMessage(TranslatableCaption.of("unsafe.debugallowunsafe_on")); } return true; } 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 4808ec8e2..8ae7e2f99 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -27,9 +27,11 @@ package com.plotsquared.core.command; import com.google.common.io.Files; import com.google.inject.Inject; +import com.google.inject.internal.cglib.transform.$ClassTransformer; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.events.PlotFlagRemoveEvent; @@ -63,6 +65,8 @@ import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.world.block.BlockState; +import javafx.collections.transformation.TransformationList; +import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,7 +96,6 @@ public class DebugExec extends SubCommand { private static final Logger logger = LoggerFactory.getLogger("P2/" + DebugExec.class.getSimpleName()); - private final PlotAreaManager plotAreaManager; private final EventDispatcher eventDispatcher; private final WorldEdit worldEdit; @@ -162,7 +165,6 @@ public class DebugExec extends SubCommand { this.scope = context.getBindings(ScriptContext.ENGINE_SCOPE); // stuff - this.scope.put("MainUtil", new MainUtil()); this.scope.put("Settings", new Settings()); this.scope.put("StringMan", new StringMan()); this.scope.put("MathMan", new MathMan()); @@ -219,42 +221,45 @@ public class DebugExec extends SubCommand { } PlotAnalysis analysis = plot.getComplexity(null); if (analysis != null) { - MainUtil.sendMessage(player, "Changes/column: " + analysis.changes / 1.0); + player.sendMessage( + TranslatableCaption.of("debugexec.changes_column"), + Template.of("value", analysis.changes / 1.0) + ); return true; } - MainUtil.sendMessage(player, "$1Starting task..."); + player.sendMessage(TranslatableCaption.of("debugexec.starting_task")); this.hybridUtils.analyzePlot(plot, new RunnableVal() { @Override public void run(PlotAnalysis value) { - MainUtil.sendMessage(player, - "$1Done: $2Use $3/plot debugexec analyze$2 for more information"); + player.sendMessage(StaticCaption.of("&6Done: &7Use &6/plot debugexec analyze &7for more information.")); } }); return true; } case "calibrate-analysis": if (args.length != 2) { - MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot debugexec analyze "); - MainUtil.sendMessage(player, - "$1 $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating " - + "it)"); + player.sendMessage( + TranslatableCaption.of("commandconfig.command_syntax"), + Template.of("value", "/plot debugexec analyze ") + ); + player.sendMessage(TranslatableCaption.of("debugexec.threshold_default")); return false; } double threshold; try { threshold = Integer.parseInt(args[1]) / 100d; } catch (NumberFormatException ignored) { - MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]); - MainUtil.sendMessage(player, - "$1 $2= $1The percentage of plots you want to clear as a number between 0 - 100"); + player.sendMessage( + TranslatableCaption.of("debugexec.invalid_threshold"), + Template.of("value", args[1]) + ); + player.sendMessage(TranslatableCaption.of("debugexec.threshold_default_double")); return false; } - PlotAnalysis.calcOptimalModifiers(() -> MainUtil - .sendMessage(player, "$1Thank you for calibrating plot expiry"), threshold); + PlotAnalysis.calcOptimalModifiers(() -> player.sendMessage(TranslatableCaption.of("debugexec.calibration_done")), threshold); return true; case "stop-expire": if (ExpireManager.IMP == null || !ExpireManager.IMP.cancelTask()) { - return MainUtil.sendMessage(player, "Task already halted"); + player.sendMessage(TranslatableCaption.of("debugexec.task_halted")); } return MainUtil.sendMessage(player, "Cancelled task."); case "remove-flag": diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index f8c6adc80..1703d203c 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -6,10 +6,10 @@ "move.move_success": "Successfully moved plot.", "move.move_merged": "Merged plots may not be moved. Please unmerge the plot before performing the move.", "move.copy_success": "Successfully copied plot.", - "move.reqiores_unowned": "The location specified is already occupied.", + "move.requires_unowned": "The location specified is already occupied.", "debug.requires_unmerged": "The plot cannot be merged.", - "debug.degub_header": " Debug Information\n", + "debug.debug_header": " Debug Information\n", "debug.debug_section": ">> &l", "debug.debug_line": ">> : \n", "debug.plot_debug": "[Plot Debug] (): ", @@ -31,13 +31,16 @@ "cluster.cluster_available_args": "The following sub commands are available: list, create, delete, resize, invite, kick, leave, members, info, tp, sethome", "cluster.cluster_list_heading": "There are clusters in this world.", "cluster.cluster_list_element": " - \n", + "cluster.cluster_list_element_owner": " - \n", + "cluster.cluster_list_element_helpers": " - \n", + "cluster.cluster_list_element_invited": " - \n", "cluster.cluster_intersection": "The proposed area overlaps with: ", "cluster.cluster_outside": "The proposed area is outside the plot area: ", "cluster.cluster_added": "Successfully created the cluster.", "cluster.cluster_deleted": "Successfully deleted the cluster.", "cluster.cluster_resized": "Successfully resized the cluster.", - "cluter.cluster_added_user": "Successfully added user to the cluster.", - "cluster.cannot_kick_player": "You cannot kick that player.", + "cluster.cluster_added_user": "Successfully added user to the cluster.", + "cluster.cannot_kick_player": "You cannot kick that player: ", "cluster.cluster_invited": "You have been invited to the following cluster: .", "cluster.cluster_removed": "You have been removed from cluster: .", "cluster.cluster_kicked_user": "Successfully kicked the user from the cluster.", @@ -152,6 +155,7 @@ "schematics.schematic_too_large": "The plot is too large for this action!", "schematics.schematic_missing_arg": "You need to specify an argument. Possible values: save, paste , exportall, list", "schematics.schematic_invalid": "That is not a valid schematic. Reason: .", + "schematics.schematic_invalid_named": " is not a valid schematic. Reason: .", "schematics.schematic_paste_merged": "Schematics cannot be pasted onto merged plots. Please unmerge the plot before performing the paste.", "schematics.schematic_paste_failed": "Failed to paste the schematic.", "schematics.schematic_paste_success": "The schematic pasted successfully.", @@ -211,8 +215,9 @@ "commandconfig.not_valid_subcommand": "That is not a valid subcommand.", "commandconfig.did_you_mean": "Did you mean: ", "commandconfig.subcommand_set_options_header": "Possible Values: ", - "commandconfig.command_syntax": "Usage: ", - "commandconfig.flag_tutorial_usage": "Have an admin set the flag: ", + "commandconfig.command_syntax": "Usage: ", + "commandconfig.command_syntax_extended": "Usage: ", + "commandconfig.flag_tutorial_usage": "Have an admin set the flag: ", "invalid.component_illegal_block": "You are not allowed to generate a component containing the block ", "invalid.not_valid_block": "That's not a valid block: ", @@ -223,7 +228,47 @@ "invalid.number_not_in_range": "That's not a valid number within the range: (, )", "invalid.number_not_positive": "That's not a positive number: ", "invalid.not_a_number": " is not a valid number.", - + + "condense.invalid_area": "Invalid area.", + "condense.task_already_started": "Task already started.", + "condense.invalid_radius": "Invalid radius.", + "condense.radius_too_small": "Radius too small.", + "condense.no_free_plots_found": "No free plots found.", + "condense.task_started": "Task started...", + "condense.task_cancelled": "Task cancelled.", + "condense.task_complete": "Task complete. Please verify that no new plots have been claimed during the task.", + "condense.moving": "Moving: -> ", + "condense.task_failed": "Task failed. No free plots found.", + "condense.skipping": "Skipping complex plot: .", + "condense.task_already_stopped": "Task already stopped.", + "condense.task_stopped": "Task already stopped.", + "condense.default_eval": "=== DEFAULT EVAL ===", + "condense.minimum_radius": "", + "condense.maximum_moved": "Maximum moved: ", + "condense.input_eval": "=== INPUT EVAL ===", + "condense.input_radius": "Input radius: ", + "condense.estimated_moves": "Estimated moves: ", + "condense.eta": "Estimated time: No idea, times will drastically change based on the system performance and load.", + "condense.radius_measured": " - Radius is measured in plot width.", + + "database.starting_conversion": "Starting...", + "database.conversion_done": "Database conversion finished.", + "database.conversion_failed": "Failed to insert plot objects, see stacktrace for info.", + "database.arg": "[arg] indicates an optional argument.", + "database.does_not_exist": "Database does not exist: .", + "database.failed_to_save_plots": "Failed to save plots, read stacktrace for info.", + "database.invalid_args": "Please make sure you are using the correct arguments.", + "database.failed_to_open": "Failed to open connection, read stacktrace for info.", + + "debugexec.changes_column": "Changes/column: ", + "debugexec.starting_task": "Starting task...", + "debugexec.threshold_default": "`threshold` = The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it.", + "debugexec.invalid_threshold": "Invalid threshold: ", + "debugexec.threshold_default_double": "$1 $2= $1The percentage of plots you want to clear as a number between 0 - 100.", + "debugexec.calibration_done": "Thank you for calibrating plot expiry.", + "debugexec.task_halted": "Task already halted.", + + "errors.invalid_player": "Player not found: .", "errors.invalid_player_offline": "The player must be online: .", @@ -243,6 +288,7 @@ "errors.player_no_plots": "That player does not own any plots.", "errors.wait_for_timer": "A set block timer is bound to either the current plot or you. Please wait for it to finish.", "errors.tile_entity_cap_reached": "The total number of tile entities in this chunk may not exceed .", + "error.plot_size": "Error: size <= 0.", "debugpaste.debug_report_created": "Uploaded a full debug to: ", @@ -279,10 +325,10 @@ "info.everyone": "Everyone", "info.plot_unowned": "The current plot must have an owner to perform this action.", "info.plot_info_unclaimed": "Plot is not yet claimed.", - "info.plot_info_header": "--------- INFO ---------", + "info.plot_info_header": "--------- INFO ---------", "info.plot_info_hidden": "You cannot view the information about this plot.", "info.plot_info_format": "ID: \nArea: \nAlias:\nOwner:\nBiome: \nCan Build: \nRating: \nSeen: \nTrusted:\nMembers:\nDenied:\nFlags:\nDescription: ", - "info.plot_info_footer": "--------- INFO ---------", + "info.plot_info_footer": "--------- INFO ---------", "info.plot_info_trusted": "Trusted:", "info.plot_info_members": "Members:", "info.plot_info_denied": "Denied:", @@ -299,7 +345,7 @@ "info.plot_flag_list": ": ", "info.plot_no_description": "No description set.", "info.info_syntax_console": "/plot info X;Z", - "info.plot_caps_header": "--------- CAPS ---------", + "info.plot_caps_header": "--------- CAPS ---------", "info.plot_caps_format": "- Cap Type: | Status: / (%)", "working.generating_component": "Started generating component from your settings.", @@ -400,6 +446,10 @@ "single.single_area_failed_to_save": "Error! Failed to save the area schematic.", "single.single_area_could_not_make_directories": "Error! Failed to create the schematic directory.", "single.single_area_created": "The area was created successfully!", + "single.get_position": "Go to the first corner and use: to create position 1.", + "single.delete_world_region": "Stop the server and delete: /region.", + "single.regeneration_complete": "Regeneration complete.", + "single.worldcreation_location": "World creation settings may be stored in multiple locations:\n - bukkit.yml in your server's root folder.\n - PlotSquared's settings.yml\n - Hyperverse's worlds.yml (or any world management plugin)\n - Stop the server and delete it from these locations.", "legacyconfig.legacy_config_found": "A legacy configuration file was detected. Conversion will be attempted.", "legacyconfig.legacy_config_backup": "A copy of worlds.yml has been saved in the file worlds.yml.old.", @@ -523,7 +573,7 @@ "flags.flag_description_keep_inventory": "Prevents players from dropping their items when they die inside of the plot.", "flags.flag_description_prevent_creative_copy": "Prevents people from copying item NBT data in the plot unless they're added as members.", - "flags.flag_error_boolean": "Flag value must be a boolean (true|false)", + "flags.flag_error_boolean": "Flag value must be a boolean (true | false)", "flags.flag_error_enum": "Must be one of: ", "flags.flag_error_gamemode": "Flag value must be a gamemode: 'survival', 'creative', 'adventure' or 'spectator.", "flags.flag_error_integer": "Flag value must be a whole number.", @@ -537,5 +587,31 @@ "flags.flag_error_string": "Flag value must be alphanumeric. Some special characters are allowed.", "flags.flag_error_stringlist": "Flag value must be a string list.", "flags.flag_error_weather": "Flag must be a weather: 'rain' or 'sun'.", - "flags.flag_error_music": "Flag value must be a valid music disc ID." + "flags.flag_error_music": "Flag value must be a valid music disc ID.", + + "commands.description.add": "Allow a user to build in a plot while the plot owner is online.", + "commands.description.alias": "Set the plot alias.", + "commands.description.area": "Create a new plot area.", + "commands.description.auto": "Claim the nearest plot.", + "commands.description.backup": "Manage plot backups.", + "commands.description.backup.save": "Create a plot backup.", + "commands.description.backup.list": "List available plot backups.", + "commands.description.backup.load": "Restore a plot backup", + "commands.description.biome": "Set the plot biome.", + "commands.description.buy": "Buy the plot you are standing on.", + "commands.description.caps": "Show plot entity caps.", + "commands.description.chat": "Toggles plot chat on or off.", + "commands.description.claim": "Claim the current plot you are standing on.", + "commands.description.clear": "Clear the plot you stand on.", + "commands.description.cluster": "Manage a plot cluster.", + "commands.description.comment": "Comment on a plot.", + "commands.description.condense": "Condense a plotworld.", + "commands.description.confirm": "Confirm an action.", + "commands.description.done": "Continue a plot that was previously marked as done.", + "commands.description.copy": "Copy a plot.", + "commands.description.createroadschematic": "Add a road schematic to your world using the roads around your current plot.", + "commands.description.database": "Convert/Backup Storage.", + "commands.description.debug": "Show debug information.", + "commands.description.debugallowunsafe": "Allow unsafe actions until toggled off.", + "commands.description.debugexec": "Multi-purpose debug command." }