package com.alttd.chat.config; import com.alttd.chat.objects.channels.CustomChannel; import com.alttd.chat.util.Utility; import com.google.common.collect.Lists; import io.leangen.geantyref.TypeToken; import net.kyori.adventure.text.Component; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationOptions; import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.yaml.NodeStyle; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; import java.util.regex.Pattern; public final class Config { private static final Pattern PATH_PATTERN = Pattern.compile("\\."); private static final String HEADER = ""; private static File CONFIG_FILE; public static ConfigurationNode config; public static YamlConfigurationLoader configLoader; static int version; static boolean verbose; public static File CONFIGPATH; public static void init() { CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "ChatPlugin"); CONFIG_FILE = new File(CONFIGPATH, "config.yml"); configLoader = YamlConfigurationLoader.builder() .file(CONFIG_FILE) .nodeStyle(NodeStyle.BLOCK) .build(); if (!CONFIG_FILE.getParentFile().exists()) { if(!CONFIG_FILE.getParentFile().mkdirs()) { return; } } if (!CONFIG_FILE.exists()) { try { if(!CONFIG_FILE.createNewFile()) { return; } } catch (IOException error) { error.printStackTrace(); } } try { config = configLoader.load(ConfigurationOptions.defaults().header(HEADER).shouldCopyDefaults(false)); } catch (IOException e) { e.printStackTrace(); } verbose = getBoolean("verbose", true); version = getInt("config-version", 1); readConfig(Config.class, null); try { configLoader.save(config); } catch (IOException e) { e.printStackTrace(); } } public static void readConfig(Class clazz, Object instance) { for (Method method : clazz.getDeclaredMethods()) { if (Modifier.isPrivate(method.getModifiers())) { if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) { try { method.setAccessible(true); method.invoke(instance); } catch (InvocationTargetException | IllegalAccessException ex) { ex.printStackTrace(); } } } } try { configLoader.save(config); } catch (IOException ex) { ex.printStackTrace(); } } public static void saveConfig() { try { configLoader.save(config); } catch (IOException ex) { ex.printStackTrace(); } } private static Object[] splitPath(String key) { return PATH_PATTERN.split(key); } private static void set(String path, Object def) { if(config.node(splitPath(path)).virtual()) { try { config.node(splitPath(path)).set(def); } catch (SerializationException e) { e.printStackTrace(); } } } private static void setString(String path, String def) { try { if(config.node(splitPath(path)).virtual()) config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def); } catch(SerializationException ex) { ex.printStackTrace(); } } private static boolean getBoolean(String path, boolean def) { set(path, def); return config.node(splitPath(path)).getBoolean(def); } private static double getDouble(String path, double def) { set(path, def); return config.node(splitPath(path)).getDouble(def); } private static int getInt(String path, int def) { set(path, def); return config.node(splitPath(path)).getInt(def); } private static String getString(String path, String def) { setString(path, def); return config.node(splitPath(path)).getString(def); } private static Long getLong(String path, Long def) { set(path, def); return config.node(splitPath(path)).getLong(def); } private static List getList(String path, T def) { try { set(path, def); return config.node(splitPath(path)).getList(TypeToken.get(String.class)); } catch(SerializationException ex) { ex.printStackTrace(); } return new ArrayList<>(); } private static ConfigurationNode getNode(String path) { if(config.node(splitPath(path)).virtual()) { //new RegexConfig("Dummy"); } config.childrenMap(); return config.node(splitPath(path)); } /** ONLY EDIT ANYTHING BELOW THIS LINE **/ public static List PREFIXGROUPS = new ArrayList<>(); public static List CONFLICTINGPREFIXGROUPS = new ArrayList<>(); public static List STAFFGROUPS = new ArrayList<>(); public static String MINIMIUMSTAFFRANK = "trainee"; public static String CONSOLENAME = "Console"; public static UUID CONSOLEUUID = UUID.randomUUID(); public static int EMOTELIMIT = 3; public static String MENTIONPLAYERTAG = "@"; private static void settings() { PREFIXGROUPS = getList("settings.prefix-groups", Lists.newArrayList("discord", "socialmedia", "eventteam", "eventleader", "youtube", "twitch", "developer")); CONFLICTINGPREFIXGROUPS = getList("settings.prefix-conflicts-groups", Lists.newArrayList("eventteam", "eventleader")); STAFFGROUPS = getList("settings.staff-groups", Lists.newArrayList("trainee", "moderator", "headmod", "admin", "manager", "owner")); CONSOLENAME = getString("settings.console-name", CONSOLENAME); CONSOLEUUID = UUID.fromString(getString("settings.console-uuid", CONSOLEUUID.toString())); MINIMIUMSTAFFRANK = getString("settings.minimum-staff-rank", MINIMIUMSTAFFRANK); EMOTELIMIT = getInt("settings.emote-limit", EMOTELIMIT); MENTIONPLAYERTAG = getString("settings.mention-player-tag", MENTIONPLAYERTAG); } public static List MESSAGECOMMANDALIASES = new ArrayList<>(); public static List REPLYCOMMANDALIASES = new ArrayList<>(); public static String MESSAGESENDER = " >(Me -> ) "; public static String MESSAGERECIEVER = " >( on -> Me) "; public static String MESSAGESPY = "( -> ) "; public static String RECEIVER_DOES_NOT_EXIST = " is not a valid player."; private static void messageCommand() { MESSAGECOMMANDALIASES.clear(); REPLYCOMMANDALIASES.clear(); MESSAGECOMMANDALIASES = getList("commands.message.aliases", Lists.newArrayList("msg", "whisper", "tell")); REPLYCOMMANDALIASES = getList("commands.reply.aliases", Lists.newArrayList("r")); MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER); MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER); MESSAGESPY = getString("commands.message.spy-message", MESSAGESPY); RECEIVER_DOES_NOT_EXIST = getString("commands.message.receiver-does-not-exist", RECEIVER_DOES_NOT_EXIST); } public static String GCFORMAT = " >to Global: "; public static String GCPERMISSION = "proxy.globalchat"; public static List GCALIAS = new ArrayList<>(); public static String GCNOTENABLED = "You don't have global chat enabled."; public static String GCONCOOLDOWN = "You have to wait seconds before using this feature again."; public static int GCCOOLDOWN = 30; private static void globalChat() { GCFORMAT = getString("commands.globalchat.format", GCFORMAT); GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION); GCALIAS.clear(); GCALIAS = getList("commands.globalchat.alias", Lists.newArrayList("gc", "global")); GCNOTENABLED = getString("commands.globalchat.not-enabled", GCNOTENABLED); GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN); } public static String CHATFORMAT = " > >: "; public static String URLFORMAT = ">"; private static void Chat() { CHATFORMAT = getString("chat.format", CHATFORMAT); URLFORMAT = getString("chat.urlformat", URLFORMAT); } public static List GACECOMMANDALIASES = new ArrayList<>(); public static String GACFORMAT = "( on -> Team) "; private static void globalAdminChat() { GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg")); GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT); } public static String MESSAGECHANNEL = "altitude:chatplugin"; private static void messageChannels() { MESSAGECHANNEL = getString("settings.message-channel", MESSAGECHANNEL); } public static ConfigurationNode REGEXNODE = null; private static void RegexNOde() { REGEXNODE = getNode("regex-settings"); } public static String SERVERSWTICHMESSAGEFROM = "* comes from ..."; public static String SERVERSWTICHMESSAGETO = "* leaves to ..."; public static String SERVERJOINMESSAGE = "* appears from thin air..."; public static String SERVERLEAVEMESSAGE = "* vanishes in the mist..."; private static void JoinLeaveMessages() { SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM); SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO); SERVERJOINMESSAGE = getString("messages.join-server", SERVERJOINMESSAGE); SERVERLEAVEMESSAGE = getString("messages.leave-server", SERVERLEAVEMESSAGE); } public static String PARTY_FORMAT = "(\"> → ) "; public static String PARTY_SPY = "PC: : "; public static String NO_PERMISSION = "You don't have permission to use this command."; public static String NO_CONSOLE = "This command can not be used by console"; public static String CREATED_PARTY = "You created a chat party called: " + "'' with the password: ''"; public static String NOT_IN_A_PARTY = "You're not in a chat party."; public static String NOT_YOUR_PARTY = "You don't own this chat party."; public static String NOT_A_PARTY = "This chat party does not exist."; public static String PARTY_EXISTS = "A chat party called already exists."; public static String INVALID_PLAYER = "Invalid player."; public static String NOT_ONLINE = " must be online to receive an invite."; public static String INVALID_PASSWORD = "Invalid password."; public static String JOINED_PARTY = "You joined !"; public static String PLAYER_JOINED_PARTY = " joined !"; public static String NOTIFY_FINDING_NEW_OWNER = "Since you own this chat party a new party owner will be chosen."; public static String LEFT_PARTY = "You have left the chat party!"; public static String OWNER_LEFT_PARTY = "[ChatParty]: left the chat party, the new party owner is "; public static String PLAYER_LEFT_PARTY = "[ChatParty]: left the chat party!"; public static String NEW_PARTY_OWNER = "[ChatParty]: transferred the party to !"; public static String CANT_REMOVE_PARTY_OWNER = "You can't remove yourself, please leave instead."; public static String REMOVED_FROM_PARTY = "You were removed from the '' chat party."; public static String REMOVED_USER_FROM_PARTY = "You removed from the chat party!"; public static String NOT_A_PARTY_MEMBER = " is not a member of your party!"; public static String ALREADY_IN_PARTY = "You're already in a party!"; public static String ALREADY_IN_THIS_PARTY = "You're already in !"; public static String SENT_PARTY_INV = "You send a chat party invite to !"; public static String JOIN_PARTY_CLICK_MESSAGE = " '>" + "You received an invite to join , click this message to accept."; public static String PARTY_MEMBER_LOGGED_ON = "[ChatParty] joined Altitude..."; public static String PARTY_MEMBER_LOGGED_OFF = "[ChatParty] left Altitude..."; public static String RENAMED_PARTY = "[ChatParty] changed the party name from to !"; public static String CHANGED_PASSWORD = "Password was set to "; public static String DISBAND_PARTY_CONFIRM = "Are you sure you want to disband your party? " + "Type /party disband confirm to confirm."; public static String DISBANDED_PARTY = "[ChatParty] has disbanded , everyone has been removed."; public static String PARTY_INFO = """ Chat party info: Name: Password: Owner: Members: """; public static Component ONLINE_PREFIX = null; public static Component OFFLINE_PREFIX = null; public static String PARTY_TOGGLED = "Party chat toggled ."; private static void party() { PARTY_FORMAT = getString("party.format", PARTY_FORMAT); PARTY_SPY = getString("party.spy", PARTY_SPY); NO_PERMISSION = getString("party.messages.no-permission", NO_PERMISSION); NO_CONSOLE = getString("party.messages.no-console", NO_CONSOLE); CREATED_PARTY = getString("party.messages.created-party", CREATED_PARTY); NOT_IN_A_PARTY = getString("party.messages.not-in-a-party", NOT_IN_A_PARTY); NOT_YOUR_PARTY = getString("party.messages.not-your-party", NOT_YOUR_PARTY); NOT_A_PARTY = getString("party.messages.not-a-party", NOT_A_PARTY); INVALID_PLAYER = getString("party.messages.invalid-player", INVALID_PLAYER); NOT_ONLINE = getString("party.messages.not-online", NOT_ONLINE); INVALID_PASSWORD = getString("party.messages.invalid-password", INVALID_PASSWORD); JOINED_PARTY = getString("party.messages.joined-party", JOINED_PARTY); PLAYER_JOINED_PARTY = getString("party.messages.player-joined-party", PLAYER_JOINED_PARTY); NOTIFY_FINDING_NEW_OWNER = getString("party.messages.notify-finding-new-owner", NOTIFY_FINDING_NEW_OWNER); LEFT_PARTY = getString("party.messages.left-party", LEFT_PARTY); OWNER_LEFT_PARTY = getString("party.messages.owner-left-party", OWNER_LEFT_PARTY); NEW_PARTY_OWNER = getString("party.messages.new-owner", NEW_PARTY_OWNER); CANT_REMOVE_PARTY_OWNER = getString("party.messages.cant-remove-owner", CANT_REMOVE_PARTY_OWNER); REMOVED_FROM_PARTY = getString("party.messages.removed-from-party", REMOVED_FROM_PARTY); NOT_A_PARTY_MEMBER = getString("party.messages.not-a-party-member", NOT_A_PARTY_MEMBER); JOIN_PARTY_CLICK_MESSAGE = getString("party.messages.join-party-click-message", JOIN_PARTY_CLICK_MESSAGE); SENT_PARTY_INV = getString("party.messages.sent-party-invite", SENT_PARTY_INV); PARTY_MEMBER_LOGGED_ON = getString("party.messages.party-member-logged-on", PARTY_MEMBER_LOGGED_ON); PARTY_MEMBER_LOGGED_OFF = getString("party.messages.party-member-logged-off", PARTY_MEMBER_LOGGED_OFF); RENAMED_PARTY = getString("party.messages.renamed-party", RENAMED_PARTY); CHANGED_PASSWORD = getString("party.messages.changed-password", CHANGED_PASSWORD); DISBAND_PARTY_CONFIRM = getString("party.messages.disband-party-confirm", DISBAND_PARTY_CONFIRM); DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY); PARTY_INFO = getString("party.messages.party-info", PARTY_INFO); ALREADY_IN_THIS_PARTY = getString("party.messages.already-in-this-party", ALREADY_IN_THIS_PARTY); ONLINE_PREFIX = Utility.parseMiniMessage(getString("party.messages.online-prefix", "")); OFFLINE_PREFIX = Utility.parseMiniMessage(getString("party.messages.offline-prefix", "")); PARTY_TOGGLED = getString("party.messages.party-toggled", PARTY_TOGGLED); } public static String PARTY_HELP_WRAPPER = "ChatParty help:\n"; public static String PARTY_HELP_HELP = "Show this menu: /party help"; public static String PARTY_HELP_CREATE = "Create a party: /party create "; public static String PARTY_HELP_INFO = "Show info about your current party: /party info"; public static String PARTY_HELP_INVITE = "Invite a user to your party: /party invite "; public static String PARTY_HELP_JOIN = "Join a party: /party join "; public static String PARTY_HELP_LEAVE = "Leave your current party: /party leave"; public static String PARTY_HELP_NAME = "Change the name of your party: /party name "; public static String PARTY_HELP_OWNER = "Change the owner of your party: /party owner "; public static String PARTY_HELP_PASSWORD = "Change the password of your party: /party password "; public static String PARTY_HELP_REMOVE = "Remove a member from your party: /party remove "; public static String PARTY_HELP_DISBAND = "Remove everyone from your party and disband it: /party disband"; public static String PARTY_HELP_CHAT = "Talk in party chat: /p "; private static void partyHelp() { PARTY_HELP_WRAPPER = getString("party.help.wrapper", PARTY_HELP_WRAPPER); PARTY_HELP_HELP = getString("party.help.help", PARTY_HELP_HELP); PARTY_HELP_CREATE = getString("party.help.create", PARTY_HELP_CREATE); PARTY_HELP_INFO = getString("party.help.info", PARTY_HELP_INFO); PARTY_HELP_INVITE = getString("party.help.invite", PARTY_HELP_INVITE); PARTY_HELP_JOIN = getString("party.help.join", PARTY_HELP_JOIN); PARTY_HELP_LEAVE = getString("party.help.leave", PARTY_HELP_LEAVE); PARTY_HELP_NAME = getString("party.help.name", PARTY_HELP_NAME); PARTY_HELP_OWNER = getString("party.help.owner", PARTY_HELP_OWNER); PARTY_HELP_PASSWORD = getString("party.help.password", PARTY_HELP_PASSWORD); PARTY_HELP_REMOVE = getString("party.help.remove", PARTY_HELP_REMOVE); PARTY_HELP_DISBAND = getString("party.help.disband", PARTY_HELP_DISBAND); PARTY_HELP_CHAT = getString("party.help.chat", PARTY_HELP_CHAT); } public static String CUSTOM_CHANNEL_TOGGLED = "Toggled ."; public static Component TOGGLED_ON = null; public static Component TOGGLED_OFF = null; private static void chatChannels() { ConfigurationNode node = getNode("chat-channels"); if (node.empty()) { getString("chat-channels.ac.format", " >to : "); getList("chat-channels.ac.servers", List.of("lobby")); getBoolean("chat-channels.ac.proxy", false); node = getNode("chat-channels"); } for (ConfigurationNode configurationNode : node.childrenMap().values()) { String channelName = Objects.requireNonNull(configurationNode.key()).toString(); String key = "chat-channels." + channelName + "."; new CustomChannel(channelName, getString(key + "format", ""), getList(key + "servers", Collections.EMPTY_LIST), getBoolean(key + "proxy", false)); } CUSTOM_CHANNEL_TOGGLED = getString("chat-channels-messages.channel-toggled", CUSTOM_CHANNEL_TOGGLED); TOGGLED_ON = Utility.parseMiniMessage(getString("chat-channels-messages.channel-on", "on")); TOGGLED_OFF = Utility.parseMiniMessage(getString("chat-channels-messages.channel-off", "off")); } public static String SERVERMUTEPERMISSION = "chat.command.mute-server"; public static String SPYPERMISSION = "chat.socialspy"; private static void permissions() { SERVERMUTEPERMISSION = getString("permissions.server-mute", SERVERMUTEPERMISSION); SPYPERMISSION = getString("permissions.spy-permission", SPYPERMISSION); } public static String IP = "0.0.0.0"; public static String PORT = "3306"; public static String DATABASE = "database"; public static String USERNAME = "root"; public static String PASSWORD = "root"; private static void database() { IP = getString("database.ip", IP); PORT = getString("database.port", PORT); DATABASE = getString("database.name", DATABASE); USERNAME = getString("database.username", USERNAME); PASSWORD = getString("database.password", PASSWORD); } public static String NOTIFICATIONFORMAT = "[] "; private static void notificationSettings() { NOTIFICATIONFORMAT = getString("settings.blockedmessage-notification", NOTIFICATIONFORMAT); } public static String mailHeader = "===== List Mails ====='"; public static String mailBody = "From: [] '> day(s) ago: "; public static String mailFooter = "======================"; public static String mailNoUser = "A player with this name hasn't logged in recently."; public static String mailReceived = "New mail from , click to view"; public static String mailUnread = "You have unread mail, click to view it."; public static String mailSent = "Successfully send mail to : <#2e8b57>"; public static List mailCommandAlias = new ArrayList<>(); private static void mailSettings() { mailHeader = getString("settings.mail.header", mailHeader); mailBody = getString("settings.mail.message", mailBody); mailFooter = getString("settings.mail.footer", mailFooter); mailCommandAlias = getList("settings.mail.command-aliases", Lists.newArrayList("gmail")); mailReceived = getString("settings.mail.mail-received", mailReceived); mailUnread = getString("settings.mail.mail-unread", mailUnread); mailSent = getString("settings.mail.mail-sent", mailSent); } public static HashMap serverChannelId = new HashMap<>(); public static String REPORT_SENT = "Your report was sent, staff will contact you asap to help resolve your issue!"; public static String REPORT_TOO_SHORT = "Please ensure your report is descriptive. We require at least 3 words per report"; private static void loadChannelIds() { serverChannelId.clear(); serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1)); ConfigurationNode node = config.node("discord-channel-id"); Map objectMap = node.childrenMap(); for (Object o : objectMap.keySet()) { String key = (String) o; if (key.equalsIgnoreCase("general")) continue; ConfigurationNode configurationNode = objectMap.get(o); long channelId = configurationNode.getLong(); serverChannelId.put(key.toLowerCase(), channelId); } REPORT_SENT = getString("messages.report-sent", REPORT_SENT); REPORT_TOO_SHORT = getString("messages.report-too-short", REPORT_TOO_SHORT); } public static List SILENT_JOIN_COMMAND_ALIASES = new ArrayList<>(); public static String SILENT_JOIN_NO_SERVER = "Unable to find destination server"; public static String SILENT_JOIN_JOINING = "Sending you to silently."; public static String SILENT_JOIN_JOINED_FROM = "* silent joined from ..."; public static String SILENT_JOIN_JOINED = "* silent joined..."; private static void silentJoinCommand() { SILENT_JOIN_COMMAND_ALIASES = getList("commands.silent-join.aliases", Lists.newArrayList("sj")); SILENT_JOIN_NO_SERVER = getString("commands.silent-join.no-server", SILENT_JOIN_NO_SERVER); SILENT_JOIN_JOINING = getString("commands.silent-join.joining", SILENT_JOIN_JOINING); SILENT_JOIN_JOINED_FROM = getString("commands.silent-join.joined-from", SILENT_JOIN_JOINED_FROM); SILENT_JOIN_JOINED = getString("commands.silent-join.joined", SILENT_JOIN_JOINED); } public static String HELP_REPORT = "/report "; public static String FIRST_JOIN = "* Welcome to Altitude! They've joined for the first time."; private static void loadMessages() { HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT); FIRST_JOIN = getString("settings.first-join.message", FIRST_JOIN); } public static String EMOTELIST_HEADER = "Available Chat Emotes"; public static String EMOTELIST_ITEM = "\"> : "; public static String EMOTELIST_FOOTER = "----<< Prev / Next >>----"; private static void emoteListCommand() { EMOTELIST_HEADER = getString("commands.emotelist.header", EMOTELIST_HEADER); EMOTELIST_ITEM = getString("commands.emotelist.item", EMOTELIST_ITEM); EMOTELIST_FOOTER = getString("commands.emotelist.footer", EMOTELIST_FOOTER); } // nicknames TODO minimessage for colors and placeholders public static String NICK_CHANGED = "Your nickname was changed to ."; public static String NICK_NOT_CHANGED = "Your nickname request was denied."; public static String NICK_RESET = "Nickname changed back to normal."; public static String NICK_CHANGED_OTHERS = "'s nickname was changed to ."; public static String NICK_TARGET_NICK_CHANGE = "Your nickname was changed to by "; public static String NICK_RESET_OTHERS = "'s nickname was reset back to normal."; public static String NICK_INVALID_CHARACTERS = "You can only use letters and numbers in nicknames."; public static String NICK_INVALID_LENGTH = "Nicknames need to be between 3 to 16 characters long."; public static String NICK_PLAYER_NOT_ONLINE = "That player is not online."; public static String NICK_BLOCKED_COLOR_CODES = "You have blocked color codes in that nickname."; public static String NICK_USER_NOT_FOUND = "Failed to set nickname from player, try again from a server this player has been on before."; public static String NICK_ACCEPTED = "You accepted 's nickname. They are now called ."; public static String NICK_DENIED = "You denied 's nickname. They are still called ."; public static String NICK_ALREADY_HANDLED = "'s nickname was already accepted or denied."; public static String NICK_NO_LUCKPERMS = "Due to an issue with LuckPerms /nick try won't work at the moment."; public static String NICK_TOO_SOON = "Please wait