226 lines
12 KiB
Diff
226 lines
12 KiB
Diff
|
From a2394941af909d50114567bebc428ee13099578d Mon Sep 17 00:00:00 2001
|
||
|
From: linsaftw <25271111+linsaftw@users.noreply.github.com>
|
||
|
Date: Sat, 1 May 2021 13:40:39 -0300
|
||
|
Subject: [PATCH] FlameCord message configuration
|
||
|
|
||
|
|
||
|
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
||
|
index ac37eaa3..c78ab3a7 100644
|
||
|
--- a/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
||
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/FlameCord.java
|
||
|
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||
|
import java.util.logging.Logger;
|
||
|
|
||
|
import dev._2lstudios.flamecord.configuration.FlameCordConfiguration;
|
||
|
+import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||
|
import dev._2lstudios.flamecord.configuration.ModulesConfiguration;
|
||
|
import lombok.Getter;
|
||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||
|
@@ -25,12 +26,15 @@ public class FlameCord {
|
||
|
private FlameCordConfiguration flameCordConfiguration;
|
||
|
@Getter
|
||
|
private ModulesConfiguration modulesConfiguration;
|
||
|
+ @Getter
|
||
|
+ private MessagesConfiguration messagesConfiguration;
|
||
|
|
||
|
private void reload(final Logger logger) {
|
||
|
final ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||
|
|
||
|
this.flameCordConfiguration = new FlameCordConfiguration(configurationProvider);
|
||
|
this.modulesConfiguration = new ModulesConfiguration(configurationProvider);
|
||
|
+ this.messagesConfiguration = new MessagesConfiguration(logger, configurationProvider);
|
||
|
}
|
||
|
|
||
|
private FlameCord(final Logger logger, final Collection<String> whitelistedAddresses) {
|
||
|
diff --git a/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java
|
||
|
new file mode 100644
|
||
|
index 00000000..57462992
|
||
|
--- /dev/null
|
||
|
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java
|
||
|
@@ -0,0 +1,113 @@
|
||
|
+package dev._2lstudios.flamecord.configuration;
|
||
|
+
|
||
|
+import java.io.File;
|
||
|
+import java.io.IOException;
|
||
|
+import java.text.MessageFormat;
|
||
|
+import java.util.HashMap;
|
||
|
+import java.util.Map;
|
||
|
+import java.util.logging.Logger;
|
||
|
+
|
||
|
+import net.md_5.bungee.api.ChatColor;
|
||
|
+import net.md_5.bungee.config.Configuration;
|
||
|
+import net.md_5.bungee.config.ConfigurationProvider;
|
||
|
+
|
||
|
+public class MessagesConfiguration extends FlameConfig {
|
||
|
+ private final Logger logger;
|
||
|
+ private final Map<String, String> messages = new HashMap<>();
|
||
|
+
|
||
|
+ public MessagesConfiguration(final Logger logger, final ConfigurationProvider configurationProvider) {
|
||
|
+ this.logger = logger;
|
||
|
+
|
||
|
+ try {
|
||
|
+ final String fileName = "./messages.yml";
|
||
|
+ final File configurationFile = new File(fileName);
|
||
|
+ final Configuration configuration;
|
||
|
+ final boolean configurationExists = configurationFile.exists();
|
||
|
+
|
||
|
+ if (!configurationExists) {
|
||
|
+ configuration = new Configuration();
|
||
|
+ } else {
|
||
|
+ configuration = configurationProvider.load(configurationFile);
|
||
|
+ }
|
||
|
+
|
||
|
+ // BungeeCord
|
||
|
+ setIfUnexistant("alert", "&8[&4Alert&8]&r ", configuration);
|
||
|
+ setIfUnexistant("already_connected", "&cYou are already connected to this server!", configuration);
|
||
|
+ setIfUnexistant("already_connected_proxy", "&cYou are already connected to this proxy!", configuration);
|
||
|
+ setIfUnexistant("already_connecting", "&cAlready connecting to this server!", configuration);
|
||
|
+ setIfUnexistant("command_list", "&a[{0}] &e({1}): &r{2}", configuration);
|
||
|
+ setIfUnexistant("connect_kick", "&cKicked whilst connecting to {0}: {1}", configuration);
|
||
|
+ setIfUnexistant("current_server", "&6You are currently connected to {0}.", configuration);
|
||
|
+ setIfUnexistant("fallback_kick",
|
||
|
+ "&cCould not connect to a default or fallback server, please try again later: {0}", configuration);
|
||
|
+ setIfUnexistant("fallback_lobby",
|
||
|
+ "&cCould not connect to target server, you have been moved to a fallback server.", configuration);
|
||
|
+ setIfUnexistant("timeout",
|
||
|
+ "Server not reachable (timeout). Offline? Incorrectly configured address/port/firewall?", configuration);
|
||
|
+ setIfUnexistant("lost_connection", "[Proxy] Lost connection to server.", configuration);
|
||
|
+ setIfUnexistant("mojang_fail", "Error occurred while contacting login servers, are they down?",
|
||
|
+ configuration);
|
||
|
+ setIfUnexistant("no_permission", "&cYou do not have permission to execute this command!", configuration);
|
||
|
+ setIfUnexistant("no_server", "&cThe specified server does not exist.", configuration);
|
||
|
+ setIfUnexistant("no_server_permission", "&cYou don't have permission to access this server.",
|
||
|
+ configuration);
|
||
|
+ setIfUnexistant("outdated_client", "Outdated client! Please use {0}", configuration);
|
||
|
+ setIfUnexistant("outdated_server", "Outdated server! I'm still on {0}", configuration);
|
||
|
+ setIfUnexistant("proxy_full", "Server is full!", configuration);
|
||
|
+ setIfUnexistant("restart", "[Proxy] Proxy restarting.", configuration);
|
||
|
+ setIfUnexistant("server_list", "&6You may connect to the following servers at this time: ", configuration);
|
||
|
+ setIfUnexistant("server_went_down",
|
||
|
+ "&cThe server you were previously on went down, you have been connected to a fallback server",
|
||
|
+ configuration);
|
||
|
+ setIfUnexistant("total_players", "Total players online: {0}", configuration);
|
||
|
+ setIfUnexistant("name_invalid", "Username contains invalid characters.", configuration);
|
||
|
+ setIfUnexistant("ping_cannot_connect", "&c[Bungee] Can't connect to server.", configuration);
|
||
|
+ setIfUnexistant("offline_mode_player", "Not authenticated with Minecraft.net", configuration);
|
||
|
+ setIfUnexistant("message_needed", "&cYou must supply a message.", configuration);
|
||
|
+ setIfUnexistant("error_occurred_player",
|
||
|
+ "&cAn error occurred while parsing your message. (Hover for details)", configuration);
|
||
|
+ setIfUnexistant("error_occurred_console", "&cAn error occurred while parsing your message: {0}",
|
||
|
+ configuration);
|
||
|
+ setIfUnexistant("click_to_connect", "Click to connect to the server", configuration);
|
||
|
+ setIfUnexistant("username_needed", "&cPlease follow this command by a user name.", configuration);
|
||
|
+ setIfUnexistant("user_not_online", "&cThat user is not online.", configuration);
|
||
|
+ setIfUnexistant("user_online_at", "&a{0} &ris online at {1}", configuration);
|
||
|
+ setIfUnexistant("send_cmd_usage",
|
||
|
+ "&cNot enough arguments, usage: /send <server|player|all|current> <target>", configuration);
|
||
|
+ setIfUnexistant("player_only", "&cOnly in game players can use this command", configuration);
|
||
|
+ setIfUnexistant("you_got_summoned", "&6Summoned to {0} by {1}", configuration);
|
||
|
+ setIfUnexistant("command_perms_groups", "&6You have the following groups: {0}", configuration);
|
||
|
+ setIfUnexistant("command_perms_permission", "&9- {0}", configuration);
|
||
|
+ setIfUnexistant("command_ip", "&9IP of {0} is {1}", configuration);
|
||
|
+ setIfUnexistant("illegal_chat_characters", "&cIllegal characters in chat ({0})", configuration);
|
||
|
+
|
||
|
+ // FlameCord
|
||
|
+ setIfUnexistant("flamecord_reload", "&aAll files had been successfully reloaded!", configuration);
|
||
|
+ setIfUnexistant("flamecord_help",
|
||
|
+ "&aFlameCord&b {0}&a by&b LinsaFTW&a &&b Sammwy&r\n&e /flamecord reload&7 >&b Reloads FlameCord files!\n&e /flamecord help&7 >&b Shows this message!",
|
||
|
+ configuration);
|
||
|
+ setIfUnexistant("flamecord_nopermission", "&cYou don't have permission to do this!", configuration);
|
||
|
+
|
||
|
+ configurationProvider.save(configuration, configurationFile);
|
||
|
+
|
||
|
+ for (final String key : configuration.getKeys()) {
|
||
|
+ final Object value = configuration.get(key);
|
||
|
+
|
||
|
+ if (value instanceof String) {
|
||
|
+ this.messages.put(key, ChatColor.translateAlternateColorCodes('&', (String) value));
|
||
|
+ }
|
||
|
+ }
|
||
|
+ } catch (final IOException e) {
|
||
|
+ e.printStackTrace();
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ public String getTranslation(final String name, final Object... args) {
|
||
|
+ if (!messages.containsKey(name)) {
|
||
|
+ logger.warning("[FlameCord] Tried to get translation '" + name
|
||
|
+ + "' from messages.yml file but wasn't found. Please try resetting this file or report to a developer.");
|
||
|
+ }
|
||
|
+
|
||
|
+ return MessageFormat.format(messages.getOrDefault(name, "<translation '" + name + "' missing>"), args);
|
||
|
+ }
|
||
|
+}
|
||
|
\ No newline at end of file
|
||
|
diff --git a/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java b/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
|
||
|
index 91d60bfb..cc76325b 100644
|
||
|
--- a/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
|
||
|
+++ b/proxy/src/main/java/dev/_2lstudios/flamecord/commands/FlameCordCommand.java
|
||
|
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||
|
import java.util.HashSet;
|
||
|
|
||
|
import dev._2lstudios.flamecord.FlameCord;
|
||
|
+import dev._2lstudios.flamecord.configuration.MessagesConfiguration;
|
||
|
import net.md_5.bungee.BungeeCord;
|
||
|
import net.md_5.bungee.api.CommandSender;
|
||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||
|
@@ -22,6 +23,7 @@ private final BungeeCord bungeeCord;
|
||
|
@Override
|
||
|
public void execute(final CommandSender sender, final String[] args) {
|
||
|
final FlameCord flameCord = FlameCord.getInstance();
|
||
|
+ final MessagesConfiguration messagesConfiguration = flameCord.getMessagesConfiguration();
|
||
|
|
||
|
if (sender.hasPermission("flamecord.usage")) {
|
||
|
if (args.length > 0) {
|
||
|
@@ -38,21 +40,22 @@ private final BungeeCord bungeeCord;
|
||
|
|
||
|
FlameCord.reload(bungeeCord.getLogger(), whitelistedAddresses);
|
||
|
sender.sendMessage(TextComponent
|
||
|
- .fromLegacyText("flamecord_reload"));
|
||
|
+ .fromLegacyText(messagesConfiguration.getTranslation("flamecord_reload")));
|
||
|
break;
|
||
|
}
|
||
|
default: {
|
||
|
- sender.sendMessage(TextComponent.fromLegacyText("flamecord_help"));
|
||
|
+ sender.sendMessage(TextComponent.fromLegacyText(
|
||
|
+ messagesConfiguration.getTranslation("flamecord_help", bungeeCord.getVersion())));
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
sender.sendMessage(TextComponent
|
||
|
- .fromLegacyText("flamecord_help"));
|
||
|
+ .fromLegacyText(messagesConfiguration.getTranslation("flamecord_help", bungeeCord.getVersion())));
|
||
|
}
|
||
|
} else {
|
||
|
sender.sendMessage(TextComponent
|
||
|
- .fromLegacyText("flamecord_nopermission"));
|
||
|
+ .fromLegacyText(messagesConfiguration.getTranslation("flamecord_nopermission")));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
||
|
index ed5ce6e6..18c53872 100644
|
||
|
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
||
|
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
|
||
|
@@ -597,14 +597,8 @@ public class BungeeCord extends ProxyServer
|
||
|
@Override
|
||
|
public String getTranslation(String name, Object... args)
|
||
|
{
|
||
|
- String translation = "<translation '" + name + "' missing>";
|
||
|
- try
|
||
|
- {
|
||
|
- translation = MessageFormat.format( customBundle != null && customBundle.containsKey( name ) ? customBundle.getString( name ) : baseBundle.getString( name ), args );
|
||
|
- } catch ( MissingResourceException ex )
|
||
|
- {
|
||
|
- }
|
||
|
- return translation;
|
||
|
+ // FlameCord - Use own translation system
|
||
|
+ return FlameCord.getInstance().getMessagesConfiguration().getTranslation(name, args);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
--
|
||
|
2.32.0
|
||
|
|