From ec9194180bcc03913818d096af0e651e765fd861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Wed, 25 May 2022 22:35:39 +0300 Subject: [PATCH] Update 2.8.1 Fix logger messages on SpongeForge. --- .../sawfowl/commandsyncclient/sponge/CSC.java | 13 ++-- .../sponge/ClientThread.java | 18 ++--- .../sponge/CommandSynchronize.java | 44 ++++++------ .../commandsyncclient/sponge/Locale.java | 71 ++++++++++++++++--- .../velocity/PluginInfo.java | 2 +- .../resources/META-INF/sponge_plugins.json | 2 +- src/main/resources/bungee.yml | 2 +- src/main/resources/plugin.yml | 2 +- 8 files changed, 104 insertions(+), 50 deletions(-) diff --git a/src/main/java/sawfowl/commandsyncclient/sponge/CSC.java b/src/main/java/sawfowl/commandsyncclient/sponge/CSC.java index 2f9893b..88a7247 100755 --- a/src/main/java/sawfowl/commandsyncclient/sponge/CSC.java +++ b/src/main/java/sawfowl/commandsyncclient/sponge/CSC.java @@ -128,7 +128,7 @@ private String[] loadConfig() { remove = Boolean.valueOf(data[6]); loc = new Locale(this, String.valueOf(data[7])); loc.init(); - logger.info(loc.getString("ConfigLoaded")); + logger.info(loc.getString("ConfigLoaded", true)); } catch(IOException e) { e.printStackTrace(); } @@ -148,8 +148,8 @@ private void workData() throws IOException { boolean remove = this.remove; if (remove == true) { if(data.delete()){ - logger.info(loc.getString("DataRemoved")); - } else logger.warn(loc.getString("DataRemoveNotFound")); + logger.info(loc.getString("DataRemoved", true)); + } else logger.warn(loc.getString("DataRemoveNotFound", true)); } else { loadData(); } @@ -164,7 +164,7 @@ public void saveData() { } ps.println("qc:" + String.valueOf(qc)); ps.close(); - logger.info(loc.getString("DataSaved")); + logger.info(loc.getString("DataSaved", true)); }catch(IOException e){ e.printStackTrace(); } @@ -185,15 +185,16 @@ private void loadData() { } l = br.readLine(); } - logger.info(loc.getString("DataLoaded")); + logger.info(loc.getString("DataLoaded", true)); } finally { br.close(); } } else { - logger.warn(loc.getString("DataNotfound")); + logger.warn(loc.getString("DataNotfound", true)); } } catch(IOException e) { e.printStackTrace(); } } + } diff --git a/src/main/java/sawfowl/commandsyncclient/sponge/ClientThread.java b/src/main/java/sawfowl/commandsyncclient/sponge/ClientThread.java index a5da200..b641803 100755 --- a/src/main/java/sawfowl/commandsyncclient/sponge/ClientThread.java +++ b/src/main/java/sawfowl/commandsyncclient/sponge/ClientThread.java @@ -45,7 +45,7 @@ public void run() { out.println("heartbeat"); if(out.checkError()) { connected = false; - plugin.getLogger().warn(plugin.getLocale().getString("ConnectLost")); + plugin.getLogger().warn(plugin.getLocale().getString("ConnectLost", true)); } else { try { Integer size = plugin.oq.size(); @@ -55,18 +55,18 @@ public void run() { count++; String output = plugin.oq.get(i); out.println(output); - plugin.getLogger().info(plugin.getLocale().getString("SentOutput", socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), output)); + plugin.getLogger().info(plugin.getLocale().getString("SentOutput", true, socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), output)); } plugin.qc = count; } while(in.ready()) { String input = in.readLine(); if(!input.equals("heartbeat")) { - plugin.getLogger().info(plugin.getLocale().getString("ReceivedInput", socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), input)); + plugin.getLogger().info(plugin.getLocale().getString("ReceivedInput", true, socket.getInetAddress().getHostName(), String.valueOf(socket.getPort()), input)); String[] data = input.split(plugin.spacer); if(data[0].equals("console")) { String command = data[2].replaceAll("\\+", " "); - plugin.getLogger().info(plugin.getLocale().getString("RanCommand", command)); + plugin.getLogger().info(plugin.getLocale().getString("RanCommand", true, command)); Sponge.server().scheduler().executor(plugin.getContainer()).execute(() -> { try { Sponge.server().commandManager().process(Sponge.systemSubject(), command); @@ -106,26 +106,26 @@ public void connect(Boolean sleep) { in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.println(name); if(in.readLine().equals("n")) { - plugin.getLogger().error(plugin.getLocale().getString("NameError", name)); + plugin.getLogger().error(plugin.getLocale().getString("NameError", true, name)); socket.close(); return; } out.println(pass); if(in.readLine().equals("n")) { - plugin.getLogger().error(plugin.getLocale().getString("InvalidPassword")); + plugin.getLogger().error(plugin.getLocale().getString("InvalidPassword", true)); socket.close(); return; } out.println(version); if(in.readLine().equals("n")) { - plugin.getLogger().error(plugin.getLocale().getString("VersionError", version, in.readLine())); + plugin.getLogger().error(plugin.getLocale().getString("VersionError", true, version, in.readLine())); socket.close(); return; } connected = true; - plugin.getLogger().info((plugin.getLocale().getString("ConnectInfo", ip.getHostName(), String.valueOf(port), name))); + plugin.getLogger().info((plugin.getLocale().getString("ConnectInfo", true, ip.getHostName(), String.valueOf(port), name))); } catch(IOException e) { - plugin.getLogger().error(plugin.getLocale().getString("NoConnect")); + plugin.getLogger().error(plugin.getLocale().getString("NoConnect", true)); } } } diff --git a/src/main/java/sawfowl/commandsyncclient/sponge/CommandSynchronize.java b/src/main/java/sawfowl/commandsyncclient/sponge/CommandSynchronize.java index f06decb..262d1ad 100755 --- a/src/main/java/sawfowl/commandsyncclient/sponge/CommandSynchronize.java +++ b/src/main/java/sawfowl/commandsyncclient/sponge/CommandSynchronize.java @@ -35,25 +35,25 @@ public CommandResult process(CommandCause cause, Mutable arguments) throws Comma String[] args = Stream.of(arguments.input().split(" ")).filter(string -> (!string.equals(""))).toArray(String[]::new); if(args.length >= 0) { if(args.length <= 2) { - cause.audience().sendMessage(plugin.getLocale().getString("HelpAuthors")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpAuthors")); if(args.length >= 1) { if(args[0].equalsIgnoreCase("console")){ - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands9", "sync")); - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands8", "sync")); - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands7", "sync")); - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands6", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands9", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands8", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands7", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands6", "sync")); } else if(args[0].equalsIgnoreCase("player")) { - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands5", "sync")); - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands4", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands5", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands4", "sync")); } else { - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands10", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands10", "sync")); } } else { - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands3", "sync")); - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands2", "sync")); - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands1")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands3", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands2", "sync")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands1")); } - cause.audience().sendMessage(plugin.getLocale().getString("HelpLink")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpLink")); } else if(args.length >= 3) { if(args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("player")) { String[] newArgs = new String[3]; @@ -73,7 +73,7 @@ public CommandResult process(CommandCause cause, Mutable arguments) throws Comma makeData(newArgs, true, cause); } } else { - cause.audience().sendMessage(plugin.getLocale().getString("HelpCommands9")); + cause.audience().sendMessage(plugin.getLocale().getComponent("HelpCommands9")); } } } @@ -115,20 +115,20 @@ public Component usage(CommandCause cause) { private void makeData(String[] args, Boolean single, CommandCause cause) { String data; - Component message; + String message; if(args[0].equalsIgnoreCase("console")) { if(args[1].equalsIgnoreCase("all")) { - message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncConsoleAll"))); + message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncConsoleAll")); } else { - message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncConsole", args[1]))); + message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncConsole", args[1])); } } else if(args[0].equalsIgnoreCase("bungee") || args[0].equalsIgnoreCase("proxy")) { - message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncConsole", args[1]))); + message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncConsole", args[1])); } else { if(args[1].equalsIgnoreCase("all")) { - message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncPlayerAll"))); + message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncPlayerAll")); } else { - message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), serialize(plugin.getLocale().getString("SyncPlayer", args[1]))); + message = plugin.getLocale().getString("SyncingCommand", args[2].replaceAll("\\+", " "), plugin.getLocale().getString("SyncPlayer", args[1])); } } if(single) { @@ -137,11 +137,11 @@ private void makeData(String[] args, Boolean single, CommandCause cause) { data = args[0].toLowerCase() + plugin.spacer + args[1].toLowerCase() + plugin.spacer + args[2]; } plugin.oq.add(data); - cause.audience().sendMessage(message); + cause.audience().sendMessage(deserialize(message)); } - private String serialize(Component component) { - return LegacyComponentSerializer.legacyAmpersand().serialize(component); + private Component deserialize(String string) { + return LegacyComponentSerializer.legacyAmpersand().deserialize(string); } } diff --git a/src/main/java/sawfowl/commandsyncclient/sponge/Locale.java b/src/main/java/sawfowl/commandsyncclient/sponge/Locale.java index e5bf7fd..40f8af6 100755 --- a/src/main/java/sawfowl/commandsyncclient/sponge/Locale.java +++ b/src/main/java/sawfowl/commandsyncclient/sponge/Locale.java @@ -13,6 +13,7 @@ import java.util.Properties; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.Style; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; /** @@ -74,8 +75,8 @@ public void init() throws IOException { * @param key - message key * @return message, otherwise null */ - public Component getString(final String key) { - return getString(key, false, ""); + public Component getComponent(final String key) { + return getComponent(key, false, ""); } /** @@ -87,7 +88,20 @@ public Component getString(final String key) { * @param args - arguments of the message. Only String format. * @return message, otherwise null */ - public Component getString(final String key, final String... args) { + public Component getComponent(final String key, final String... args) { + return this.getComponent(key, false, args); + } + + /** + * Receiving a message with arguments from the configuration
+ * Example message: "There is {0} players: {1}."
+ * Example call: getString("key", "2", "You, Me"); + * + * @param key - message key + * @param args - arguments of the message. Only String format. + * @return message, otherwise null + */ + public String getString(final String key, final String... args) { return this.getString(key, false, args); } @@ -100,8 +114,48 @@ public Component getString(final String key, final String... args) { * @param removeColors if true, then the colors will be removed * @return message, otherwise null */ - public Component getString(final String key, final boolean removeColors) { - return this.getString(key, removeColors, ""); + public Component getComponent(final String key, final boolean removeColors) { + return this.getComponent(key, removeColors, ""); + } + + /** + * Receiving a message from a configuration with the ability to filter color
+ * Example message: "\u00a76There is so many players."
+ * Example call: getString("key", false); + * + * @param key - message key + * @param removeColors if true, then the colors will be removed + * @return message, otherwise null + */ + public String getString(final String key, final boolean removeColors) { + return getString(key, removeColors, ""); + } + + /** + * Receiving a message with arguments from a configuration with the ability to filter the color
+ * Example message: "\u00a76There is \u00a7c{0} \u00a76players:\u00a7c {1}."
+ * Example call: getString("key", false, "2", "You, Me");
+ * + * @param key - message key + * @param removeColors - if true, then the colors will be removed + * @param args - arguments of the message. Only String format. + * @return message, otherwise null + */ + public String getString(final String key, final boolean removeColors, final String... args) { + String out = this.locale.getProperty(key); + if (out == null) { + return LegacyComponentSerializer.legacyAmpersand().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize("&4Key \"" + key + "\" not found!&r")); + } + MessageFormat mf = this.messageCache.get(out); + if (mf == null) { + mf = new MessageFormat(out); + this.messageCache.put(out, mf); + } + out = mf.format(args); + if (removeColors) { + return LegacyComponentSerializer.legacyAmpersand().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(out).style(Style.style().build()).style(Style.style().build())); + } + return out; } /** @@ -114,7 +168,7 @@ public Component getString(final String key, final boolean removeColors) { * @param args - arguments of the message. Only String format. * @return message, otherwise null */ - public Component getString(final String key, final boolean removeColors, final String... args) { + public Component getComponent(final String key, final boolean removeColors, final String... args) { String out = this.locale.getProperty(key); if (out == null) { return LegacyComponentSerializer.legacyAmpersand().deserialize("&4Key \"" + key + "\" not found!&r"); @@ -125,11 +179,10 @@ public Component getString(final String key, final boolean removeColors, final S this.messageCache.put(out, mf); } out = mf.format(args); - Component component = LegacyComponentSerializer.legacyAmpersand().deserialize(out); if (removeColors) { - component.decorations().clear(); + return LegacyComponentSerializer.legacyAmpersand().deserialize(out).style(Style.style().build()).style(Style.style().build()); } - return component; + return LegacyComponentSerializer.legacyAmpersand().deserialize(out); } /** diff --git a/src/main/java/sawfowl/commandsyncserver/velocity/PluginInfo.java b/src/main/java/sawfowl/commandsyncserver/velocity/PluginInfo.java index 10a8bff..af0dfda 100755 --- a/src/main/java/sawfowl/commandsyncserver/velocity/PluginInfo.java +++ b/src/main/java/sawfowl/commandsyncserver/velocity/PluginInfo.java @@ -6,7 +6,7 @@ public class PluginInfo { public static final String NAME = "CommandSync"; - public static final String VERSION = "2.8.0"; + public static final String VERSION = "2.8.1"; public static final String DESCRIPTION = "Synchronize commands across servers."; diff --git a/src/main/resources/META-INF/sponge_plugins.json b/src/main/resources/META-INF/sponge_plugins.json index d5de486..3f7cc18 100755 --- a/src/main/resources/META-INF/sponge_plugins.json +++ b/src/main/resources/META-INF/sponge_plugins.json @@ -5,7 +5,7 @@ }, "license": "GNU", "global": { - "version": "2.8.0-API8", + "version": "2.8.1-API8", "links": { "homepage": "https://ore.spongepowered.org/Semenkovsky_Ivan/CommandSync", "source": "https://github.com/SawFowl/CommandSync", diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml index de41ef4..f7a42e8 100755 --- a/src/main/resources/bungee.yml +++ b/src/main/resources/bungee.yml @@ -1,5 +1,5 @@ name: CommandSync main: sawfowl.commandsyncserver.bungee.CSS -version: 2.8.0 +version: 2.8.1 author: YoFuzzy3 description: Synchronize commands across servers. \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6983ce6..1561163 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: CommandSync main: sawfowl.commandsyncclient.bukkit.CSC -version: 2.8.0 +version: 2.8.1 author: YoFuzzy3 description: Synchronize commands across servers.