getAliases() {
- return this.aliases;
- }
-
/*
* Are any permissions set for this channel?
*/
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/AbstractProxyConfig.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/AbstractProxyConfig.java
new file mode 100644
index 00000000..2ce280a4
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/AbstractProxyConfig.java
@@ -0,0 +1,162 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+
+import java.io.File;
+import java.io.IOException;
+
+import net.md_5.bungee.api.plugin.Plugin;
+import net.md_5.bungee.config.Configuration;
+import net.md_5.bungee.config.ConfigurationProvider;
+import net.md_5.bungee.config.YamlConfiguration;
+
+/**
+ * Class that represents the base of a config that can be handled by MultiChat
+ *
+ * Manages creation and reloads
+ *
+ * @author Oliver Martin (Revilo410)
+ */
+public abstract class AbstractProxyConfig {
+
+ private final String fileName;
+
+ /**
+ * Prepare an abstract config.
+ * You have to call {@link #setPlugin(Plugin)} to make {@link #reloadConfig()} work.
+ * You can call {@link #setDataFolder(File)} to change the folder under which the plugin will be saved.
+ *
+ * @param fileName The name of the file, needs
+ */
+ AbstractProxyConfig(String fileName) {
+ if (!fileName.endsWith(".yml"))
+ throw new IllegalArgumentException("Filename did not end with .yml");
+
+ this.fileName = fileName;
+ }
+
+ private Plugin plugin;
+ private File dataFolder, configFile;
+ private Configuration config;
+
+ /**
+ * Set the plugin that owns the configuration file
+ *
+ * @param plugin the BungeeCord plugin
+ * @throws IllegalArgumentException if the plugin has already been set
+ */
+ public final void setPlugin(Plugin plugin) throws IllegalArgumentException {
+ if (this.plugin != null)
+ throw new IllegalArgumentException("You can not change the plugin after setting it once.");
+
+ this.plugin = plugin;
+ }
+
+ /**
+ * Set the folder under which the file should be
+ *
+ * @param dataFolder the folder
+ * @throws IllegalArgumentException if the data folder has already been set
+ */
+ public final void setDataFolder(File dataFolder) throws IllegalArgumentException {
+ if (this.dataFolder != null)
+ throw new IllegalArgumentException("You can not change the data folder after setting it once.");
+
+ this.dataFolder = dataFolder;
+ }
+
+ /**
+ * Reload the config.
+ *
+ * This method can only be called if {@link #setPlugin(Plugin)} has been called.
+ * Data folder will be the plugin folder unless first set with with {@link #setDataFolder(File)}.
+ *
+ * @throws IllegalStateException if the plugin has not been set yet.
+ */
+ public final void reloadConfig() throws IllegalStateException {
+ if (plugin == null)
+ throw new IllegalStateException("You have not set the plugin yet.");
+
+ if (this.configFile == null)
+ this.configFile = new File(getDataFolder(), fileName);
+
+ plugin.getLogger().info("Loading " + fileName + " ...");
+ ProxyConfigUpdater configUpdater = new ProxyConfigUpdater(this);
+ configUpdater.update();
+
+ try {
+ config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
+ reloadValues();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Method that can be overridden to define what should happen after configuration has been reloaded.
+ */
+ void reloadValues() {
+ }
+
+ /**
+ * Convenience method to get the plugin. Same-Package only.
+ *
+ * @return the data folder.
+ * @throws IllegalStateException if the plugin has not been set
+ */
+ Plugin getPlugin() {
+ if (plugin == null)
+ throw new IllegalStateException("Method has been called without defining the plugin first.");
+
+ return plugin;
+ }
+
+ /**
+ * Convenience method to get the file name.
+ *
+ * @return the file name.
+ */
+ public final String getFileName() {
+ return fileName;
+ }
+
+ /**
+ * Convenience method to get the data folder.
+ *
+ * @return the data folder.
+ * @throws IllegalStateException if the plugin has not been set
+ */
+ public final File getDataFolder() throws IllegalStateException {
+ if (plugin == null)
+ throw new IllegalStateException("Method has been called without defining the plugin first.");
+
+ if (dataFolder == null)
+ dataFolder = plugin.getDataFolder();
+
+ return dataFolder;
+ }
+
+ /**
+ * Convenience method to get the config's file.
+ *
+ * @return the config's file.
+ * @throws IllegalStateException if the plugin has not been set
+ */
+ public final File getConfigFile() throws IllegalStateException {
+ if (plugin == null)
+ throw new IllegalStateException("Method has been called without defining the plugin first.");
+
+ return configFile;
+ }
+
+ /**
+ * Convenience method to get the bungee configuration.
+ *
+ * @return the config.
+ */
+ public final Configuration getConfig() {
+ if (config == null)
+ throw new IllegalStateException("Configuration has not been loaded yet. This should NOT happen! " +
+ "Check the server startup for errors.");
+ return config;
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ConfigFile.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ConfigFile.java
deleted file mode 100644
index 297223e5..00000000
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ConfigFile.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package xyz.olivermartin.multichat.proxy.common.config;
-
-public enum ConfigFile {
-
- CONFIG ("config.yml"),
- JOIN_MESSAGES ("joinmessages.yml"),
- CHAT_CONTROL ("chatcontrol.yml"),
- MESSAGES ("messages.yml"),
- ALIASES ("aliases.yml");
-
- private String fileName;
-
- private ConfigFile(String fileName) {
- this.fileName = fileName;
- }
-
- /**
- * Get the raw file name of this config file
- * @return the file name
- */
- public String getFileName() {
- return this.fileName;
- }
-
-}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ConfigValues.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ConfigValues.java
deleted file mode 100644
index 8e189a8a..00000000
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ConfigValues.java
+++ /dev/null
@@ -1,235 +0,0 @@
-package xyz.olivermartin.multichat.proxy.common.config;
-
-public class ConfigValues {
-
- public static interface Config {
-
- // Version
-
- /**
- * STRING :: Version of config file
- */
- String VERSION = "version";
-
- // General
-
- /**
- * BOOL :: Should display names be fetched from spigot
- */
- String FETCH_SPIGOT_DISPLAY_NAMES = "fetch_spigot_display_names";
-
- /**
- * BOOL :: Should MultiChat set display names
- */
- String SET_DISPLAY_NAME = "set_display_name";
-
- /**
- * STRING :: The format MultiChat should use to set display names
- */
- String DISPLAY_NAME_FORMAT = "display_name_format";
-
- // Private Messaging
-
- /**
- * BOOL :: Should private messaging be enabled
- */
- String PM = "pm";
-
- /**
- * STRING LIST :: List of servers that are excluded from PMs
- */
- String NO_PM = "no_pm";
-
- /**
- * BOOL :: Can players toggle pms with /msg playername?
- */
- String TOGGLE_PM = "toggle_pm";
-
- /**
- * STRING :: Format used for outgoing PMs
- */
- String PM_OUT_FORMAT = "pmout";
-
- /**
- * STRING :: Format used for incoming PMs
- */
- String PM_IN_FORMAT = "pmin";
-
- /**
- * STRING :: Format used for social spy PMs
- */
- String PM_SPY_FORMAT = "pmspy";
-
- // Chat Channels
-
- /**
- * STRING :: Default channel (local or global)
- */
- String DEFAULT_CHANNEL = "default_channel";
-
- /**
- * BOOL :: Should the default channel be enforced every time a player joins?
- */
- String FORCE_CHANNEL_ON_JOIN = "force_channel_on_join";
-
- // Global Chat
-
- /**
- * BOOL :: Should global chat be enabled?
- */
- String GLOBAL = "global";
-
- /**
- * STRING LIST :: List of servers to be excluded from global chat
- */
- String NO_GLOBAL = "no_global";
-
- /**
- * STRING :: Format for global chat
- */
- String GLOBAL_FORMAT = "globalformat";
-
- /**
- * STRING :: Format for local spy
- */
- String LOCAL_SPY_FORMAT = "localspyformat";
-
- // Group Chats
-
- public static interface GroupChat {
-
- /**
- * The prefix for this section of the config file
- */
- String PREFIX = "groupchat.";
-
- /**
- * STRING :: Format for group chats
- */
- String FORMAT = PREFIX + "format";
-
- /**
- * STRING :: Default chat colour
- */
- String CC_DEFAULT = PREFIX + "ccdefault";
-
- /**
- * STRING :: Default name colour
- */
- String NC_DEFAULT = PREFIX + "ncdefault";
-
- }
-
- // Staff Chats
-
- public static interface ModChat {
-
- /**
- * The prefix for this section of the config file
- */
- String PREFIX = "modchat.";
-
- /**
- * STRING :: Format for mod chat
- */
- String FORMAT = PREFIX + "format";
-
- /**
- * STRING :: Default chat colour
- */
- String CC_DEFAULT = PREFIX + "ccdefault";
-
- /**
- * STRING :: Default name colour
- */
- String NC_DEFAULT = PREFIX + "ncdefault";
-
- }
-
- public static interface AdminChat {
-
- /**
- * The prefix for this section of the config file
- */
- String PREFIX = "adminchat.";
-
- /**
- * STRING :: Format for admin chat
- */
- String FORMAT = PREFIX + "format";
-
- /**
- * STRING :: Default chat colour
- */
- String CC_DEFAULT = PREFIX + "ccdefault";
-
- /**
- * STRING :: Default name colour
- */
- String NC_DEFAULT = PREFIX + "ncdefault";
-
- }
-
- // Other Settings
-
- /**
- * BOOL :: Should staff list be enabled?
- */
- String STAFF_LIST = "staff_list";
-
- public static interface PrivacySettings {
-
- /**
- * The prefix for this section of the config file
- */
- String PREFIX = "privacy_settings.";
-
- /**
- * BOOL :: Should PMs be logged?
- */
- String LOG_PMS = PREFIX + "log_pms";
-
- /**
- * BOOL :: Should staff chat be logged?
- */
- String LOG_STAFFCHAT = PREFIX + "log_staffchat";
-
- /**
- * BOOL :: Should group chat be logged?
- */
- String LOG_GROUPCHAT = PREFIX + "log_groupchat";
-
- }
-
- public static interface PremiumVanish {
-
- /**
- * The prefix for this section of the config file
- */
- String PREFIX = "premium_vanish.";
-
- /**
- * BOOL :: Should PMs to vanished staff be prevented?
- */
- String PREVENT_MESSAGE = PREFIX + "prevent_message";
-
- /**
- * BOOL :: Should vanished staff be hidden from staff list?
- */
- String PREVENT_STAFF_LIST = PREFIX + "prevent_staff_list";
-
- /**
- * BOOL :: Should join messages be hidden for vanished staff?
- */
- String SILENCE_JOIN = PREFIX + "silence_join";
-
- }
-
- /**
- * STRING LIST :: List of pre 1.16 servers for RGB code approximation
- */
- String LEGACY_SERVERS = "legacy_servers";
-
- }
-
-}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyAliases.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyAliases.java
new file mode 100644
index 00000000..76458e0e
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyAliases.java
@@ -0,0 +1,35 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class to represent the proxy's aliases.yml.
+ */
+public class ProxyAliases extends AbstractProxyConfig {
+
+ private final Map commandAliases = new HashMap<>();
+
+ ProxyAliases() {
+ super("aliases.yml");
+ }
+
+ @Override
+ void reloadValues() {
+ commandAliases.clear();
+
+ getConfig().getKeys().forEach(key ->
+ commandAliases.put(key, getConfig().getStringList(key).toArray(new String[0]))
+ );
+ }
+
+ /**
+ * Get all aliases to a certain command.
+ *
+ * @param command The base name of the command
+ * @return the array of defined aliases, empty if command does not exist
+ */
+ public String[] getAliases(String command) {
+ return commandAliases.getOrDefault(command, new String[0]);
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyChatControl.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyChatControl.java
new file mode 100644
index 00000000..7d93ba7c
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyChatControl.java
@@ -0,0 +1,257 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.ProxyServer;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import xyz.olivermartin.multichat.common.MessageType;
+import xyz.olivermartin.multichat.proxy.common.ProxyLocalCommunicationManager;
+
+import java.util.*;
+import java.util.regex.Pattern;
+
+/**
+ * Class to represent the proxy's chatcontrol.yml.
+ *
+ * All methods should be relatively straight forward and represent their respective entries in the config.
+ */
+public class ProxyChatControl extends AbstractProxyConfig {
+
+ private String version, antiSpamCommand, linkRemovalMessage;
+ private final Set regexRules = new LinkedHashSet<>();
+ private final Set regexActions = new LinkedHashSet<>();
+ private final Map applyRulesTo = new HashMap<>(), applyActionsTo = new HashMap<>(),
+ applyAntiSpamTo = new HashMap<>(), applyMuteTo = new HashMap<>(), applyIgnoreTo = new HashMap<>();
+
+ private boolean antiSpam, antiSpamAction, antiSpamSpigot, mute, notifyIgnore, sessionIgnore, linkControl;
+ private int antiSpamTime, spamSameMessage, antiSpamCoolDown, antiSpamTrigger;
+ private Pattern linkPattern;
+
+ ProxyChatControl() {
+ super("chatcontrol.yml");
+ }
+
+ @Override
+ void reloadValues() {
+ regexRules.clear();
+ regexActions.clear();
+ applyRulesTo.clear();
+ applyActionsTo.clear();
+ applyAntiSpamTo.clear();
+ applyMuteTo.clear();
+ applyIgnoreTo.clear();
+
+ version = getConfig().getString("version", "1.10");
+
+ // Load regex rules
+ getConfig().getList("regex_rules").forEach(listEntry -> {
+ if (!(listEntry instanceof Map))
+ return;
+ Map, ?> regexRuleConfig = (Map, ?>) listEntry;
+ String pattern = String.valueOf(regexRuleConfig.get("look_for"));
+ if (pattern == null || pattern.isEmpty())
+ return;
+
+ regexRules.add(new RegexRule(pattern,
+ String.valueOf(regexRuleConfig.get("replace_with")),
+ String.valueOf(regexRuleConfig.get("permission")))
+ );
+ });
+ for (MessageType messageType : MessageType.values())
+ applyRulesTo.put(messageType, getConfig().getBoolean("apply_rules_to." + messageType.toString(), false));
+
+ // Load regex actions
+ getConfig().getList("regex_actions").forEach(listEntry -> {
+ if (!(listEntry instanceof Map))
+ return;
+ Map, ?> regexActionConfig = (Map, ?>) listEntry;
+
+ String pattern = String.valueOf(regexActionConfig.get("look_for"));
+ if (pattern == null || pattern.isEmpty())
+ return;
+
+ Object cancelObject = regexActionConfig.get("cancel");
+ boolean cancel = cancelObject instanceof Boolean && (boolean) cancelObject;
+
+ Object spigotObject = regexActionConfig.get("spigot");
+ boolean spigot = spigotObject instanceof Boolean && (boolean) spigotObject;
+
+ regexActions.add(new RegexAction(pattern,
+ String.valueOf(regexActionConfig.get("command")),
+ String.valueOf(regexActionConfig.get("permission")),
+ cancel,
+ spigot
+ )
+ );
+ });
+ for (MessageType messageType : MessageType.values())
+ applyActionsTo.put(messageType, getConfig().getBoolean("apply_actions_to." + messageType.toString(), false));
+
+ // Load spam settings
+ antiSpam = getConfig().getBoolean("anti_spam", true);
+ antiSpamTime = getConfig().getInt("anti_spam_time", 4);
+ spamSameMessage = getConfig().getInt("spam_same_message", 4);
+ antiSpamCoolDown = getConfig().getInt("anti_spam_cooldown", 60);
+ antiSpamAction = getConfig().getBoolean("anti_spam_action", true);
+ antiSpamSpigot = getConfig().getBoolean("anti_spam_spigot", true);
+ antiSpamTrigger = getConfig().getInt("anti_spam_trigger", 3);
+ antiSpamCommand = getConfig().getString("anti_spam_command");
+ for (MessageType messageType : MessageType.values())
+ applyAntiSpamTo.put(messageType, getConfig().getBoolean("apply_anti_spam_to." + messageType.toString(), false));
+
+ // Load mute settings
+ mute = getConfig().getBoolean("mute", false);
+ for (MessageType messageType : MessageType.values())
+ applyMuteTo.put(messageType, getConfig().getBoolean("apply_mute_to." + messageType.toString(), false));
+
+ // Load ignore settings
+ notifyIgnore = getConfig().getBoolean("notify_ignore", false);
+ sessionIgnore = getConfig().getBoolean("session_ignore", false);
+ for (MessageType messageType : MessageType.values())
+ applyIgnoreTo.put(messageType, getConfig().getBoolean("apply_ignore_to." + messageType.toString(), false));
+
+ // Load link control settings
+ linkControl = getConfig().getBoolean("link_control", false);
+ linkPattern = Pattern.compile(getConfig().getString("link_regex",
+ "((https|http):\\/\\/)?(www\\.)?([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.)+[a-zA-Z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]*)")
+ );
+ linkRemovalMessage = getConfig().getString("link_removal_message", "[LINK REMOVED]");
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ // TODO: [2.0] Some of these #apply / #replace / #handle methods could be moved into a refactored ChatControl.class
+ // I just added them to not lose the logic for now
+ // TODO: [2.0] Add events for regex rules and actions ?
+ public String applyRegexRules(CommandSender commandSender, String message, MessageType messageType) {
+ if (!applyRulesTo.get(messageType)) return message;
+
+ for (RegexRule regexRule : regexRules)
+ message = regexRule.apply(commandSender, message);
+ return message;
+ }
+
+ public boolean regexActionsCancel(CommandSender commandSender, String message, MessageType messageType) {
+ if (!applyActionsTo.get(messageType)) return false;
+
+ // TODO: [ConfigRefactor] Personally I believe we should return after the first action cancels the message being sent
+ boolean cancel = false;
+ for (RegexAction regexAction : regexActions) {
+ if (regexAction.cancels(commandSender, message))
+ cancel = true;
+ }
+
+ return cancel;
+ }
+
+ public String replaceLinks(String message) {
+ if (!linkControl)
+ return message;
+
+ return linkPattern.matcher(message).replaceAll(linkRemovalMessage);
+ }
+
+ public boolean applyMuteTo(MessageType messageType) {
+ return applyMuteTo.get(messageType);
+ }
+
+ public boolean applyIgnoreTo(MessageType messageType) {
+ return applyIgnoreTo.get(messageType);
+ }
+
+ public boolean applyAntiSpamTo(MessageType messageType) {
+ return applyAntiSpamTo.get(messageType);
+ }
+
+ public boolean isAntiSpam() {
+ return antiSpam;
+ }
+
+ public int getAntiSpamTime() {
+ return antiSpamTime;
+ }
+
+ public int getSpamSameMessage() {
+ return spamSameMessage;
+ }
+
+ public int getAntiSpamCoolDown() {
+ return antiSpamCoolDown;
+ }
+
+ public boolean isAntiSpamAction() {
+ return antiSpamAction;
+ }
+
+ public boolean isAntiSpamSpigot() {
+ return antiSpamSpigot;
+ }
+
+ public int getAntiSpamTrigger() {
+ return antiSpamTrigger;
+ }
+
+ public String getAntiSpamCommand() {
+ return antiSpamCommand;
+ }
+
+ public boolean isMute() {
+ return mute;
+ }
+
+ public boolean isNotifyIgnore() {
+ return notifyIgnore;
+ }
+
+ public boolean isSessionIgnore() {
+ return sessionIgnore;
+ }
+
+ // TODO: [ConfigRefactor] [2.0] Decide if we want to move these out of here. I don't think any other class needs access to these though.
+ private static class RegexRule {
+ private final Pattern pattern;
+ private final String replaceWith, permission;
+
+ RegexRule(String pattern, String replaceWith, String permission) {
+ this.pattern = Pattern.compile(pattern);
+ this.replaceWith = replaceWith.equals("null") ? "" : replaceWith;
+ this.permission = permission.equals("null") ? "" : permission;
+ }
+
+ public String apply(CommandSender commandSender, String message) {
+ if (commandSender != null && !permission.isEmpty() && !commandSender.hasPermission(permission))
+ return message;
+ return pattern.matcher(message).replaceAll(replaceWith);
+ }
+ }
+
+ private static class RegexAction {
+ private final Pattern pattern, playerPattern = Pattern.compile("%PLAYER%");
+ private final String command, permission;
+ private final boolean cancel, spigot;
+
+ RegexAction(String pattern, String command, String permission, boolean cancel, boolean spigot) {
+ this.pattern = Pattern.compile(pattern);
+ this.command = command.equals("null") ? "" : command;
+ this.permission = permission.equals("null") ? "" : permission;
+ this.cancel = cancel;
+ this.spigot = spigot;
+ }
+
+ public boolean cancels(CommandSender commandSender, String message) {
+ if (!permission.isEmpty() && !commandSender.hasPermission(permission))
+ return false;
+ if (!pattern.matcher(message).matches())
+ return false;
+ if (!command.isEmpty()) {
+ String tempCommand = playerPattern.matcher(command).replaceAll(commandSender.getName());
+ if (spigot && commandSender instanceof ProxiedPlayer)
+ ProxyLocalCommunicationManager.sendCommandMessage(tempCommand, ((ProxiedPlayer) commandSender).getServer().getInfo());
+ else
+ ProxyServer.getInstance().getPluginManager().dispatchCommand(commandSender, tempCommand);
+ }
+ return cancel;
+ }
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfig.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfig.java
new file mode 100644
index 00000000..fd4e5f48
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfig.java
@@ -0,0 +1,225 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+import xyz.olivermartin.multichat.common.RegexUtil;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Class to represent the proxy's config.yml.
+ *
+ * All methods should be relatively straight forward and represent their respective entries in the config.
+ */
+public class ProxyConfig extends AbstractProxyConfig {
+
+ private String version, displayNameFormat, pmOutFormat, pmInFormat, pmSpyFormat, defaultChannel, globalFormat,
+ localSpyFormat, groupChatFormat, modChatFormat, adminChatFormat;
+ private char groupChatColor, groupNameColor, modChatColor, modNameColor, adminChatColor, adminNameColor;
+ private boolean fetchSpigotDisplayNames, setDisplayName, pm, togglePm, forceChannelOnJoin, global, staffList,
+ logPms, logStaffChat, logGroupChat, pvPreventMessage, pvPreventStaffList, pvSilenceJoin;
+ private final Set noPmServers = new HashSet<>(), localServers = new HashSet<>(), legacyServers = new HashSet<>();
+
+ ProxyConfig() {
+ super("config.yml");
+ }
+
+ @Override
+ void reloadValues() {
+ noPmServers.clear();
+ localServers.clear();
+ legacyServers.clear();
+
+ version = getConfig().getString("version", "1.10");
+
+ fetchSpigotDisplayNames = getConfig().getBoolean("fetch_spigot_display_names", true);
+ setDisplayName = getConfig().getBoolean("set_display_name", true);
+ displayNameFormat = getConfig().getString("display_name_format", "%PREFIX%%NICK%%SUFFIX%");
+
+ pm = getConfig().getBoolean("pm", true);
+ noPmServers.addAll(getConfig().getStringList("no_pm"));
+ togglePm = getConfig().getBoolean("toggle_pm", true);
+
+ pmOutFormat = getConfig().getString("pmout", "&6[&cYou &6-> &c%DISPLAYNAMET%&6] &f%MESSAGE%");
+ pmInFormat = getConfig().getString("pmin", "&6[&c%DISPLAYNAME% &6-> &cMe&6] &f%MESSAGE%");
+ pmSpyFormat = getConfig().getString("pmSpyFormat", "&8&l<< &f%NAME% &7-> &f%NAMET%&8: &7%MESSAGE% &8&l>>");
+
+ defaultChannel = getConfig().getString("default_channel", "global");
+ if (!defaultChannel.equals("global") && !defaultChannel.equals("local"))
+ defaultChannel = "global";
+ forceChannelOnJoin = getConfig().getBoolean("force_channel_on_join", forceChannelOnJoin);
+
+ global = getConfig().getBoolean("global", true);
+ localServers.addAll(getConfig().getStringList("no_global"));
+
+ globalFormat = getConfig().getString("globalformat", "&2[&aG&2] &f%DISPLAYNAME%&f: ");
+ localSpyFormat = getConfig().getString("localspyformat", "&8[&7SPY&8] %FORMAT%");
+
+ groupChatFormat = getConfig().getString("groupchat.format", "%CC%(%NC%%GROUPNAME%%CC%)(%NC%%NAME%%CC%) %MESSAGE%");
+ groupChatColor = getConfig().getString("groupchat.ccdefault", "a").charAt(0);
+ if (!RegexUtil.LEGACY_COLOR.matches(String.valueOf(groupChatColor)))
+ groupChatColor = 'a';
+ groupNameColor = getConfig().getString("groupchat.ncdefault", "f").charAt(0);
+ if (!RegexUtil.LEGACY_COLOR.matches(String.valueOf(groupNameColor)))
+ groupNameColor = 'f';
+
+ modChatFormat = getConfig().getString("modchat.format", "%CC%{%NC%%NAME%%CC%} %MESSAGE%");
+ modChatColor = getConfig().getString("modchat.ccdefault", "b").charAt(0);
+ if (!RegexUtil.LEGACY_COLOR.matches(String.valueOf(modChatColor)))
+ modChatColor = 'b';
+ modNameColor = getConfig().getString("modchat.ncdefault", "d").charAt(0);
+ if (!RegexUtil.LEGACY_COLOR.matches(String.valueOf(modNameColor)))
+ modNameColor = 'd';
+
+ adminChatFormat = getConfig().getString("adminchat.format", "%CC%{%NC%%NAME%%CC%} %MESSAGE%");
+ adminChatColor = getConfig().getString("adminchat.ccdefault", "d").charAt(0);
+ if (!RegexUtil.LEGACY_COLOR.matches(String.valueOf(adminChatColor)))
+ adminChatColor = 'd';
+ adminNameColor = getConfig().getString("adminchat.ncdefault", "b").charAt(0);
+ if (!RegexUtil.LEGACY_COLOR.matches(String.valueOf(adminNameColor)))
+ adminNameColor = 'b';
+
+ staffList = getConfig().getBoolean("staff_list", true);
+
+ logPms = getConfig().getBoolean("privacy_settings.log_pms", true);
+ logStaffChat = getConfig().getBoolean("privacy_settings.log_staffchat", true);
+ logGroupChat = getConfig().getBoolean("privacy_settings.log_groupochat", true);
+
+ pvPreventMessage = getConfig().getBoolean("premium_vanish.prevent_message", true);
+ pvPreventStaffList = getConfig().getBoolean("premium_vanish.prevent_staff_list", true);
+ pvSilenceJoin = getConfig().getBoolean("premium_vanish.silence_join", true);
+
+ legacyServers.addAll(getConfig().getStringList("legacy_servers"));
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public boolean isFetchSpigotDisplayNames() {
+ return fetchSpigotDisplayNames;
+ }
+
+ public boolean isSetDisplayName() {
+ return setDisplayName;
+ }
+
+ public String getDisplayNameFormat() {
+ return displayNameFormat;
+ }
+
+ public boolean isPm() {
+ return pm;
+ }
+
+ public boolean isNoPmServer(String serverName) {
+ return noPmServers.contains(serverName);
+ }
+
+ public boolean isTogglePm() {
+ return togglePm;
+ }
+
+ public String getPmOutFormat() {
+ return pmOutFormat;
+ }
+
+ public String getPmInFormat() {
+ return pmInFormat;
+ }
+
+ public String getPmSpyFormat() {
+ return pmSpyFormat;
+ }
+
+ public String getDefaultChannel() {
+ return defaultChannel;
+ }
+
+ public boolean isForceChannelOnJoin() {
+ return forceChannelOnJoin;
+ }
+
+ public boolean isGlobal() {
+ return global;
+ }
+
+ public boolean isGlobalServer(String serverName) {
+ return !localServers.contains(serverName);
+ }
+
+ public String getGlobalFormat() {
+ return globalFormat;
+ }
+
+ public String getLocalSpyFormat() {
+ return localSpyFormat;
+ }
+
+ public String getGroupChatFormat() {
+ return groupChatFormat;
+ }
+
+ public char getGroupChatColor() {
+ return groupChatColor;
+ }
+
+ public char getGroupNameColor() {
+ return groupNameColor;
+ }
+
+ public String getModChatFormat() {
+ return modChatFormat;
+ }
+
+ public char getModChatColor() {
+ return modChatColor;
+ }
+
+ public char getModNameColor() {
+ return modNameColor;
+ }
+
+ public String getAdminChatFormat() {
+ return adminChatFormat;
+ }
+
+ public char getAdminChatColor() {
+ return adminChatColor;
+ }
+
+ public char getAdminNameColor() {
+ return adminNameColor;
+ }
+
+ public boolean isStaffList() {
+ return staffList;
+ }
+
+ public boolean isLogPms() {
+ return logPms;
+ }
+
+ public boolean isLogStaffChat() {
+ return logStaffChat;
+ }
+
+ public boolean isLogGroupChat() {
+ return logGroupChat;
+ }
+
+ public boolean isPvPreventMessage() {
+ return pvPreventMessage;
+ }
+
+ public boolean isPvPreventStaffList() {
+ return pvPreventStaffList;
+ }
+
+ public boolean isPvSilenceJoin() {
+ return pvSilenceJoin;
+ }
+
+ public boolean isLegacyServer(String serverName) {
+ return legacyServers.contains(serverName);
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfigUpdater.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfigUpdater.java
new file mode 100644
index 00000000..0bde8fad
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfigUpdater.java
@@ -0,0 +1,341 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+import net.md_5.bungee.api.plugin.Plugin;
+import net.md_5.bungee.config.Configuration;
+import net.md_5.bungee.config.ConfigurationProvider;
+import net.md_5.bungee.config.YamlConfiguration;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+public class ProxyConfigUpdater {
+
+ private final Plugin plugin;
+ private final AbstractProxyConfig config;
+ private final File backupDir;
+ private BufferedWriter writer;
+ private final Yaml yaml = new Yaml();
+
+ /**
+ * Create an updater for a proxy config. Will not do anything until you call {@link #update()}
+ *
+ * @param config the config that this updater will update
+ */
+ public ProxyConfigUpdater(AbstractProxyConfig config) {
+ this.config = config;
+ this.plugin = config.getPlugin();
+ this.backupDir = new File(config.getDataFolder(), "backups");
+ }
+
+ /**
+ * Update a yaml file from a resource inside your plugin jar, if the new version is higher than the old version.
+ *
+ * Creates the yaml file if it does not exist.
+ */
+ public void update() {
+ if (!config.getConfigFile().exists()) {
+ plugin.getLogger().info("Creating " + config.getFileName() + " ...");
+ try {
+ Files.copy(plugin.getResourceAsStream(config.getFileName()), config.getConfigFile().toPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return;
+ }
+
+ Configuration oldConfig;
+ try {
+ oldConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(config.getConfigFile());
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+ Configuration newConfig = ConfigurationProvider.getProvider(YamlConfiguration.class).load(
+ new InputStreamReader(plugin.getResourceAsStream(config.getFileName()))
+ );
+
+ String oldVersionString = oldConfig.getString("version");
+ String newVersionString = newConfig.getString("version");
+ if (oldVersionString == null) {
+ plugin.getLogger().info("Your saved version of " + config.getFileName()
+ + " does not have a version. The auto updater will cancel.");
+ return;
+ }
+ if (newVersionString == null) {
+ plugin.getLogger().info("The plugin-stored version of " + config.getFileName()
+ + " does not have a version. Please contact the plugin developer: "
+ + plugin.getDescription().getAuthor());
+ return;
+ }
+
+ boolean shouldUpdate = false;
+ String[] oldVersionStringSplit = oldVersionString.split("\\.");
+ String[] newVersionStringSplit = newVersionString.split("\\.");
+ for (int i = 0; i < oldVersionStringSplit.length; i++) {
+ if (i > newVersionStringSplit.length - 1) break;
+ try {
+ int oldVersionInt = Integer.parseInt(oldVersionStringSplit[i]);
+ int newVersionInt = Integer.parseInt(newVersionStringSplit[i]);
+
+ if (newVersionInt > oldVersionInt) {
+ shouldUpdate = true;
+ break;
+ }
+ } catch (NumberFormatException ignored) {
+ break;
+ }
+ }
+
+ if (!shouldUpdate) return;
+
+ plugin.getLogger().info("New config version found for " + config.getFileName() + "! Attempting auto update...");
+
+ if (!backupDir.exists() && !backupDir.mkdirs()) {
+ plugin.getLogger().severe("The backups directory could not be created.");
+ return;
+ }
+
+ // Back old config up
+ try {
+ InputStream in = new BufferedInputStream(new FileInputStream(config.getConfigFile()));
+ OutputStream out = new BufferedOutputStream(new FileOutputStream(
+ new File(backupDir, config.getFileName().replace(".yml", oldVersionString + ".yml")))
+ );
+
+ byte[] buffer = new byte[1024];
+ int lengthRead;
+ while ((lengthRead = in.read(buffer)) > 0) {
+ out.write(buffer, 0, lengthRead);
+ out.flush();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ oldConfig.set("version", newVersionString);
+
+ try {
+ write(oldConfig, newConfig);
+ plugin.getLogger().info("Auto update for " + config.getFileName() + " successful! Please check it yourself to verify.");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Get all keys and child keys of a configuration
+ *
+ * Thanks BungeeCord for not offering this.
+ *
+ * @param configuration the configuration to get the keys of
+ * @param previousKey the previous key (used for recursion, should be called with "")
+ * @return an insertion-ordered set of key names
+ */
+ private Set getDeepKeys(Configuration configuration, String previousKey) {
+ Set output = new LinkedHashSet<>();
+ configuration.getKeys().forEach(key -> {
+ Object deepKeyObject = configuration.get(key);
+ output.add(previousKey + key);
+ if (deepKeyObject instanceof Configuration) {
+ output.add(previousKey + key);
+ Configuration deepKey = (Configuration) deepKeyObject;
+ output.addAll(getDeepKeys(deepKey, key + "."));
+ }
+ });
+ return output;
+ }
+
+ private void write(Configuration oldConfig, Configuration newConfig) throws IOException {
+ BufferedReader resourceBufferedReader = new BufferedReader(
+ new InputStreamReader(plugin.getResourceAsStream(config.getFileName()), StandardCharsets.UTF_8)
+ );
+ Map comments = getComments(resourceBufferedReader.lines().collect(Collectors.toList()));
+ resourceBufferedReader.close();
+
+ writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(config.getConfigFile()), StandardCharsets.UTF_8)
+ );
+
+ for (String key : getDeepKeys(newConfig, "")) {
+ String[] currentKeys = key.split("\\.");
+ String actualKey = currentKeys[currentKeys.length - 1];
+ String comment = comments.remove(key);
+
+ StringBuilder indentBuilder = new StringBuilder();
+ for (int i = 0; i < currentKeys.length - 1; i++)
+ indentBuilder.append(" ");
+ String indent = indentBuilder.toString();
+
+ if (comment != null)
+ writer.write(comment);
+
+ Object newObject = newConfig.get(key);
+ Object oldObject = oldConfig.get(key);
+
+ if (newObject instanceof Configuration && oldObject instanceof Configuration) {
+ // Write the old section
+ writeSection(indent, actualKey, (Configuration) oldObject);
+ } else if (newObject instanceof Configuration) {
+ // Write the new section
+ writeSection(indent, actualKey, (Configuration) newObject);
+ } else if (oldObject != null) {
+ // Write the old object
+ write(indent, actualKey, oldObject);
+ } else {
+ // Write the new object
+ write(indent, actualKey, newObject);
+ }
+ }
+
+ // All keys written, write leftover comments
+ String danglingComments = comments.get(null);
+
+ if (danglingComments != null)
+ writer.write(danglingComments);
+
+ writer.close();
+ }
+
+ private void write(String indent, String key, Object toWrite) throws IOException {
+ if (toWrite instanceof String || toWrite instanceof Character) {
+ String string = String.valueOf(toWrite);
+ writer.write(indent + key + ": " + yaml.dump(string.replace("\n", "\\n")));
+ } else if (toWrite instanceof List) {
+ writer.write(getListAsString(indent, key, (List>) toWrite));
+ } else {
+ writer.write(indent + key + ": " + yaml.dump(toWrite));
+ }
+ }
+
+ private void writeSection(String indent, String key, Configuration section) throws IOException {
+ if (section.getKeys().isEmpty()) {
+ writer.write(indent + key + ": {}");
+ } else {
+ writer.write(indent + key + ":");
+ }
+
+ writer.write("\n");
+ }
+
+ private String getListAsString(String indent, String key, List> list) {
+ StringBuilder builder = new StringBuilder(indent).append(key).append(":");
+
+ if (list.isEmpty()) {
+ builder.append(" []\n");
+ return builder.toString();
+ }
+
+ builder.append("\n");
+
+ for (Object toWrite : list) {
+ builder.append(indent);
+
+ if (toWrite instanceof String || toWrite instanceof Character) {
+ builder.append("- '").append(toWrite).append("'");
+ } else if (toWrite instanceof List) {
+ builder.append("- ").append(yaml.dump(toWrite));
+ } else if (toWrite instanceof Map) {
+ AtomicBoolean first = new AtomicBoolean(true);
+ ((Map, ?>) toWrite).forEach(((mapKey, mapValue) -> {
+ if (first.get()) {
+ builder.append("- ");
+ first.set(false);
+ } else
+ builder.append(" ");
+ builder.append(mapKey).append(": ").append(yaml.dump(mapValue));
+ }));
+ } else {
+ builder.append("- ").append(toWrite);
+ }
+ }
+
+ return builder.toString();
+ }
+
+ private Map getComments(List lines) {
+ Map comments = new HashMap<>();
+ StringBuilder keysBuilder = new StringBuilder();
+ StringBuilder commentBuilder = new StringBuilder();
+ long indents = 0;
+
+ for (String line : lines) {
+ String trimmedLine = line == null ? "" : line.trim();
+ if (trimmedLine.startsWith("-")) continue;
+
+ if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) {
+ commentBuilder.append(line).append("\n");
+ } else {
+ indents = setFullKey(keysBuilder, line, indents);
+
+ if (keysBuilder.length() > 0) {
+ comments.put(keysBuilder.toString(), commentBuilder.toString());
+ commentBuilder.setLength(0);
+ }
+ }
+ }
+
+ if (commentBuilder.length() > 0) {
+ comments.put(null, commentBuilder.toString());
+ }
+
+ return comments;
+ }
+
+ private void removeLastKey(StringBuilder keyBuilder) {
+ String temp = keyBuilder.toString();
+ String[] keys = temp.split("\\.");
+
+ if (keys.length == 1) {
+ keyBuilder.setLength(0);
+ return;
+ }
+
+ temp = temp.substring(0, temp.length() - keys[keys.length - 1].length() - 1);
+ keyBuilder.setLength(temp.length());
+ }
+
+ private long setFullKey(StringBuilder keysBuilder, String configLine, long indents) {
+ // One indent is 2 spaces
+ long currentIndents = 0;
+ for (char c : configLine.toCharArray()) {
+ if (c == ' ') currentIndents++;
+ // Ignore further spaces
+ else break;
+ }
+ currentIndents = currentIndents / 2;
+
+ String key = configLine.trim().split(":")[0];
+
+ if (keysBuilder.length() == 0) {
+ keysBuilder.append(key);
+ } else if (currentIndents == indents) {
+ removeLastKey(keysBuilder);
+
+ if (keysBuilder.length() > 0) {
+ keysBuilder.append(".");
+ }
+
+ keysBuilder.append(key);
+ } else if (currentIndents > indents) {
+ keysBuilder.append(".").append(key);
+ } else {
+ long difference = indents - currentIndents;
+
+ for (int i = 0; i < difference + 1; i++) {
+ removeLastKey(keysBuilder);
+ }
+
+ if (keysBuilder.length() > 0) {
+ keysBuilder.append(".");
+ }
+
+ keysBuilder.append(key);
+ }
+
+ return currentIndents;
+ }
+}
\ No newline at end of file
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfigs.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfigs.java
new file mode 100644
index 00000000..6ad48a96
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyConfigs.java
@@ -0,0 +1,95 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+import net.md_5.bungee.api.plugin.Plugin;
+
+import java.io.File;
+import java.util.*;
+
+/**
+ * Utility class to access proxy configs.
+ */
+public class ProxyConfigs {
+
+ private ProxyConfigs() {
+ }
+
+ /**
+ * Used to access the proxy's config.yml.
+ */
+ public static final ProxyConfig CONFIG = new ProxyConfig();
+
+ /**
+ * Used to access the proxy's aliases.yml.
+ */
+ public static final ProxyAliases ALIASES = new ProxyAliases();
+
+ /**
+ * Used to access the proxy's chatcontrol.yml.
+ */
+ public static final ProxyChatControl CHAT_CONTROL = new ProxyChatControl();
+
+ /**
+ * Used to access the proxy's messages.yml.
+ */
+ public static final ProxyMessages MESSAGES = new ProxyMessages();
+
+ /**
+ * Used to access the proxy's joinmessages.yml.
+ */
+ public static final ProxyJoinMessages JOIN_MESSAGES = new ProxyJoinMessages();
+
+ /**
+ * List of all configurations that are managed by the plugin and have pre-defined values.
+ */
+ public static final List ALL = Arrays.asList(CONFIG, ALIASES, CHAT_CONTROL, MESSAGES, JOIN_MESSAGES);
+
+ /**
+ * List of all configurations that are saved in the plugin jar and don't have pre-defined values.
+ */
+ public static final Set RAW_CONFIGS = new HashSet<>();
+
+ /**
+ * Loads or reloads and gets the {@link AbstractProxyConfig} of a .yml file inside a plugin's resources.
+ * Calling reloadValues on the config will do nothing, you will have to make your own implementation.
+ *
+ * Currently only used by french translations in MultiChat.
+ *
+ * @param plugin the plugin of which the resources should be loaded
+ * @param fileName the name of the file that ends with .yml
+ * @return the {@link AbstractProxyConfig} of that file
+ */
+ public static AbstractProxyConfig loadRawConfig(Plugin plugin, String fileName) {
+ return loadRawConfig(plugin, fileName, plugin.getDataFolder());
+ }
+
+ /**
+ * Loads or reloads and gets the {@link AbstractProxyConfig} of a .yml file inside a plugin's resources.
+ * Calling reloadValues on the config will do nothing, you will have to make your own implementation.
+ *
+ * Currently only used by french translations in MultiChat.
+ *
+ * @param plugin the plugin of which the resources should be loaded
+ * @param fileName the name of the file that ends with .yml
+ * @param dataFolder the path where the file should end up
+ * @return the {@link AbstractProxyConfig} of that file
+ */
+ public static AbstractProxyConfig loadRawConfig(Plugin plugin, String fileName, File dataFolder) {
+ if (!fileName.endsWith(".yml"))
+ throw new IllegalArgumentException("File name did not end with .yml");
+
+ AbstractProxyConfig rawConfig = RAW_CONFIGS.stream()
+ .filter(abstractProxyConfig -> abstractProxyConfig.getFileName().equals(fileName))
+ .findFirst()
+ .orElse(null);
+ if (rawConfig == null) {
+ rawConfig = new AbstractProxyConfig(fileName) {};
+ rawConfig.setPlugin(plugin);
+ rawConfig.setDataFolder(dataFolder);
+ } else
+ RAW_CONFIGS.remove(rawConfig);
+ rawConfig.reloadConfig();
+ RAW_CONFIGS.add(rawConfig);
+
+ return rawConfig;
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyJoinMessages.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyJoinMessages.java
new file mode 100644
index 00000000..54b1d3cb
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyJoinMessages.java
@@ -0,0 +1,78 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+/**
+ * Class to represent the proxy's joinmessages.yml.
+ *
+ * All methods should be relatively straight forward and represent their respective entries in the config.
+ */
+public class ProxyJoinMessages extends AbstractProxyConfig {
+
+ private String version, serverJoin, silentJoin, networkQuit, silentQuit, welcomeMessage, privateWelcomeMessage;
+ private boolean showJoin, showQuit, welcome, privateWelcome;
+
+ ProxyJoinMessages() {
+ super("joinmessages.yml");
+ }
+
+ @Override
+ void reloadValues() {
+ version = getConfig().getString("version", "1.10");
+
+ showJoin = getConfig().getBoolean("showjoin", true);
+ showQuit = getConfig().getBoolean("showquit", true);
+
+ serverJoin = getConfig().getString("serverjoin", "&e%NAME% &ejoined the network");
+ silentJoin = getConfig().getString("silentjoin", "&b&o%NAME% &b&ojoined the network silently");
+ networkQuit = getConfig().getString("networkquit", "&e%NAME% left the network");
+ silentQuit = getConfig().getString("silentquit", "&b&o%NAME% &b&oleft the network silently");
+
+ welcome = getConfig().getBoolean("welcome", true);
+ welcomeMessage = getConfig().getString("welcome_message", "&dWelcome %NAME% to the network for the first time!");
+ privateWelcome = getConfig().getBoolean("private_welcome", false);
+ privateWelcomeMessage = getConfig().getString("private_welcome_message", "&5Hi there %NAME%, please make sure you read the /rules!");
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public boolean isShowJoin() {
+ return showJoin;
+ }
+
+ public boolean isShowQuit() {
+ return showQuit;
+ }
+
+ public String getServerJoin() {
+ return serverJoin;
+ }
+
+ public String getSilentJoin() {
+ return silentJoin;
+ }
+
+ public String getNetworkQuit() {
+ return networkQuit;
+ }
+
+ public String getSilentQuit() {
+ return silentQuit;
+ }
+
+ public boolean isWelcome() {
+ return welcome;
+ }
+
+ public String getWelcomeMessage() {
+ return welcomeMessage;
+ }
+
+ public boolean isPrivateWelcome() {
+ return privateWelcome;
+ }
+
+ public String getPrivateWelcomeMessage() {
+ return privateWelcomeMessage;
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyMessages.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyMessages.java
new file mode 100644
index 00000000..efe755b7
--- /dev/null
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/config/ProxyMessages.java
@@ -0,0 +1,96 @@
+package xyz.olivermartin.multichat.proxy.common.config;
+
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import xyz.olivermartin.multichat.common.MultiChatUtil;
+import xyz.olivermartin.multichat.proxy.common.ProxyJsonUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class to represent the proxy's messages.yml.
+ *
+ * All methods should be relatively straight forward and represent their respective entries in the config.
+ */
+public class ProxyMessages extends AbstractProxyConfig {
+
+ private final Map messagesMap = new HashMap<>();
+
+ ProxyMessages() {
+ super("messages.yml");
+ }
+
+ @Override
+ void reloadValues() {
+ messagesMap.clear();
+
+ getConfig().getKeys().forEach(key -> messagesMap.put(key, getConfig().getString(key)));
+ }
+
+ public String getPrefix() {
+ return messagesMap.getOrDefault("prefix", "&8&l[&2&lM&a&lC&8&l]&f ");
+ }
+
+ public String getMessage(String key) {
+ return messagesMap.getOrDefault(key, "&cERROR - Please report to plugin dev - No message defined for: " + key);
+ }
+
+ public void sendMessage(CommandSender sender, String id) {
+ sendMessage(sender, id, true);
+ }
+
+ public void sendMessage(CommandSender sender, String id, boolean usePrefix) {
+ sendMessage(sender, id, usePrefix, null);
+ }
+
+ public void sendMessage(CommandSender sender, String id, String special) {
+ sendMessage(sender, id, true, special, false);
+ }
+
+ public void sendMessage(CommandSender sender, String id, boolean usePrefix, String special) {
+ sendMessage(sender, id, usePrefix, special, false);
+ }
+
+ public void sendMessage(CommandSender sender, String id, String special, boolean specialJson) {
+ sendMessage(sender, id, true, special, specialJson);
+ }
+
+ // TODO: [2.0] [ConfigRefactor] Should probably take another look at this method at some point
+ public void sendMessage(CommandSender sender, String id, boolean usePrefix, String special, boolean specialJson) {
+
+ boolean isSpecial = special != null;
+
+ // Translate format codes
+ String message = (usePrefix ? getPrefix() : "+++") + getMessage(id);
+ message = MultiChatUtil.translateColorCodes(message);
+ if (isSpecial) special = MultiChatUtil.translateColorCodes(special);
+
+ // Handle legacy servers
+ if (sender instanceof ProxiedPlayer) {
+ ProxiedPlayer player = (ProxiedPlayer) sender;
+ if (ProxyConfigs.CONFIG.isLegacyServer(player.getServer().getInfo().getName())) {
+ message = MultiChatUtil.approximateRGBColorCodes(message);
+ if (isSpecial) special = MultiChatUtil.approximateRGBColorCodes(special);
+ }
+ } else {
+ // Handle console
+ message = MultiChatUtil.approximateRGBColorCodes(message);
+ if (isSpecial) special = MultiChatUtil.approximateRGBColorCodes(special);
+ }
+
+ // If we want to treat the "Special" part as Json, then we will parse it here and treat it as a non special message
+ if (isSpecial && specialJson) {
+ message = message.replace("%SPECIAL%", special);
+ isSpecial = false;
+ }
+
+ // Parse & send message
+ if (isSpecial) {
+ sender.sendMessage(ProxyJsonUtils.parseMessage(message, "%SPECIAL%", special));
+ } else {
+ sender.sendMessage(ProxyJsonUtils.parseMessage(message));
+ }
+
+ }
+}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/contexts/GlobalContext.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/contexts/GlobalContext.java
index 785e1001..c0699429 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/contexts/GlobalContext.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/contexts/GlobalContext.java
@@ -1,11 +1,34 @@
package xyz.olivermartin.multichat.proxy.common.contexts;
-import java.util.List;
+import net.md_5.bungee.api.CommandSender;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
+
+import java.util.ArrayList;
public class GlobalContext extends Context {
- public GlobalContext(String defaultChannel, boolean forceChannel, boolean blacklistServers, List servers) {
- super("global", 0, defaultChannel, forceChannel, blacklistServers, servers);
+ public GlobalContext(String defaultChannel, boolean forceChannel, boolean blacklistServers) {
+ super("global", 0, defaultChannel, forceChannel, blacklistServers, new ArrayList<>());
}
+ @Override
+ public boolean contains(CommandSender sender) {
+ if (!(sender instanceof ProxiedPlayer)) return true;
+
+ ProxiedPlayer player = (ProxiedPlayer) sender;
+ if (player.getServer() == null) return false;
+
+ /*
+ global blacklist needed
+ --------------------------------
+ 0 0 0
+ 0 1 1
+ 1 0 1
+ 1 1 0
+
+ This concludes that we can use XOR
+ */
+ return ProxyConfigs.CONFIG.isGlobalServer(player.getServer().getInfo().getName()) ^ isBlacklistServers();
+ }
}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLoginListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLoginListener.java
index 9b0b7e86..cd795541 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLoginListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLoginListener.java
@@ -9,11 +9,10 @@
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
-import xyz.olivermartin.multichat.bungee.ConfigManager;
import xyz.olivermartin.multichat.bungee.ConsoleManager;
import xyz.olivermartin.multichat.bungee.PlayerMetaManager;
import xyz.olivermartin.multichat.proxy.common.MultiChatProxy;
-import xyz.olivermartin.multichat.proxy.common.config.ConfigFile;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
import xyz.olivermartin.multichat.proxy.common.storage.ProxyDataStore;
public class ProxyLoginListener implements Listener {
@@ -32,8 +31,8 @@ public void onLogin(PostLoginEvent event) {
if (!ds.getModChatPreferences().containsKey(uuid)) {
TChatInfo chatinfo = new TChatInfo();
- chatinfo.setChatColor(ConfigManager.getInstance().getHandler(ConfigFile.CONFIG).getConfig().getString("modchat.ccdefault").toCharArray()[0]);
- chatinfo.setNameColor(ConfigManager.getInstance().getHandler(ConfigFile.CONFIG).getConfig().getString("modchat.ncdefault").toCharArray()[0]);
+ chatinfo.setChatColor(ProxyConfigs.CONFIG.getModChatColor());
+ chatinfo.setNameColor(ProxyConfigs.CONFIG.getModNameColor());
ds.getModChatPreferences().put(uuid, chatinfo);
}
@@ -45,8 +44,8 @@ public void onLogin(PostLoginEvent event) {
if (!ds.getAdminChatPreferences().containsKey(uuid)) {
TChatInfo chatinfo = new TChatInfo();
- chatinfo.setChatColor(ConfigManager.getInstance().getHandler(ConfigFile.CONFIG).getConfig().getString("adminchat.ccdefault").toCharArray()[0]);
- chatinfo.setNameColor(ConfigManager.getInstance().getHandler(ConfigFile.CONFIG).getConfig().getString("adminchat.ncdefault").toCharArray()[0]);
+ chatinfo.setChatColor(ProxyConfigs.CONFIG.getAdminChatColor());
+ chatinfo.setNameColor(ProxyConfigs.CONFIG.getAdminNameColor());
ds.getAdminChatPreferences().put(uuid, chatinfo);
}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLogoutListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLogoutListener.java
index 80f18030..368ecded 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLogoutListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyLogoutListener.java
@@ -1,27 +1,20 @@
package xyz.olivermartin.multichat.proxy.common.listeners;
-import java.util.UUID;
-
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.plugin.Listener;
-import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
-import xyz.olivermartin.multichat.bungee.ChatControl;
-import xyz.olivermartin.multichat.bungee.ChatManipulation;
-import xyz.olivermartin.multichat.bungee.ConfigManager;
-import xyz.olivermartin.multichat.bungee.ConsoleManager;
-import xyz.olivermartin.multichat.bungee.Events;
-import xyz.olivermartin.multichat.bungee.MultiChat;
-import xyz.olivermartin.multichat.bungee.PlayerMetaManager;
+import xyz.olivermartin.multichat.bungee.*;
import xyz.olivermartin.multichat.common.MultiChatUtil;
import xyz.olivermartin.multichat.proxy.common.MultiChatProxy;
import xyz.olivermartin.multichat.proxy.common.ProxyJsonUtils;
-import xyz.olivermartin.multichat.proxy.common.config.ConfigFile;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
import xyz.olivermartin.multichat.proxy.common.storage.ProxyDataStore;
+import java.util.UUID;
+
public class ProxyLogoutListener implements Listener {
private void displayMessage(ProxiedPlayer player, String message) {
@@ -30,7 +23,7 @@ private void displayMessage(ProxiedPlayer player, String message) {
message = MultiChatUtil.translateColorCodes(message);
- if (MultiChat.legacyServers.contains(player.getServer().getInfo().getName())) message = MultiChatUtil.approximateRGBColorCodes(message);
+ if (ProxyConfigs.CONFIG.isLegacyServer(player.getServer().getInfo().getName())) message = MultiChatUtil.approximateRGBColorCodes(message);
player.sendMessage(ProxyJsonUtils.parseMessage(message));
@@ -65,10 +58,8 @@ public void onLogout(PlayerDisconnectEvent event) {
Events.GCToggle.remove(uuid);
}
- Configuration config = ConfigManager.getInstance().getHandler(ConfigFile.CHAT_CONTROL).getConfig();
-
// If using sessional ignore, then wipe ignores stored
- if (config.getBoolean("session_ignore")) {
+ if (ProxyConfigs.CHAT_CONTROL.isSessionIgnore()) {
ChatControl.unignoreAll(uuid);
}
@@ -89,32 +80,23 @@ public void onLogout(PlayerDisconnectEvent event) {
ds.getJoinedNetwork().remove(player.getUniqueId());
// If we are handling the quit messages, then handle them...
- if ( ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("showquit") == true ) {
-
+ if (ProxyConfigs.JOIN_MESSAGES.isShowQuit()) {
// Get the formats
- String joinformat = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getString("networkquit");
- String silentformat = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getString("silentquit");
+ String quitFormat = ProxyConfigs.JOIN_MESSAGES.getNetworkQuit();
+ boolean silenceQuit = player.hasPermission("multichat.staff.silentjoin");
+ if (silenceQuit)
+ quitFormat = ProxyConfigs.JOIN_MESSAGES.getSilentQuit();
// Replace the placeholders
- ChatManipulation chatman = new ChatManipulation();
- joinformat = chatman.replaceJoinMsgVars(joinformat, player.getName(), player.getServer().getInfo().getName());
- silentformat = chatman.replaceJoinMsgVars(silentformat, player.getName(), player.getServer().getInfo().getName());
+ String serverName = player.getServer().getInfo().getName();
+ quitFormat = new ChatManipulation().replaceJoinMsgVars(quitFormat, player.getName(), serverName);
// Broadcast
- for (ProxiedPlayer onlineplayer : ProxyServer.getInstance().getPlayers()) {
-
- if (!player.hasPermission("multichat.staff.silentjoin")) {
-
- displayMessage(onlineplayer, joinformat);
-
- } else {
-
- if (onlineplayer.hasPermission("multichat.staff.silentjoin") ) {
- displayMessage(onlineplayer, silentformat);
- }
-
- }
+ for (ProxiedPlayer target : ProxyServer.getInstance().getPlayers()) {
+ if (silenceQuit && !target.hasPermission("multichat.staff.silentjoin"))
+ continue;
+ displayMessage(target, quitFormat);
}
}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerConnectedListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerConnectedListener.java
index e8098d35..c428e0b6 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerConnectedListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerConnectedListener.java
@@ -1,7 +1,5 @@
package xyz.olivermartin.multichat.proxy.common.listeners;
-import java.util.UUID;
-
import de.myzelyam.api.vanish.BungeeVanishAPI;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -9,19 +7,16 @@
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
-import xyz.olivermartin.multichat.bungee.ChatManipulation;
-import xyz.olivermartin.multichat.bungee.ChatModeManager;
-import xyz.olivermartin.multichat.bungee.ConfigManager;
-import xyz.olivermartin.multichat.bungee.ConsoleManager;
-import xyz.olivermartin.multichat.bungee.MultiChat;
-import xyz.olivermartin.multichat.bungee.UUIDNameManager;
+import xyz.olivermartin.multichat.bungee.*;
import xyz.olivermartin.multichat.common.MultiChatUtil;
import xyz.olivermartin.multichat.proxy.common.MultiChatProxy;
import xyz.olivermartin.multichat.proxy.common.ProxyJsonUtils;
import xyz.olivermartin.multichat.proxy.common.channels.ChannelManager;
-import xyz.olivermartin.multichat.proxy.common.config.ConfigFile;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
import xyz.olivermartin.multichat.proxy.common.storage.ProxyDataStore;
+import java.util.UUID;
+
public class ProxyServerConnectedListener implements Listener {
private void displayMessage(ProxiedPlayer player, ProxiedPlayer sender, String senderServer, String message) {
@@ -29,10 +24,10 @@ private void displayMessage(ProxiedPlayer player, ProxiedPlayer sender, String s
message = MultiChatUtil.translateColorCodes(message);
if (player.getUniqueId().equals(sender.getUniqueId())) {
- if (MultiChat.legacyServers.contains(senderServer)) message = MultiChatUtil.approximateRGBColorCodes(message);
+ if (ProxyConfigs.CONFIG.isLegacyServer(senderServer)) message = MultiChatUtil.approximateRGBColorCodes(message);
} else {
if (player.getServer() == null) return;
- if (MultiChat.legacyServers.contains(player.getServer().getInfo().getName())) message = MultiChatUtil.approximateRGBColorCodes(message);
+ if (ProxyConfigs.CONFIG.isLegacyServer(player.getServer().getInfo().getName())) message = MultiChatUtil.approximateRGBColorCodes(message);
}
player.sendMessage(ProxyJsonUtils.parseMessage(message));
@@ -101,20 +96,20 @@ public void onServerConnected(ServerConnectedEvent event) {
ds.getJoinedNetwork().add(player.getUniqueId());
// If MultiChat is handling join messages...
- if (ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("showjoin")
- || ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("welcome")
- || ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("private_welcome")) {
+ if (ProxyConfigs.JOIN_MESSAGES.isShowJoin()
+ || ProxyConfigs.JOIN_MESSAGES.isWelcome()
+ || ProxyConfigs.JOIN_MESSAGES.isPrivateWelcome()) {
// PremiumVanish support, return as early as possible to avoid loading unnecessary resources
- if (MultiChat.premiumVanish && MultiChat.hideVanishedStaffInJoin && BungeeVanishAPI.isInvisible(player)) {
+ if (MultiChat.premiumVanish && ProxyConfigs.CONFIG.isPvSilenceJoin() && BungeeVanishAPI.isInvisible(player)) {
return;
}
// Load join message formats from config
- String joinformat = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getString("serverjoin");
- String silentformat = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getString("silentjoin");
- String welcomeMessage = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getString("welcome_message");
- String privateWelcomeMessage = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getString("private_welcome_message");
+ String joinformat = ProxyConfigs.JOIN_MESSAGES.getServerJoin();
+ String silentformat = ProxyConfigs.JOIN_MESSAGES.getSilentJoin();
+ String welcomeMessage = ProxyConfigs.JOIN_MESSAGES.getWelcomeMessage();
+ String privateWelcomeMessage = ProxyConfigs.JOIN_MESSAGES.getPrivateWelcomeMessage();
// Replace the placeholders
ChatManipulation chatman = new ChatManipulation(); // TODO Legacy
@@ -124,8 +119,8 @@ public void onServerConnected(ServerConnectedEvent event) {
privateWelcomeMessage = chatman.replaceJoinMsgVars(privateWelcomeMessage, player.getName(), event.getServer().getInfo().getName());
// Check which messages should be broadcast
- boolean broadcastWelcome = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("welcome", true);
- boolean privateWelcome = ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("private_welcome", false);
+ boolean broadcastWelcome = ProxyConfigs.JOIN_MESSAGES.isWelcome();
+ boolean privateWelcome = ProxyConfigs.JOIN_MESSAGES.isPrivateWelcome();
boolean broadcastJoin = !player.hasPermission("multichat.staff.silentjoin");
// Broadcast
@@ -144,7 +139,7 @@ public void onServerConnected(ServerConnectedEvent event) {
}
- if (ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("showjoin")) {
+ if (ProxyConfigs.JOIN_MESSAGES.isShowJoin()) {
displayMessage(onlineplayer, event.getPlayer(), event.getServer().getInfo().getName(), joinformat);
}
@@ -152,7 +147,7 @@ public void onServerConnected(ServerConnectedEvent event) {
ds.getHiddenStaff().add(player.getUniqueId());
- if (ConfigManager.getInstance().getHandler(ConfigFile.JOIN_MESSAGES).getConfig().getBoolean("showjoin")) {
+ if (ProxyConfigs.JOIN_MESSAGES.isShowJoin()) {
if (onlineplayer.hasPermission("multichat.staff.silentjoin") ) {
displayMessage(onlineplayer, event.getPlayer(), event.getServer().getInfo().getName(), silentformat);
}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerSwitchListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerSwitchListener.java
index 2283f305..4bf8794a 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerSwitchListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/ProxyServerSwitchListener.java
@@ -8,12 +8,10 @@
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
-import xyz.olivermartin.multichat.bungee.ConfigManager;
import xyz.olivermartin.multichat.proxy.common.MultiChatProxy;
import xyz.olivermartin.multichat.proxy.common.ProxyLocalCommunicationManager;
import xyz.olivermartin.multichat.proxy.common.channels.ChannelManager;
-import xyz.olivermartin.multichat.proxy.common.config.ConfigFile;
-import xyz.olivermartin.multichat.proxy.common.config.ConfigValues;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
public class ProxyServerSwitchListener implements Listener {
@@ -48,7 +46,7 @@ public void run() {
ProxyLocalCommunicationManager.sendPlayerDataMessage(event.getPlayer().getName(), MultiChatProxy.getInstance().getChannelManager().getChannel(event.getPlayer()), channelFormat, event.getPlayer().getServer().getInfo(), (event.getPlayer().hasPermission("multichat.chat.colour")||event.getPlayer().hasPermission("multichat.chat.color")||event.getPlayer().hasPermission("multichat.chat.colour.simple")||event.getPlayer().hasPermission("multichat.chat.color.simple")), (event.getPlayer().hasPermission("multichat.chat.colour")||event.getPlayer().hasPermission("multichat.chat.color")||event.getPlayer().hasPermission("multichat.chat.colour.rgb")||event.getPlayer().hasPermission("multichat.chat.color.rgb")));
ProxyLocalCommunicationManager.sendLegacyServerData(event.getPlayer().getServer().getInfo());
- if (ConfigManager.getInstance().getHandler(ConfigFile.CONFIG).getConfig().getBoolean(ConfigValues.Config.FETCH_SPIGOT_DISPLAY_NAMES) == true) {
+ if (ProxyConfigs.CONFIG.isFetchSpigotDisplayNames()) {
ProxiedPlayer player = event.getPlayer();
if (player.getServer() != null) {
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerActionListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerActionListener.java
index ea11a8aa..1d874526 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerActionListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerActionListener.java
@@ -10,8 +10,8 @@
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
-import xyz.olivermartin.multichat.bungee.MessageManager;
import xyz.olivermartin.multichat.common.communication.CommChannels;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
/**
* Listener for communication over the Player Action communication channel
@@ -22,7 +22,7 @@
public class ProxyPlayerActionListener implements Listener {
@EventHandler
- public static void onPluginMessage(PluginMessageEvent event) {
+ public void onPluginMessage(PluginMessageEvent event) {
// Ignore if sent to a different channel
if (!event.getTag().equals(CommChannels.PLAYER_ACTION)) return;
@@ -54,7 +54,7 @@ public static void onPluginMessage(PluginMessageEvent event) {
}
} catch (PatternSyntaxException e) {
- MessageManager.sendMessage(ProxyServer.getInstance().getConsole(), "command_execute_regex");
+ ProxyConfigs.MESSAGES.sendMessage(ProxyServer.getInstance().getConsole(), "command_execute_regex");
}
}
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerChatListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerChatListener.java
index 064231be..ca91d9ea 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerChatListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerChatListener.java
@@ -30,7 +30,7 @@ public class ProxyPlayerChatListener implements Listener {
@SuppressWarnings("unchecked")
@EventHandler
- public static void onPluginMessage(PluginMessageEvent event) {
+ public void onPluginMessage(PluginMessageEvent event) {
// Ignore if sent to a different channel
if (!event.getTag().equals(CommChannels.PLAYER_CHAT)) return;
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerMetaListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerMetaListener.java
index c3319e83..21338f58 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerMetaListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyPlayerMetaListener.java
@@ -24,7 +24,7 @@
public class ProxyPlayerMetaListener implements Listener {
@EventHandler
- public static void onPluginMessage(PluginMessageEvent event) {
+ public void onPluginMessage(PluginMessageEvent event) {
// Ignore if sent to a different channel
if (!event.getTag().equals(CommChannels.PLAYER_META)) return;
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyServerActionListener.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyServerActionListener.java
index 9979698a..59be0632 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyServerActionListener.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/listeners/communication/ProxyServerActionListener.java
@@ -19,7 +19,7 @@
public class ProxyServerActionListener implements Listener {
@EventHandler
- public static void onPluginMessage(PluginMessageEvent event) {
+ public void onPluginMessage(PluginMessageEvent event) {
// Ignore if sent to a different channel
if (!event.getTag().equals(CommChannels.SERVER_ACTION)) return;
diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/storage/files/ProxyIgnoreFileStore.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/storage/files/ProxyIgnoreFileStore.java
index 7b937972..f49a7fed 100644
--- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/storage/files/ProxyIgnoreFileStore.java
+++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/storage/files/ProxyIgnoreFileStore.java
@@ -11,10 +11,8 @@
import java.util.Set;
import java.util.UUID;
-import net.md_5.bungee.config.Configuration;
import xyz.olivermartin.multichat.bungee.ChatControl;
-import xyz.olivermartin.multichat.bungee.ConfigManager;
-import xyz.olivermartin.multichat.proxy.common.config.ConfigFile;
+import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs;
import xyz.olivermartin.multichat.proxy.common.storage.ProxyGenericFileStore;
public class ProxyIgnoreFileStore extends ProxyGenericFileStore {
@@ -26,11 +24,8 @@ public ProxyIgnoreFileStore(String fileName, File fileDirectory) {
@SuppressWarnings("unchecked")
@Override
protected boolean loadFile(File file) {
-
- Configuration config = ConfigManager.getInstance().getHandler(ConfigFile.CHAT_CONTROL).getConfig();
-
- if (config.getBoolean("session_ignore")) {
- ChatControl.setIgnoreMap(new HashMap>());
+ if (ProxyConfigs.CHAT_CONTROL.isSessionIgnore()) {
+ ChatControl.setIgnoreMap(new HashMap<>());
return true;
}
@@ -56,10 +51,7 @@ protected boolean loadFile(File file) {
@Override
protected boolean saveFile(File file) {
-
- Configuration config = ConfigManager.getInstance().getHandler(ConfigFile.CHAT_CONTROL).getConfig();
-
- if (config.getBoolean("session_ignore")) return true;
+ if (ProxyConfigs.CHAT_CONTROL.isSessionIgnore()) return true;
try {
diff --git a/multichat/src/main/resources/aliases.yml b/multichat/src/main/resources/aliases.yml
index c7516d6c..9cf28195 100644
--- a/multichat/src/main/resources/aliases.yml
+++ b/multichat/src/main/resources/aliases.yml
@@ -20,100 +20,100 @@ version: "1.10" #
############################################################
# The admin chat colour command has the following aliases (other than /mcacc)
-acc:
+mcacc:
- acc
# The admin chat command has the following aliases (other than /mcac)
-ac:
+mcac:
- ac
# The announcement command has the following aliases (other than /mcannouncement)
-announcement:
+mcannouncement:
- announcement
- announce
- announcements
# The bulletin command has the following aliases (other than /mcbulletin)
-bulletin:
+mcbulletin:
- bulletin
- bulletins
# The cast command has the following aliases (other than /mccast)
-cast:
+mccast:
- cast
# The channel command has the following aliases (other than /mcchannel)
-channel:
+mcchannel:
- channel
- ch
# The clearchat command has the following aliases (other than /mcclearchat)
-clearchat:
+mcclearchat:
- clearchat
- chatclear
- wipechat
- killchat
# The display command has the following aliases (other than /mcdisplay)
-display:
+mcdisplay:
- display
# The freezechat command has the following aliases (other than /mcfreezechat)
-freezechat:
+mcfreezechat:
- freezechat
- pausechat
- lockchat
- chatlock
# The group chat command has the following aliases (other than /mcgc)
-gc:
+mcgc:
- gc
# The global command has the following aliases (other than /mcglobal)
-global:
+mcglobal:
- global
- g
# The group command has the following aliases (other than /mcgroup)
-group:
+mcgroup:
- group
# The group list command has the following aliases (other than /mcgroups)
-groups:
+mcgroups:
- groups
- grouplist
# The helpme command has the following aliases (other than /mchelpme)
-helpme:
+mchelpme:
- helpme
- helpop
# The ignore command has the following aliases (other than /mcignore)
-ignore:
+mcignore:
- ignore
- blockplayer
# The local command has the following aliases (other than /mclocal)
-local:
+mclocal:
- local
- l
# The localspy command has the following aliases (other than /mclocalspy)
-localspy:
+mclocalspy:
- localspy
- localchatspy
- lspy
# The mod chat colour command has the following aliases (other than /mcmcc)
-mcc:
+mcmcc:
- mcc
# The mod chat command has the following aliases (other than /mcmc)
-mc:
+mcmc:
- mc
# The private message command has the following aliases (other than /mcmsg)
-msg:
+mcmsg:
- msg
- m
- message
@@ -125,7 +125,7 @@ msg:
- pm
# The multichat bypass command has the following aliases (other than /mcbypass)
-bypass:
+mcbypass:
- bypass
- mcb
- multichatbypass
@@ -136,7 +136,7 @@ multichat:
- mcversion
# The multichat execute command has the following aliases (other than /mcexecute)
-execute:
+mcexecute:
- execute
- mce
- multichatexecute
@@ -144,30 +144,30 @@ execute:
- gexecute
# The mute command has the following aliases (other than /mcmute)
-mute:
+mcmute:
- mute
- silence
- multichatmute
# The reply command has the following aliases (other than /mcr)
-r:
+mcr:
- r
- reply
- respond
# The socialspy command has the following aliases (other than /mcsocialspy)
-socialspy:
+mcsocialspy:
- socialspy
- spy
- sspy
# The staff list command has the following aliases (other than /mcstaff)
-staff:
+mcstaff:
- staff
- stafflist
- liststaff
# The usecast command has the following aliases (other than /mcusecast)
-usecast:
+mcusecast:
- usecast
- ccast
diff --git a/multichat/src/main/resources/aliases_fr.yml b/multichat/src/main/resources/aliases_fr.yml
index ffd3bd0b..932d76c5 100644
--- a/multichat/src/main/resources/aliases_fr.yml
+++ b/multichat/src/main/resources/aliases_fr.yml
@@ -22,100 +22,100 @@ version: "1.10" #
############################################################
# La commande 'acc' possède les alias suivants (autres que /mcacc)
-acc:
+mcacc:
- acc
# La commande 'ac' possède les alias suivants (autres que /mcac)
-ac:
+mcac:
- ac
# La commande 'announcement' possède les alias suivants (autres que /mcannouncement)
-announcement:
+mcannouncement:
- announcement
- announce
- announcements
# La commande 'bulletin' possède les alias suivants (autres que /mcbulletin)
-bulletin:
+mcbulletin:
- bulletin
- bulletins
# La commande 'cast' possède les alias suivants (autres que /mccast)
-cast:
+mccast:
- cast
# La commande 'channel' possède les alias suivants (autres que /mcchannel)
-channel:
+mcchannel:
- channel
- ch
# La commande 'clearchat' possède les alias suivants (autres que /mcclearchat)
-clearchat:
+mcclearchat:
- clearchat
- chatclear
- wipechat
- killchat
# La commande 'display' possède les alias suivants (autres que /mcdisplay)
-display:
+mcdisplay:
- display
# La commande 'freezechat' possède les alias suivants (autres que /mcfreezechat)
-freezechat:
+mcfreezechat:
- freezechat
- pausechat
- lockchat
- chatlock
# La commande 'gc' possède les alias suivants (autres que /mcgc)
-gc:
+mcgc:
- gc
# La commande 'global' possède les alias suivants (autres que /mcglobal)
-global:
+mcglobal:
- global
- g
# La commande 'group' possède les alias suivants (autres que /mcgroup)
-group:
+mcgroup:
- group
# La commande 'groups' possède les alias suivants (autres que /mcgroups)
-groups:
+mcgroups:
- groups
- grouplist
# La commande 'helpme' possède les alias suivants (autres que /mchelpme)
-helpme:
+mchelpme:
- helpme
- helpop
# La commande 'ignore' possède les alias suivants (autres que /mcignore)
-ignore:
+mcignore:
- ignore
- blockplayer
# La commande 'local' possède les alias suivants (autres que /mclocal)
-local:
+mclocal:
- local
- l
# La commande 'localspy' possède les alias suivants (autres que /mclocalspy)
-localspy:
+mclocalspy:
- localspy
- localchatspy
- lspy
# La commande 'mcc' possède les alias suivants (autres que /mcmcc)
-mcc:
+mcmcc:
- mcc
# La commande 'mc' possède les alias suivants (autres que /mcmc)
-mc:
+mcmc:
- mc
# La commande 'msg' possède les alias suivants (autres que /mcmsg)
-msg:
+mcmsg:
- msg
- m
- message
@@ -127,7 +127,7 @@ msg:
- pm
# La commande 'bypass' possède les alias suivants (autres que /mcbypass)
-bypass:
+mcbypass:
- bypass
- mcb
- multichatbypass
@@ -138,7 +138,7 @@ multichat:
- mcversion
# La commande 'execute' possède les alias suivants (autres que /mcexecute)
-execute:
+mcexecute:
- execute
- mce
- multichatexecute
@@ -146,30 +146,30 @@ execute:
- gexecute
# La commande 'mute' possède les alias suivants (autres que /mcmute)
-mute:
+mcmute:
- mute
- silence
- multichatmute
# La commande 'r' possède les alias suivants (autres que /mcr)
-r:
+mcr:
- r
- reply
- respond
# La commande 'socialspy' possède les alias suivants (autres que /mcsocialspy)
-socialspy:
+mcsocialspy:
- socialspy
- spy
- sspy
# La commande 'staff' possède les alias suivants (autres que /mcstaff)
-staff:
+mcstaff:
- staff
- stafflist
- liststaff
# La commande 'usecast' possède les alias suivants (autres que /mcusecast)
-usecast:
+mcusecast:
- usecast
- ccast
diff --git a/multichat/src/test/java/xyz/olivermartin/multichat/junit/MultiChatUtilTest.java b/multichat/src/test/java/xyz/olivermartin/multichat/junit/MultiChatUtilTest.java
index f051a5a2..28adeb76 100644
--- a/multichat/src/test/java/xyz/olivermartin/multichat/junit/MultiChatUtilTest.java
+++ b/multichat/src/test/java/xyz/olivermartin/multichat/junit/MultiChatUtilTest.java
@@ -29,67 +29,67 @@ public void shouldTranslateColorCodesCorrectly() {
// ALL
assertEquals("All codes should be translated appropriately",
- "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! §r§x§a§b§c§d§e§fRGB §r§x§a§b§c§d§e§ftoo§r§x§a§b§c§d§e§f!",
+ "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! §r§x§a§b§c§d§e§fRGB §r§x§a§b§c§d§e§ftoo§r§x§a§b§c§d§e§f!",
MultiChatUtil.translateColorCodes(rawMessage));
// ALL #2
assertEquals("All codes should be translated appropriately",
- "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! §r§x§a§b§c§d§e§fRGB §r§x§a§b§c§d§e§ftoo§r§x§a§b§c§d§e§f!",
+ "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! §r§x§a§b§c§d§e§fRGB §r§x§a§b§c§d§e§ftoo§r§x§a§b§c§d§e§f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.ALL));
// SIMPLE
assertEquals("Simple codes should be translated appropriately",
- "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! ABCDEFRGB &xAbCdEftoo&x§a§b§c§d§e§f!",
+ "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! ABCDEFRGB &xAbCdEftoo&x§a§b§c§d§e§f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.SIMPLE));
// SIMPLE COLOR
assertEquals("Simple color codes should be translated appropriately",
- "&r§aHello &kthere! §6<his &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x§a§b§c§d§e§f!",
+ "&r§aHello &kthere! §6<his &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x§a§b§c§d§e§f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.COLOR_SIMPLE));
// ALL COLOR
assertEquals("All color codes should be translated appropriately",
- "§r§aHello &kthere! §6<his &ois &ma &nmessage! §r§x§a§b§c§d§e§fRGB §r§x§a§b§c§d§e§ftoo§r§x§a§b§c§d§e§f!",
+ "§r§aHello &kthere! §6<his &ois &ma &nmessage! §r§x§a§b§c§d§e§fRGB §r§x§a§b§c§d§e§ftoo§r§x§a§b§c§d§e§f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.COLOR_ALL));
// FORMAT UNDERLINE
assertEquals("Underline codes should be translated appropriately",
- "&r&aHello &kthere! &6<his &ois &ma §nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "&r&aHello &kthere! &6<his &ois &ma §nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_UNDERLINE));
// FORMAT ITALIC
assertEquals("Italic codes should be translated appropriately",
- "&r&aHello &kthere! &6<his §ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "&r&aHello &kthere! &6<his §ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_ITALIC));
// FORMAT BOLD
assertEquals("Bold codes should be translated appropriately",
- "&r&aHello &kthere! &6§lthis &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "&r&aHello &kthere! &6§lthis &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_BOLD));
// FORMAT STRIKE
assertEquals("Strike codes should be translated appropriately",
- "&r&aHello &kthere! &6<his &ois §ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "&r&aHello &kthere! &6<his &ois §ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_STRIKE));
// FORMAT OBFUSCATED
assertEquals("Obfuscation codes should be translated appropriately",
- "&r&aHello §kthere! &6<his &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "&r&aHello §kthere! &6<his &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_OBFUSCATED));
// FORMAT RESET
assertEquals("Reset codes should be translated appropriately",
- "§r&aHello &kthere! &6<his &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "§r&aHello &kthere! &6<his &ois &ma &nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_RESET));
// FORMAT ALL
assertEquals("All format codes should be translated appropriately",
- "§r&aHello §kthere! &6§lthis §ois §ma §nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
+ "§r&aHello §kthere! &6§lthis §ois §ma §nmessage! ABCDEFRGB &xAbCdEftoo&x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.FORMAT_ALL));
// X
assertEquals("All X codes should be translated appropriately",
- "&r&aHello &kthere! &6<his &ois &ma &nmessage! &r§x&a&b&c&d&e&fRGB &r§x&a&b&c&d&e&ftoo&r§x&a&b&c&d&e&f!",
+ "&r&aHello &kthere! &6<his &ois &ma &nmessage! &r§x&a&b&c&d&e&fRGB &r§x&a&b&c&d&e&ftoo&r§x&a&b&c&d&e&f!",
MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.X));
}
@@ -119,7 +119,7 @@ public void shouldApproximateRGBColorCodesCorrectly() {
String approximated = MultiChatUtil.approximateRGBColorCodes(translated);
assertEquals("Translated RGB color codes should be approximated to nearest minecraft equivalent",
- "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! §7RGB §7too§7!",
+ "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! §7RGB §7too§7!",
approximated);
String simpleTranslated = MultiChatUtil.translateColorCodes(rawMessage, TranslateMode.SIMPLE);
@@ -127,7 +127,7 @@ public void shouldApproximateRGBColorCodesCorrectly() {
String simpleApproximated = MultiChatUtil.approximateRGBColorCodes(simpleTranslated);
assertEquals("Non translated RGB color codes should NOT be approximated to nearest minecraft equivalent",
- "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! ABCDEFRGB &xAbCdEftoo&x§a§b§c§d§e§f!",
+ "§r§aHello §kthere! §6§lthis §ois §ma §nmessage! ABCDEFRGB &xAbCdEftoo&x§a§b§c§d§e§f!",
simpleApproximated);
String jsonMessage = "{\"text\":\"hello world\", \"color\":\"#ABCDEF\"}";