From c31c4b428698805c88126a3bfe5495b14c80038d Mon Sep 17 00:00:00 2001 From: N0tMyFaultOG Date: Fri, 7 Aug 2020 18:52:45 +0200 Subject: [PATCH] More work --- .../plotsquared/bukkit/BukkitPlatform.java | 3 +- .../bukkit/listener/PaperListener.java | 8 +++- .../bukkit/listener/PlayerEvents.java | 41 ++++++++++--------- .../bukkit/player/BukkitPlayer.java | 6 +-- .../bukkit/schematic/StateWrapper.java | 1 - .../core/util/helpmenu/HelpObject.java | 1 - Core/src/main/resources/lang/messages_en.json | 6 +++ 7 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 5a1d7c8ef..0c74939a3 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -65,7 +65,6 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.command.WE_Anywhere; import com.plotsquared.core.components.ComponentPresetManager; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.caption.ChatFormatter; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; @@ -276,7 +275,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass; if (!plotSquared.getConfigurationVersion().equalsIgnoreCase("v5")) { // Perform upgrade if (DBFunc.dbManager.convertFlags()) { - log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!"); + logger.info("[P2] Flags were converted successfully!"); // Update the config version try { plotSquared.setConfigurationVersion("v5"); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index e0bbe1ec6..bc3cfcaae 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -36,14 +36,15 @@ import com.google.inject.Inject; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.core.command.Command; import com.plotsquared.core.command.MainCommand; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.plot.world.PlotAreaManager; +import net.kyori.adventure.text.minimessage.Template; import org.bukkit.Chunk; import org.bukkit.block.Block; import org.bukkit.block.TileState; @@ -287,7 +288,10 @@ public class PaperListener implements Listener { final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length; if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) { final PlotPlayer plotPlayer = BukkitUtil.adapt(event.getPlayer()); - Captions.TILE_ENTITY_CAP_REACHED.send(plotPlayer, Settings.Chunk_Processor.MAX_TILES); + plotPlayer.sendMessage( + TranslatableCaption.of("errors.tile_entity_cap_reached"), + Template.of("", String.valueOf(Settings.Chunk_Processor.MAX_TILES)) + ); event.setCancelled(true); event.setBuild(false); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 9c698afe6..d3ab888a0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -32,6 +32,7 @@ import com.plotsquared.bukkit.player.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.UpdateUtility; import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.TranslatableCaption; @@ -706,19 +707,17 @@ import java.util.regex.Pattern; this.eventDispatcher.doJoinTask(pp); }, TaskTime.seconds(1L)); - if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated()) - && Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium() + if (pp.hasPermission(Permission.PERMISSION_ADMIN_UPDATE_NOTIFICATION.toString()) + && Settings.Enabled_Components.UPDATE_NOTIFICATIONS + && PremiumVerification.isPremium() && UpdateUtility.hasUpdate) { - new PlotMessage("-----------------------------------").send(pp); - new PlotMessage(Captions.PREFIX + "There appears to be a PlotSquared update available!") - .color("$1").send(pp); - new PlotMessage( - Captions.PREFIX + "&6You are running version " + UpdateUtility.internalVersion - .versionString() + ", &6latest version is " + UpdateUtility.spigotVersion) - .color("$1").send(pp); - new PlotMessage(Captions.PREFIX + "Download at:").color("$1").send(pp); - player.sendMessage(" https://www.spigotmc.org/resources/77506/updates"); - new PlotMessage("-----------------------------------").send(pp); + Caption upperBoundary = TranslatableCaption.of("update.update_boundary"); + Caption updateNotification = TranslatableCaption.of("update.update_notification"); + Template internalVersion = Template.of("p2version", String.valueOf(UpdateUtility.internalVersion.versionString())); + Template spigotVersion = Template.of("spigotversion", UpdateUtility.spigotVersion); + Template downloadUrl = Template.of("downloadurl", "https://www.spigotmc.org/resources/77506/updates"); + Caption lowerBoundary = TranslatableCaption.of("update.update_boundary"); + pp.sendMessage(upperBoundary, updateNotification, internalVersion, spigotVersion, downloadUrl, lowerBoundary); } } @@ -1025,10 +1024,11 @@ import java.util.regex.Pattern; return; } event.setCancelled(true); - String message = event.getMessage(); - String format = Captions.PLOT_CHAT_FORMAT.getTranslated(); - String sender = event.getPlayer().getDisplayName(); - PlotId id = plot.getId(); + Caption msg = TranslatableCaption.of("chat.plot_chat_format"); + Template msgTemplate = Template.of("msg", event.getMessage()); + Template plotTemplate = Template.of("plot_id", String.valueOf(plot.getId())); + Template senderTemplate = Template.of("sender", event.getPlayer().getDisplayName()); + plotPlayer.sendMessage(msg, msgTemplate, plotTemplate, senderTemplate); Set recipients = event.getRecipients(); recipients.clear(); Set spies = new HashSet<>(); @@ -1052,11 +1052,12 @@ import java.util.regex.Pattern; receiver.sendMessage(full); } if (!spies.isEmpty()) { - String spyMessage = Captions.PLOT_CHAT_SPY_FORMAT.getTranslated() - .replace("%plot_id%", id.getX() + ";" + id.getY()).replace("%sender%", sender) - .replace("%msg%", message); + Caption spymsg = TranslatableCaption.of("chat.plot_chat_spy_format"); + Template plotidTemplate = Template.of("plot_id", id.getX() + ";" + id.getY()); + Template spysenderTemplate = Template.of("sender", sender); + Template spymessageTemplate = Template.of("msg", message); for (Player player : spies) { - player.sendMessage(spyMessage); + plotPlayer.sendMessage(spymsg, plotidTemplate, spysenderTemplate, spymessageTemplate); } } // TODO: Re-implement diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 9a58b8087..86ccc7fc0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -162,15 +162,15 @@ public class BukkitPlayer extends PlotPlayer { @Override @Nonnegative public int hasPermissionRange(@Nonnull final String stub, @Nonnegative final int range) { - if (hasPermission(Permission.PERMISSION_ADMIN.getTranslated())) { + if (hasPermission(Permission.PERMISSION_ADMIN.toString())) { return Integer.MAX_VALUE; } final String[] nodes = stub.split("\\."); final StringBuilder n = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { n.append(nodes[i]).append("."); - if (!stub.equals(n + Permission.PERMISSION_STAR.getTranslated())) { - if (hasPermission(n + Permission.PERMISSION_STAR.getTranslated())) { + if (!stub.equals(n + Permission.PERMISSION_STAR.toString())) { + if (hasPermission(n + Permission.PERMISSION_STAR.toString())) { return Integer.MAX_VALUE; } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java index 3b62aa6a8..123e61310 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java @@ -26,7 +26,6 @@ package com.plotsquared.bukkit.schematic; import com.plotsquared.bukkit.util.BukkitUtil; -import com.plotsquared.core.configuration.Captions; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; diff --git a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java index f33a1f519..19913c4ae 100644 --- a/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java +++ b/Core/src/main/java/com/plotsquared/core/util/helpmenu/HelpObject.java @@ -27,7 +27,6 @@ package com.plotsquared.core.util.helpmenu; import com.plotsquared.core.command.Argument; import com.plotsquared.core.command.Command; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.util.StringMan; public class HelpObject { diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index d45552776..e933c2067 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -502,6 +502,12 @@ "legacyconfig.legacy_config_replaced": " has been replaced with ", "legacyconfig.legacy_config_done": "The conversion has finished. PlotSquared will now be disabled and the new configuration file will be used at next startup. Please review the new worlds.yml file. Please note that schematics will not be converted, as we are now using WorldEdit to handle schematics. You need to re-generate the schematics.", "legacyconfig.legacy_config_conversion_failed": "Failed to convert the legacy configuration file. See stack trace for information.", + + "update.update_boundary": "-----------------------------------", + "update.update_notification": "There appears to be a PlotSquared update available!", + "update.internal_version": "You are running version ", + "update.spigot_version": "Latest version is ", + "update.download": "Download the update at: >", "flag.flag_key": "Key: ", "flag.flag_desc": "Desc: ",