diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java index 1514918..690fe5b 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java @@ -352,7 +352,7 @@ public abstract class AbstractRedisBungeeAPI { * @since 0.8.0 * @deprecated */ - + @Deprecated public void kickPlayer(String playerName, String message) { kickPlayer(getUuidFromName(playerName), message); } diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java index 2662dfe..5d9391b 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java @@ -89,7 +89,7 @@ public interface ConfigLoader { boolean reconnectToLastServer = node.getNode("reconnect-to-last-server").getBoolean(); boolean handleMotd = node.getNode("handle-motd").getBoolean(true); - RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)), kickWhenOnline, reconnectToLastServer, handleMotd); + RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, kickWhenOnline, reconnectToLastServer, handleMotd); Summoner summoner; RedisBungeeMode redisBungeeMode; if (node.getNode("cluster-mode-enabled").getBoolean(false)) { @@ -137,30 +137,6 @@ public interface ConfigLoader { void onConfigLoad(RedisBungeeConfiguration configuration, Summoner summoner, RedisBungeeMode mode); - default ImmutableMap getMessagesFromPath(Path path) throws IOException { - final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(path).build(); - ConfigurationNode node = yamlConfigurationFileLoader.load(); - HashMap messages = new HashMap<>(); - messages.put(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION, node.getNode("logged-in-other-location").getString("§cLogged in from another location.")); - messages.put(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN, node.getNode("already-logged-in").getString("§cYou are already logged in!")); - return ImmutableMap.copyOf(messages); - } - - default Path createMessagesFile(Path dataFolder) throws IOException { - if (Files.notExists(dataFolder)) { - Files.createDirectory(dataFolder); - } - Path file = dataFolder.resolve("messages.yml"); - if (Files.notExists(file)) { - try (InputStream in = getClass().getClassLoader().getResourceAsStream("messages.yml")) { - Files.createFile(file); - assert in != null; - Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING); - } - } - return file; - } - default Path createConfigFile(Path dataFolder) throws IOException { if (Files.notExists(dataFolder)) { Files.createDirectory(dataFolder); diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java index ec61bae..5b991fa 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java @@ -13,18 +13,13 @@ package com.imaginarycode.minecraft.redisbungee.api.config; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.net.InetAddresses; +import net.kyori.adventure.text.Component; import java.net.InetAddress; import java.util.List; public class RedisBungeeConfiguration { - public enum MessageType { - LOGGED_IN_OTHER_LOCATION, - ALREADY_LOGGED_IN - } - - private final ImmutableMap messages; public static final int CONFIG_VERSION = 2; private final String proxyId; private final List exemptAddresses; @@ -36,9 +31,8 @@ public class RedisBungeeConfiguration { private final boolean handleMotd; - public RedisBungeeConfiguration(String proxyId, List exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap messages, boolean kickWhenOnline, boolean handleReconnectToLastServer, boolean handleMotd) { + public RedisBungeeConfiguration(String proxyId, List exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, boolean kickWhenOnline, boolean handleReconnectToLastServer, boolean handleMotd) { this.proxyId = proxyId; - this.messages = messages; ImmutableList.Builder addressBuilder = ImmutableList.builder(); for (String s : exemptAddresses) { addressBuilder.add(InetAddresses.forString(s)); @@ -67,10 +61,6 @@ public class RedisBungeeConfiguration { return overrideBungeeCommands; } - public String getMessage(MessageType messageType) { - return this.messages.get(messageType); - } - public boolean kickWhenOnline() { return kickWhenOnline; } diff --git a/RedisBungee-API/src/main/resources/lang.yml b/RedisBungee-API/src/main/resources/lang.yml new file mode 100644 index 0000000..f1b6367 --- /dev/null +++ b/RedisBungee-API/src/main/resources/lang.yml @@ -0,0 +1,34 @@ +# this config file is for messages / Languages +# Note 1: use MiniMessage format https://docs.advntr.dev/minimessage/format.html for colors etc... Legacy chat color is not supported. +# Mote 2: Language codes that are used is ISO 639-1, here is full list https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes + + +# example: +# Format: +# message_id: +# <2 char language code>: "MiniMessage color and your text." +# lets assume we want to add arabic language. +# logged-in-other-location: +# en: "You logged in from another location!" +# ar: "لقد اتصلت من مكان اخر" + + +# Prefix if ever used. +redis-bungee-prefix: "[RedisBungee]" + +# en is English, Which is the default language used when a language for a message isn't defined. +# Warning: if en or set default language wasn't defined in the config for all messages, plugin will not load. + +# set the default language +default-language: en + +# send language based on client sent settings +# https://minecraft.fandom.com/wiki/Language +use-client-language: true + + +logged-in-other-location: + en: "You logged in from another location!" + +already-logged-in: + en: "You are already logged in!" \ No newline at end of file diff --git a/RedisBungee-API/src/main/resources/messages.yml b/RedisBungee-API/src/main/resources/messages.yml deleted file mode 100644 index a92689b..0000000 --- a/RedisBungee-API/src/main/resources/messages.yml +++ /dev/null @@ -1,5 +0,0 @@ -# this config file is for messages for players and command messages -# Note this uses MiniMessage format https://docs.advntr.dev/minimessage/format.html - -logged-in-other-location: "You logged in from another location!" -already-logged-in: "You are already logged in!" \ No newline at end of file diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java index f21d703..9a50019 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/BungeePlayerDataManager.java @@ -16,6 +16,7 @@ import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfigurati import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent; import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.ChatColor; @@ -73,12 +74,12 @@ public class BungeePlayerDataManager extends PlayerDataManager event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3); } else { event.setCancelled(true); - event.setCancelReason(BungeeComponentSerializer.get().serialize(MiniMessage.miniMessage().deserialize( plugin.configuration().getMessage(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN)))); + event.setCancelReason(BUNGEECORD_SERIALIZER.serialize(Component.empty())); event.completeIntent((Plugin) plugin); } } else { diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java index 109cdff..b4e42fc 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/VelocityPlayerDataManager.java @@ -24,6 +24,7 @@ import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -68,15 +69,15 @@ public class VelocityPlayerDataManager extends PlayerDataManager