Waterfall/Waterfall-Proxy-Patches/0020-FlameCord-message-configuration.patch
2023-01-15 19:48:59 -03:00

238 lines
13 KiB
Diff

From fbf8efb44cceaa714da0ca83a04695ad4ba1c4e3 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 fb3d8ca2e..676ba95b9 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;
@@ -27,6 +28,8 @@ public class FlameCord {
// FlameCord - Module System
@Getter
private ModulesConfiguration modulesConfiguration;
+ @Getter
+ private MessagesConfiguration messagesConfiguration;
public void reload(final Logger logger, final Collection<String> whitelistedAddresses) {
final ConfigurationProvider configurationProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
@@ -35,5 +38,6 @@ public class FlameCord {
// FlameCord - Module System
this.modulesConfiguration = new ModulesConfiguration(configurationProvider);
+ this.messagesConfiguration = new MessagesConfiguration(logger, configurationProvider);
}
}
\ No newline at end of file
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 000000000..21381bb45
--- /dev/null
+++ b/flamecord/src/main/java/dev/_2lstudios/flamecord/configuration/MessagesConfiguration.java
@@ -0,0 +1,115 @@
+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);
+ }
+
+ // FlameCord
+ setIfUnexistant("flamecord_reload", "&aAll files had been successfully reloaded!", configuration);
+ setIfUnexistant("flamecord_help",
+ "&aFlameCord&b {0}&a by&b LinsaFTW\n&e /flamecord reload&7 >&b Reloads FlameCord files!\n&e /flamecord firewall <add/remove> <ip>&7 >&b Firewall certain ips!\n&e /bplugins&7 >&b Show the plugin list!\n&e /bip <player>&7 >&b Show the ip and info of a player!\n&e /flamecord help&7 >&b Shows this message!",
+ configuration);
+ setIfUnexistant("flamecord_nopermission", "&cYou don't have permission to do this!", configuration);
+
+ // 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("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("secure_profile_required", "A secure profile is required to join this server.", configuration);
+ setIfUnexistant("secure_profile_expired", "Secure profile expired.", configuration);
+ setIfUnexistant("secure_profile_invalid", "Secure profile invalid.", 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("server_command_hover_players", "{0} players", 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);
+
+ 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/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java b/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java
index 698b420f4..e4ad7e389 100644
--- a/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java
+++ b/module/cmd-server/src/main/java/net/md_5/bungee/module/cmd/server/CommandServer.java
@@ -50,7 +50,9 @@ public class CommandServer extends Command implements TabExecutor
int count = server.getPlayers().size();
serverTextComponent.setHoverEvent( new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
- new ComponentBuilder( count + ( count == 1 ? " player" : " players" ) + "\n" ).appendLegacy( ProxyServer.getInstance().getTranslation( "click_to_connect" ) ).create() )
+ // FlameCord - FlameCord messages configuration
+ // Make player count customizable
+ new ComponentBuilder( ProxyServer.getInstance().getTranslation( "server_command_hover_players", count ) + "\n" ).appendLegacy( ProxyServer.getInstance().getTranslation( "click_to_connect" ) ).create() )
);
serverTextComponent.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/server " + server.getName() ) );
serverList.append( serverTextComponent );
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 021b38d43..fb81adee0 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.initialize(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 0eb9ae146..857b0b622 100644
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
@@ -620,8 +620,8 @@ public class BungeeCord extends ProxyServer
@Override
public String getTranslation(String name, Object... args)
{
- Format format = messageFormats.get( name );
- return ( format != null ) ? format.format( args ) : "<translation '" + name + "' missing>";
+ // FlameCord - Use own translation system
+ return FlameCord.getInstance().getMessagesConfiguration().getTranslation(name, args);
}
@Override
--
2.37.3.windows.1