diff --git a/multichat/dependency-reduced-pom.xml b/multichat/dependency-reduced-pom.xml index b582160f..d024b680 100644 --- a/multichat/dependency-reduced-pom.xml +++ b/multichat/dependency-reduced-pom.xml @@ -3,39 +3,35 @@ 4.0.0 xyz.olivermartin.multichat multichat - 1.9.6 + 1.9.9 maven-shade-plugin - 3.1.0 + 3.2.4 package shade + + + + com.zaxxer.hikari + shaded.com.zaxxer.hikari + + + - - - - com.zaxxer.hikari - xyz.olivermartin.shadedlib.hikari - - - org.slf4j - xyz.olivermartin.shadedlib.slf4j - - - maven-compiler-plugin - 3.1 + 3.8.1 - 1.8 - 1.8 + 11 + 11 @@ -46,8 +42,9 @@ https://repo.codemc.org/repository/maven-public - sponge - http://repo.spongepowered.org/maven + sponge-repo + Sponge Maven Repository + https://repo.spongepowered.org/maven bungeecord-repo @@ -69,6 +66,10 @@ jitpack.io https://jitpack.io + + velocity + https://nexus.velocitypowered.com/repository/maven-public/ + @@ -77,221 +78,66 @@ 3.27.2.1 provided - - org.spongepowered - spongeapi - 7.1.0 - provided - - - guava - com.google.guava - - - error_prone_annotations - com.google.errorprone - - - gson - com.google.code.gson - - - commons-lang3 - org.apache.commons - - - jsr305 - com.google.code.findbugs - - - guice - com.google.inject - - - caffeine - com.github.ben-manes.caffeine - - - guava - com.github.ben-manes.caffeine - - - plugin-meta - org.spongepowered - - - configurate-hocon - org.spongepowered - - - configurate-gson - org.spongepowered - - - configurate-yaml - org.spongepowered - - - flow-math - com.flowpowered - - - flow-noise - com.flowpowered - - - asm - org.ow2.asm - - - net.md-5 bungeecord-api - 1.16-R0.4-SNAPSHOT + 1.18-R0.1-SNAPSHOT provided - - - bungeecord-chat - net.md-5 - - - bungeecord-config - net.md-5 - - - bungeecord-event - net.md-5 - - - bungeecord-protocol - net.md-5 - - - netty-transport-native-unix-common - io.netty - - - snakeyaml - org.yaml - - - guava - com.google.guava - - net.md-5 bungeecord-api - 1.16-R0.4-SNAPSHOT + 1.18-R0.1-SNAPSHOT javadoc provided - - - bungeecord-chat - net.md-5 - - - bungeecord-config - net.md-5 - - - bungeecord-event - net.md-5 - - - bungeecord-protocol - net.md-5 - - - netty-transport-native-unix-common - io.netty - - - snakeyaml - org.yaml - - - guava - com.google.guava - - org.spigotmc spigot-api - 1.16.1-R0.1-SNAPSHOT + 1.18.1-R0.1-SNAPSHOT provided - - - commons-lang - commons-lang - - - gson - com.google.code.gson - - - bungeecord-chat - net.md-5 - - - snakeyaml - org.yaml - - - guava - com.google.guava - - net.milkbowl.vault VaultAPI - 1.6 + 1.7 provided - - - bukkit - org.bukkit - - me.clip placeholderapi - 2.9.2 + 2.11.1 + provided + + + org.spongepowered + spongeapi + 7.2.0 provided com.github.rojo8399 PlaceholderAPI - master-SNAPSHOT + master-4.5.1-gb58a67b-1 provided - - - reflections - org.reflections - - - configurate-hocon - ninja.leaping.configurate - - - com.github.MyzelYam + com.github.LeonMangler PremiumVanishAPI - 2.0.2 + 2.7.3 + provided + + + com.velocitypowered + velocity-api + 3.1.0 + provided + + + org.projectlombok + lombok + 1.18.22 provided - - - jsr305 - com.google.code.findbugs - - - diff --git a/multichat/pom.xml b/multichat/pom.xml index afe5c8f5..6c4c2c5d 100644 --- a/multichat/pom.xml +++ b/multichat/pom.xml @@ -1,15 +1,11 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 xyz.olivermartin.multichat multichat - 1.9.7 - - - UTF-8 - + 1.9.9 @@ -19,8 +15,9 @@ - sponge - http://repo.spongepowered.org/maven + sponge-repo + Sponge Maven Repository + https://repo.spongepowered.org/maven @@ -48,6 +45,12 @@ https://jitpack.io + + + velocity + https://nexus.velocitypowered.com/repository/maven-public/ + + @@ -55,25 +58,21 @@ org.apache.maven.plugins maven-shade-plugin - 3.1.0 - - - - com.zaxxer.hikari - xyz.olivermartin.shadedlib.hikari - - - org.slf4j - xyz.olivermartin.shadedlib.slf4j - - - + 3.2.4 package shade + + + + com.zaxxer.hikari + shaded.com.zaxxer.hikari + + + @@ -81,10 +80,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 + 3.8.1 - 1.8 - 1.8 + 11 + 11 @@ -95,7 +94,7 @@ com.zaxxer HikariCP - 2.6.1 + 5.0.0 @@ -111,17 +110,10 @@ provided - - org.spongepowered - spongeapi - 7.1.0 - provided - - net.md-5 bungeecord-api - 1.16-R0.4-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar provided @@ -129,7 +121,7 @@ net.md-5 bungeecord-api - 1.16-R0.4-SNAPSHOT + 1.18-R0.1-SNAPSHOT javadoc provided @@ -137,38 +129,60 @@ org.spigotmc spigot-api - 1.16.1-R0.1-SNAPSHOT + 1.18.1-R0.1-SNAPSHOT provided net.milkbowl.vault VaultAPI - 1.6 + 1.7 provided me.clip placeholderapi - 2.9.2 + 2.11.1 + provided + + + + org.spongepowered + spongeapi + 7.2.0 + jar provided com.github.rojo8399 PlaceholderAPI - master-SNAPSHOT + master-4.5.1-gb58a67b-1 provided + - com.github.MyzelYam + com.github.LeonMangler PremiumVanishAPI - 2.0.2 + 2.7.3 provided - + + + com.velocitypowered + velocity-api + 3.1.0 + provided + + + org.projectlombok + lombok + 1.18.22 + provided + + \ No newline at end of file diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/Channel.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/Channel.java index 953a453d..1c80b91a 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/Channel.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/Channel.java @@ -15,11 +15,12 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import xyz.olivermartin.multichat.bungee.events.PostBroadcastEvent; import xyz.olivermartin.multichat.bungee.events.PostGlobalChatEvent; +import xyz.olivermartin.multichat.proxy.common.ServerGroups; /** * Channel *

A class to represent a chat channel and control the messages sent etc.

- * + * * @author Oliver Martin (Revilo410) * */ @@ -132,12 +133,14 @@ public void setFormat(String format) { } public void sendMessage(ProxiedPlayer sender, String message, String format) { - DebugManager.log("CHANNEL #" + getName() + ": Got a message for the channel"); DebugManager.log("CHANNEL #" + getName() + ": SENDER = " + sender.getName()); DebugManager.log("CHANNEL #" + getName() + ": MESSAGE = " + message); DebugManager.log("CHANNEL #" + getName() + ": FORMAT = " + format); + Boolean serverGroupsEnabled = ServerGroups.getServerGroupsEnabled(); + ArrayList serverGroupList = ServerGroups.getServerGroupList(sender); + for (ProxiedPlayer receiver : ProxyServer.getInstance().getPlayers()) { if (receiver != null && sender != null) { @@ -147,28 +150,40 @@ public void sendMessage(ProxiedPlayer sender, String message, String format) { if (sender.getServer() != null && receiver.getServer() != null) { if ( (whitelistMembers && members.contains(receiver.getUniqueId())) || (!whitelistMembers && !members.contains(receiver.getUniqueId()))) { - if ( (whitelistServers && servers.contains(receiver.getServer().getInfo().getName())) || (!whitelistServers && !servers.contains(receiver.getServer().getInfo().getName()))) { - if (!ChatControl.ignores(sender.getUniqueId(), receiver.getUniqueId(), "global_chat")) { - if (!receiver.getServer().getInfo().getName().equals(sender.getServer().getInfo().getName())) { - receiver.sendMessage(buildFormat(sender,receiver,format,message)); + if (!serverGroupsEnabled || serverGroupsEnabled == null) { + + if ((whitelistServers && servers.contains(receiver.getServer().getInfo().getName())) || (!whitelistServers && !servers.contains(receiver.getServer().getInfo().getName()))) { + + if (!ChatControl.ignores(sender.getUniqueId(), receiver.getUniqueId(), "global_chat")) { + + if (!receiver.getServer().getInfo().getName().equals(sender.getServer().getInfo().getName())) { + receiver.sendMessage(buildFormat(sender, receiver, format, message)); + } else { + // If they are on the same server, this message will already have been displayed locally. + } } else { - // If they are on the same server, this message will already have been displayed locally. + ChatControl.sendIgnoreNotifications(receiver, sender, "global_chat"); + } + } + } else { + if (serverGroupList != null && serverGroupList.contains(receiver.getServer().getInfo().getName())) { + if (!ChatControl.ignores(sender.getUniqueId(), receiver.getUniqueId(), "global_chat")) { + + if (!receiver.getServer().getInfo().getName().equals(sender.getServer().getInfo().getName())) { + receiver.sendMessage(buildFormat(sender, receiver, format, message)); + } else { + // If they are on the same server, this message will already have been displayed locally. + } + } else { + ChatControl.sendIgnoreNotifications(receiver, sender, "global_chat"); } - } else { - ChatControl.sendIgnoreNotifications(receiver, sender, "global_chat"); } - } - } - } - } - } - } // Trigger PostGlobalChatEvent @@ -179,7 +194,6 @@ public void sendMessage(ProxiedPlayer sender, String message, String format) { } public void sendMessage(String message, CommandSender sender) { - for (ProxiedPlayer receiver : ProxyServer.getInstance().getPlayers()) { if (receiver != null && sender != null) { if (receiver.getServer() != null) { diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java index 9cfad8cd..45ec5046 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java @@ -7,6 +7,7 @@ import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.config.Configuration; +import org.bukkit.entity.Player; /** * Message Manager @@ -410,12 +411,28 @@ public static String getMessage(String id) { public static void sendMessage(CommandSender sender, String id) { updatePrefix(); - sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', prefix + MultiChatUtil.reformatRGB(getMessage(id))))); + + Player player; + String server = ""; + if (sender instanceof Player) { + player = (Player) sender; + server = player.getServer().getName(); + } + + sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', prefix + MultiChatUtil.reformatRGB(getMessage(id).replaceAll("%SERVER%", server))))); } public static void sendSpecialMessage(CommandSender sender, String id, String special) { updatePrefix(); - sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', prefix + MultiChatUtil.reformatRGB(getMessage(id)).replaceAll("%SPECIAL%", special)))); + + Player player; + String server = ""; + if (sender instanceof Player) { + player = (Player) sender; + server = player.getServer().getName(); + } + + sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', prefix + MultiChatUtil.reformatRGB(getMessage(id)).replaceAll("%SPECIAL%", special).replaceAll("%SERVER%", server)))); } public static void sendSpecialMessageWithoutPrefix(CommandSender sender, String id, String special) { diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MultiChat.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MultiChat.java index 00ee9c3e..519dc8ad 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MultiChat.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MultiChat.java @@ -26,6 +26,7 @@ import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.event.EventHandler; +import xyz.olivermartin.multichat.proxy.common.ServerGroups; /** @@ -37,11 +38,13 @@ */ public class MultiChat extends Plugin implements Listener { - public static final String LATEST_VERSION = "1.9.7"; + public static final String LATEST_VERSION = "1.9.9"; public static final String[] ALLOWED_VERSIONS = new String[] { LATEST_VERSION, + "1.9.8", + "1.9.7", "1.9.6", "1.9.5", "1.9.4", @@ -105,6 +108,10 @@ public class MultiChat extends Plugin implements Listener { public static List legacyServers = new ArrayList(); + private static ServerGroups serverGroups; + private static Boolean serverGroupsEnabled = false; + private static HashMap> serverGroupsMap = new HashMap<>(); + public static MultiChat getInstance() { return instance; } @@ -300,7 +307,7 @@ public void onEnable() { if (!configversion.equals(LATEST_VERSION)) { getLogger().info("[!!!] [WARNING] YOUR CONFIG FILES ARE NOT THE LATEST VERSION"); - getLogger().info("[!!!] [WARNING] MULTICHAT 1.8 INTRODUCES SEVERAL NEW FEATURES WHICH ARE NOT IN YOUR OLD FILE"); + getLogger().info("[!!!] [WARNING] MULTICHAT HAS INTRODUCED SEVERAL NEW FEATURES WHICH ARE NOT IN YOUR OLD FILE"); getLogger().info("[!!!] [WARNING] THE PLUGIN SHOULD WORK WITH THE OLDER FILE, BUT IS NOT SUPPORTED!"); getLogger().info("[!!!] [WARNING] PLEASE BACKUP YOUR OLD CONFIG FILES AND DELETE THEM FROM THE MULTICHAT FOLDER SO NEW ONES CAN BE GENERATED!"); getLogger().info("[!!!] [WARNING] THANK YOU"); @@ -369,6 +376,25 @@ public void onEnable() { channel.addServer(server); } + // Setup Server Groups for Global Chatting + serverGroups = new ServerGroups(); + serverGroupsEnabled = configYML.getBoolean("serverGroups.enabled", false); + + if (configYML.getSection("serverGroups.groups") != null && configYML.getSection("serverGroups.groups").getKeys() != null) { + for (String groupKey : configYML.getSection("serverGroups.groups").getKeys()) { + ArrayList serverGroupList = new ArrayList<>(); + + for (String server : configYML.getStringList("serverGroups.groups." + groupKey)) { + serverGroupList.add(server); + } + + serverGroupsMap.put(groupKey, serverGroupList); + } + } + + serverGroups.setServerGroupsEnabled(serverGroupsEnabled); + serverGroups.setServerGroups(serverGroupsMap); + // Initiate backup routine backup(); @@ -423,7 +449,6 @@ public void registerCommands(Configuration configYML, Configuration chatcontrolY getProxy().getPluginManager().registerCommand(this, CommandManager.getGrouplist()); getProxy().getPluginManager().registerCommand(this, CommandManager.getMultichat()); getProxy().getPluginManager().registerCommand(this, CommandManager.getMultichatBypass()); - getProxy().getPluginManager().registerCommand(this, CommandManager.getMultiChatExecute()); getProxy().getPluginManager().registerCommand(this, CommandManager.getDisplay()); getProxy().getPluginManager().registerCommand(this, CommandManager.getFreezechat()); getProxy().getPluginManager().registerCommand(this, CommandManager.getHelpme()); @@ -434,6 +459,12 @@ public void registerCommands(Configuration configYML, Configuration chatcontrolY getProxy().getPluginManager().registerCommand(this, CommandManager.getUsecast()); getProxy().getPluginManager().registerCommand(this, CommandManager.getIgnore()); + // Check for Multichat Execute Command Being Enabled + // By default this is enabled + if (configYML.getBoolean("mcexecute_enabled", true)) { + getProxy().getPluginManager().registerCommand(this, CommandManager.getMultiChatExecute()); + } + // Register PM commands if (configYML.getBoolean("pm")) { getProxy().getPluginManager().registerCommand(this, CommandManager.getMsg()); @@ -476,7 +507,6 @@ public void unregisterCommands(Configuration configYML, Configuration chatcontro getProxy().getPluginManager().unregisterCommand(CommandManager.getGrouplist()); getProxy().getPluginManager().unregisterCommand(CommandManager.getMultichat()); getProxy().getPluginManager().unregisterCommand(CommandManager.getMultichatBypass()); - getProxy().getPluginManager().unregisterCommand(CommandManager.getMultiChatExecute()); getProxy().getPluginManager().unregisterCommand(CommandManager.getDisplay()); getProxy().getPluginManager().unregisterCommand(CommandManager.getFreezechat()); getProxy().getPluginManager().unregisterCommand(CommandManager.getHelpme()); @@ -487,6 +517,12 @@ public void unregisterCommands(Configuration configYML, Configuration chatcontro getProxy().getPluginManager().unregisterCommand(CommandManager.getUsecast()); getProxy().getPluginManager().unregisterCommand(CommandManager.getIgnore()); + // Check for Multichat Execute Command Being Enabled + // By default this is enabled + if (configYML.getBoolean("mcexecute_enabled", true)) { + getProxy().getPluginManager().unregisterCommand(CommandManager.getMultiChatExecute()); + } + // Unregister PM commands if (configYML.getBoolean("pm")) { getProxy().getPluginManager().unregisterCommand(CommandManager.getMsg()); diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/local/common/config/LocalConfig.java b/multichat/src/main/java/xyz/olivermartin/multichat/local/common/config/LocalConfig.java index a969dd37..5cac5f83 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/local/common/config/LocalConfig.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/local/common/config/LocalConfig.java @@ -39,6 +39,9 @@ public abstract class LocalConfig { private boolean nicknameSQL; private boolean mySQL; + // Proxy Execute Settings + private Boolean pExecute; + // CHANNEL CONTROL SETTINGS private List regexChannelForcers; @@ -140,6 +143,9 @@ private void setMemberAttributes() { nicknameLengthLimitFormatting = getBoolean("nickname_length_limit_formatting", false); nicknameSQL = getBoolean("nickname_sql", false); + // Proxy Execute + pExecute = getBoolean("pexecute_enabled", true); + // MySQL mySQL = getBoolean("mysql", false); LocalDatabaseCredentials.getInstance().updateValues(getString("mysql_url",""), @@ -287,6 +293,10 @@ public boolean isMySQL() { return mySQL; } + public boolean isPExecuteEnabled() { + return pExecute; + } + /** * @return the regex channel forcers */ diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/local/spigot/MultiChatLocalSpigotPlugin.java b/multichat/src/main/java/xyz/olivermartin/multichat/local/spigot/MultiChatLocalSpigotPlugin.java index 79899fa7..5dc98bba 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/local/spigot/MultiChatLocalSpigotPlugin.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/local/spigot/MultiChatLocalSpigotPlugin.java @@ -44,6 +44,8 @@ public class MultiChatLocalSpigotPlugin extends JavaPlugin { + private Boolean pExecuteEnabled; + @Override public void onEnable() { @@ -111,6 +113,9 @@ public void onEnable() { } + // Set the value of the PExecute Boolean + pExecuteEnabled = configMan.getLocalConfig().isPExecuteEnabled(); + api.registerNameManager(nameManager); LocalFileSystemManager fileSystemManager = new LocalFileSystemManager(); @@ -152,13 +157,18 @@ public void onEnable() { // Register Commands this.getCommand("multichatlocal").setExecutor(new MultiChatLocalSpigotCommand()); - SpigotProxyExecuteCommand pxeCommand = new SpigotProxyExecuteCommand(); - this.getCommand("pxe").setExecutor(pxeCommand); - this.getCommand("pexecute").setExecutor(pxeCommand); this.getCommand("nick").setExecutor(new SpigotNickCommand()); this.getCommand("realname").setExecutor(new SpigotRealnameCommand()); this.getCommand("username").setExecutor(new SpigotUsernameCommand()); + // Check for Proxy Execute Command Being Enabled + // By default this is enabled + if (pExecuteEnabled) { + SpigotProxyExecuteCommand pxeCommand = new SpigotProxyExecuteCommand(); + this.getCommand("pxe").setExecutor(pxeCommand); + this.getCommand("pexecute").setExecutor(pxeCommand); + } + // Manage dependencies setupVaultChat(); setupPAPI(); @@ -174,8 +184,13 @@ private void registerCommunicationChannels() { getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:dn"); getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:world"); getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:nick"); - getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:pxe"); - getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:ppxe"); + + // Check for Proxy Execute Command Being Enabled + // By default this is enabled + if (pExecuteEnabled) { + getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:pxe"); + getServer().getMessenger().registerOutgoingPluginChannel(this, "multichat:ppxe"); + } getServer().getMessenger().registerIncomingPluginChannel(this, "multichat:comm", new LocalSpigotPlayerMetaListener()); getServer().getMessenger().registerIncomingPluginChannel(this, "multichat:chat", new LocalSpigotCastListener()); diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/local/sponge/MultiChatLocalSpongePlugin.java b/multichat/src/main/java/xyz/olivermartin/multichat/local/sponge/MultiChatLocalSpongePlugin.java index cf4a1d0f..0b73e207 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/local/sponge/MultiChatLocalSpongePlugin.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/local/sponge/MultiChatLocalSpongePlugin.java @@ -37,6 +37,7 @@ import xyz.olivermartin.multichat.local.common.storage.LocalNameManager; import xyz.olivermartin.multichat.local.common.storage.LocalNameManagerMode; import xyz.olivermartin.multichat.local.common.storage.LocalSQLNameManager; +import xyz.olivermartin.multichat.local.spigot.commands.SpigotProxyExecuteCommand; import xyz.olivermartin.multichat.local.sponge.commands.MultiChatLocalSpongeCommand; import xyz.olivermartin.multichat.local.sponge.commands.SpongeNickCommand; import xyz.olivermartin.multichat.local.sponge.commands.SpongeProxyExecuteCommand; @@ -62,6 +63,7 @@ public class MultiChatLocalSpongePlugin { @Inject @ConfigDir(sharedRoot = false) private Path privateConfigDir; + private Boolean pExecuteEnabled; @Listener public void onServerStart(GameStartedServerEvent event) { @@ -129,6 +131,9 @@ public void onServerStart(GameStartedServerEvent event) { } + // Set the value of the PExecute Boolean + pExecuteEnabled = configMan.getLocalConfig().isPExecuteEnabled(); + api.registerNameManager(nameManager); LocalFileSystemManager fileSystemManager = new LocalFileSystemManager(); @@ -202,19 +207,24 @@ public void onServerStart(GameStartedServerEvent event) { .executor(new SpongeUsernameCommand()) .build(); - CommandSpec pexecuteCommandSpec = CommandSpec.builder() - .description(Text.of("Sponge Proxy Execute Command")) - .arguments( - GenericArguments.remainingJoinedStrings(Text.of("message"))) - .permission("multichatlocal.pexecute") - .executor(new SpongeProxyExecuteCommand()) - .build(); - Sponge.getCommandManager().register(this, nicknameCommandSpec, "nick"); Sponge.getCommandManager().register(this, multichatlocalCommandSpec, "multichatlocal"); Sponge.getCommandManager().register(this, realnameCommandSpec, "realname"); Sponge.getCommandManager().register(this, usernameCommandSpec, "username"); - Sponge.getCommandManager().register(this, pexecuteCommandSpec, "pexecute", "pxe"); + + // Check for Proxy Execute Command Being Enabled + // By default this is enabled + if (pExecuteEnabled) { + CommandSpec pexecuteCommandSpec = CommandSpec.builder() + .description(Text.of("Sponge Proxy Execute Command")) + .arguments( + GenericArguments.remainingJoinedStrings(Text.of("message"))) + .permission("multichatlocal.pexecute") + .executor(new SpongeProxyExecuteCommand()) + .build(); + + Sponge.getCommandManager().register(this, pexecuteCommandSpec, "pexecute", "pxe"); + } // Manage Dependencies try { @@ -255,10 +265,14 @@ private void registerCommunicationChannels(SpongeBungeeCommunicationManager comm ChannelBinding.RawDataChannel ignoreChannel = channelRegistrar.createRawChannel(this, "multichat:ignore"); commManager.registerChannel("multichat:ignore", ignoreChannel); - ChannelBinding.RawDataChannel pexecuteChannel = channelRegistrar.createRawChannel(this, "multichat:pxe"); - commManager.registerChannel("multichat:pxe", pexecuteChannel); - ChannelBinding.RawDataChannel ppexecuteChannel = channelRegistrar.createRawChannel(this, "multichat:ppxe"); - commManager.registerChannel("multichat:ppxe", ppexecuteChannel); + // Check for Proxy Execute Command Being Enabled + // By default this is enabled + if (pExecuteEnabled) { + ChannelBinding.RawDataChannel pexecuteChannel = channelRegistrar.createRawChannel(this, "multichat:pxe"); + commManager.registerChannel("multichat:pxe", pexecuteChannel); + ChannelBinding.RawDataChannel ppexecuteChannel = channelRegistrar.createRawChannel(this, "multichat:ppxe"); + commManager.registerChannel("multichat:ppxe", ppexecuteChannel); + } commChannel.addListener(Platform.Type.SERVER, new LocalSpongePlayerMetaListener()); chatChannel.addListener(Platform.Type.SERVER, new LocalSpongeCastListener()); @@ -297,10 +311,15 @@ public void onServerStop(GameStoppingServerEvent event) { commManager.unregisterChannel("multichat:ch"); Sponge.getChannelRegistrar().unbindChannel(commManager.getChannel("multichat:ignore")); commManager.unregisterChannel("multichat:ignore"); - Sponge.getChannelRegistrar().unbindChannel(commManager.getChannel("multichat:pxe")); - commManager.unregisterChannel("multichat:pxe"); - Sponge.getChannelRegistrar().unbindChannel(commManager.getChannel("multichat:ppxe")); - commManager.unregisterChannel("multichat:ppxe"); + + // Check for Proxy Execute Command Being Enabled + // By default this is enabled + if (pExecuteEnabled) { + Sponge.getChannelRegistrar().unbindChannel(commManager.getChannel("multichat:pxe")); + commManager.unregisterChannel("multichat:pxe"); + Sponge.getChannelRegistrar().unbindChannel(commManager.getChannel("multichat:ppxe")); + commManager.unregisterChannel("multichat:ppxe"); + } if (MultiChatLocal.getInstance().getNameManager().getMode() == LocalNameManagerMode.SQL) { diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/MultiChatProxyPlatform.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/MultiChatProxyPlatform.java index 9e38a098..294e3d1b 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/MultiChatProxyPlatform.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/MultiChatProxyPlatform.java @@ -1,5 +1,5 @@ package xyz.olivermartin.multichat.proxy.common; public enum MultiChatProxyPlatform { - BUNGEE + BUNGEE, VELOCITY } diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/ServerGroups.java b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/ServerGroups.java new file mode 100644 index 00000000..34eefa64 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/proxy/common/ServerGroups.java @@ -0,0 +1,74 @@ +package xyz.olivermartin.multichat.proxy.common; + +import com.velocitypowered.api.proxy.Player; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.ArrayList; +import java.util.HashMap; + +public class ServerGroups { + private static Boolean serverGroupsEnabled = false; + private static HashMap> serverGroups; + + public ServerGroups() { + + } + + public static Boolean getServerGroupsEnabled() { + return serverGroupsEnabled; + } + + public void setServerGroupsEnabled(Boolean serverGroupsEnabled) { + this.serverGroupsEnabled = serverGroupsEnabled; + } + + public HashMap> getServerGroups() { + return serverGroups; + } + + public void setServerGroups(HashMap> serverGroups) { + this.serverGroups = serverGroups; + } + + public static ArrayList getServerGroupList(ProxiedPlayer sender) { + if (serverGroupsEnabled && serverGroups != null && sender != null && sender.getServer() != null) { + String serverName = sender.getServer().getInfo().getName(); + + for (HashMap.Entry> serverGroup : serverGroups.entrySet()) { + if (serverGroup.getValue().contains(serverName)) { + return serverGroup.getValue(); + } + } + } + + return null; + } + + public static ArrayList getServerGroupList(Player sender) { + if (serverGroupsEnabled && serverGroups != null && sender != null && sender.getCurrentServer() != null) { + String serverName = sender.getCurrentServer().get().getServerInfo().getName(); + + for (HashMap.Entry> serverGroup : serverGroups.entrySet()) { + if (serverGroup.getValue().contains(serverName)) { + return serverGroup.getValue(); + } + } + } + + return null; + } + + public static String getServerGroupName(Player sender) { + if (serverGroupsEnabled && serverGroups != null && sender != null && sender.getCurrentServer() != null) { + String serverName = sender.getCurrentServer().get().getServerInfo().getName(); + + for (HashMap.Entry> serverGroup : serverGroups.entrySet()) { + if (serverGroup.getValue().contains(serverName)) { + return serverGroup.getKey(); + } + } + } + + return null; + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Announcements.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Announcements.java new file mode 100644 index 00000000..9214bf27 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Announcements.java @@ -0,0 +1,130 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.scheduler.ScheduledTask; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.velocity.events.PostBroadcastEvent; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * Announcements Management + *

The back-end code which manages the creation, deletion and scheduling of announcements

+ * + * @author Oliver Martin (Revilo410) + */ +public class Announcements { + + private static final Map aKey = new HashMap<>(); + private static Map announcements = new HashMap<>(); + + public static boolean startAnnouncement(final String name, Integer minutes) { + + if (!(aKey.containsKey(name.toLowerCase())) && announcements.containsKey(name.toLowerCase())) { + + ScheduledTask task = MultiChat.getInstance().getServer().getScheduler().buildTask(MultiChat.getInstance(), () -> { + String message = announcements.get(name.toLowerCase()); + + message = ChatControl.applyChatRules(message, "announcements", "").get(); + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } + + // Trigger PostBroadcastEvent + MultiChat.getInstance().getServer().getEventManager().fire(new PostBroadcastEvent("announcement", message)); + }).repeat(minutes, TimeUnit.MINUTES).schedule(); + aKey.put(name.toLowerCase(), task); + return true; + + } else { + + return false; + + } + } + + public static HashMap getAnnouncementList() { + + return (HashMap) announcements; + + } + + public static void loadAnnouncementList(HashMap loadedAnnouncements) { + + announcements = loadedAnnouncements; + + } + + public static boolean stopAnnouncement(String name) { + + if (aKey.containsKey(name.toLowerCase())) { + aKey.get(name.toLowerCase()).cancel(); + aKey.remove(name.toLowerCase()); + return true; + } else { + return false; + } + + } + + public static boolean addAnnouncement(String name, String message) { + + if (!announcements.containsKey(name.toLowerCase())) { + + announcements.put(name.toLowerCase(), MultiChatUtil.reformatRGB(message)); + return true; + + } else { + return false; + } + + } + + public static boolean removeAnnouncement(String name) { + + if (aKey.containsKey(name.toLowerCase())) { + aKey.get(name.toLowerCase()).cancel(); + aKey.remove(name.toLowerCase()); + } + + if (announcements.containsKey(name.toLowerCase())) { + announcements.remove(name.toLowerCase()); + return true; + } else { + return false; + } + + } + + public static boolean existsAnnouncemnt(String name) { + return announcements.containsKey(name.toLowerCase()); + } + + public static void playAnnouncement(String name) { + + if (announcements.containsKey(name.toLowerCase())) { + + String message = announcements.get(name.toLowerCase()); + + message = ChatControl.applyChatRules(message, "announcements", "").get(); + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } + + // Trigger PostBroadcastEvent + MultiChat.getInstance().getServer().getEventManager().fire(new PostBroadcastEvent("announcement", message)); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Bulletins.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Bulletins.java new file mode 100644 index 00000000..9a5531b1 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Bulletins.java @@ -0,0 +1,120 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.scheduler.ScheduledTask; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.velocity.events.PostBroadcastEvent; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; + +/** + * Bulletins Management + *

The back-end code which manages the creation, deletion and scheduling of bulletins

+ * + * @author Oliver Martin (Revilo410) + */ +public class Bulletins { + private static final Object lock = new Object(); + + private static ScheduledTask currentlyScheduled = null; + private static int nextBulletin = -1; + private static ArrayList bulletin = new ArrayList<>(); + private static int timeInbetween = 0; + + public static void setArrayList(ArrayList bulletinList) { + bulletin = bulletinList; + } + + public static ArrayList getArrayList() { + return bulletin; + } + + public static void startBulletins(int timeBetween) { + + timeInbetween = timeBetween; + + if (nextBulletin == -1 && bulletin.size() > 0) { + nextBulletin = 0; + scheduleNextBulletin(timeBetween); + } + + } + + public static int getTimeBetween() { + return timeInbetween; + } + + public static boolean isEnabled() { + return nextBulletin != -1; + } + + public static void stopBulletins() { + + if (nextBulletin != -1) { + nextBulletin = -1; + } + + try { + currentlyScheduled.cancel(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + public static void addBulletin(String message) { + synchronized (lock) { + bulletin.add(MultiChatUtil.reformatRGB(message)); + } + } + + public static Iterator getIterator() { + synchronized (lock) { + return bulletin.iterator(); + } + } + + public static void removeBulletin(int index) { + synchronized (lock) { + try { + bulletin.remove(index); + } catch (Exception e) { + System.err.println("Couldnt remove bulletin!"); + } + } + + } + + private static void scheduleNextBulletin(final int minutes) { + currentlyScheduled = MultiChat.getInstance().getServer().getScheduler().buildTask(MultiChat.getInstance(), () -> { + String message; + if (bulletin.size() >= 1) { + message = bulletin.get(nextBulletin); + + message = ChatControl.applyChatRules(message, "bulletins", "").get(); + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } + + // Trigger PostBroadcastEvent + MultiChat.getInstance().getServer().getEventManager().fire(new PostBroadcastEvent("bulletin", message)); + + } + + if (nextBulletin >= bulletin.size() - 1) { + nextBulletin = 0; + } else { + nextBulletin++; + } + + scheduleNextBulletin(minutes); + }).delay(minutes, TimeUnit.MINUTES).schedule(); + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/BungeeComm.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/BungeeComm.java new file mode 100644 index 00000000..6ba54bbe --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/BungeeComm.java @@ -0,0 +1,498 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.server.ServerInfo; +import ninja.leaping.configurate.ConfigurationNode; + +import java.io.*; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.regex.PatternSyntaxException; + +/** + * Bungee Communication Manager + *

Manages all plug-in messaging channels on the BungeeCord side

+ * + * @author Oliver Martin (Revilo410) + */ +public class BungeeComm { + + public static void sendMessage(String message, ServerInfo server) { + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(stream); + + try { + // Players name + out.writeUTF(message); + + // Should display name be set? + ConfigurationNode configYML = ConfigManager.getInstance().getHandler("config.yml").getConfig(); + if (configYML.getChildrenMap().containsKey("set_display_name")) { + if (configYML.getNode("set_display_name").getBoolean()) { + out.writeUTF("T"); + } else { + out.writeUTF("F"); + } + } else { + out.writeUTF("T"); + } + + // Display name format + if (configYML.getChildrenMap().containsKey("display_name_format")) { + out.writeUTF(Objects.requireNonNull(configYML.getNode("display_name_format").getString())); + } else { + out.writeUTF("%PREFIX%%NICK%%SUFFIX%"); + } + + // Is this server a global chat server? + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("global").getBoolean() + && !ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_global").getList(String::valueOf).contains(server.getName())) { + out.writeUTF("T"); + } else { + out.writeUTF("F"); + } + + // Send the global format + out.writeUTF(Channel.getGlobalChannel().getFormat()); + + } catch (IOException e) { + e.printStackTrace(); + } + MultiChat.getInstance().getServer().getServer(server.getName()).ifPresent( + registeredServer -> registeredServer.sendPluginMessage(MinecraftChannelIdentifier.from("multichat:comm"), stream.toByteArray())); + } + + public static void sendCommandMessage(String command, ServerInfo server) { + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(stream); + + try { + + // Command + out.writeUTF(command); + + } catch (IOException e) { + e.printStackTrace(); + } + + MultiChat.getInstance().getServer().getServer(server.getName()).ifPresent( + registeredServer -> registeredServer.sendPluginMessage(MinecraftChannelIdentifier.from("multichat:act"), stream.toByteArray())); + } + + public static void sendPlayerCommandMessage(String command, String playerRegex, ServerInfo server) { + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(stream); + + try { + + // Command + out.writeUTF(playerRegex); + out.writeUTF(command); + + } catch (IOException e) { + e.printStackTrace(); + } + + MultiChat.getInstance().getServer().getServer(server.getName()).ifPresent( + registeredServer -> registeredServer.sendPluginMessage(MinecraftChannelIdentifier.from("multichat:pact"), stream.toByteArray())); + } + + public static void sendChatMessage(String message, ServerInfo server) { + + // This has been repurposed to send casts to local chat streams! + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(stream); + + + try { + // message part + out.writeUTF(message); + + + } catch (IOException e) { + e.printStackTrace(); + } + + MultiChat.getInstance().getServer().getServer(server.getName()).ifPresent( + registeredServer -> registeredServer.sendPluginMessage(MinecraftChannelIdentifier.from("multichat:chat"), stream.toByteArray())); + } + + public static void sendIgnoreMap(ServerInfo server) { + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + ObjectOutputStream oout = new ObjectOutputStream(stream); + + oout.writeObject(ChatControl.getIgnoreMap()); + + } catch (IOException e) { + e.printStackTrace(); + } + + MultiChat.getInstance().getServer().getServer(server.getName()).ifPresent( + registeredServer -> registeredServer.sendPluginMessage(MinecraftChannelIdentifier.from("multichat:ignore"), stream.toByteArray())); + } + + public static void sendPlayerChannelMessage(String playerName, String channel, Channel channelObject, ServerInfo server, boolean colour, boolean rgb) { + + sendIgnoreMap(server); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + //DataOutputStream out = new DataOutputStream(stream); + try { + ObjectOutputStream oout = new ObjectOutputStream(stream); + + // Players name + oout.writeUTF(playerName); + // Channel part + oout.writeUTF(channel); + oout.writeBoolean(colour); + oout.writeBoolean(rgb); + oout.writeBoolean(channelObject.isWhitelistMembers()); + oout.writeObject(channelObject.getMembers()); + + } catch (IOException e) { + e.printStackTrace(); + } + + MultiChat.getInstance().getServer().getServer(server.getName()).ifPresent( + registeredServer -> registeredServer.sendPluginMessage(MinecraftChannelIdentifier.from("multichat:ch"), stream.toByteArray())); + + DebugManager.log("Sent message on multichat:ch channel!"); + + } + + @Subscribe + public void onPluginMessage(PluginMessageEvent ev) { + if (!ev.getIdentifier().getId().startsWith("multichat:")) + return; + + if (!(ev.getSource() instanceof ServerConnection)) { + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + return; + } + + if (ev.getIdentifier().getId().equals("multichat:chat")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + DebugManager.log("{multichat:chat} Got a plugin message"); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + UUID uuid = UUID.fromString(in.readUTF()); + DebugManager.log("{multichat:chat} UUID = " + uuid); + String message = in.readUTF(); + DebugManager.log("{multichat:chat} Message = " + message); + String format = in.readUTF(); + + DebugManager.log("{multichat:chat} Format (before removal of double chars) = " + format); + + format = format.replace("%%", "%"); + + DebugManager.log("{multichat:chat} Format = " + format); + + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) { + DebugManager.log("{multichat:chat} Could not get player! Abandoning chat message... (Is IP-Forwarding on?)"); + return; + } + + DebugManager.log("{multichat:chat} Got player successfully! Name = " + player.getUsername()); + + //synchronized (player) { + + DebugManager.log("{multichat:chat} Global Channel Available? = " + (Channel.getGlobalChannel() != null)); + Channel.getGlobalChannel().sendMessage(player, message, format); + + //} + + } catch (IOException e) { + DebugManager.log("{multichat:chat} ERROR READING PLUGIN MESSAGE"); + e.printStackTrace(); + } + + + return; + + } + + if (ev.getIdentifier().getId().equals("multichat:nick")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + UUID uuid = UUID.fromString(in.readUTF()); + String nick = in.readUTF(); + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) return; + + synchronized (player) { + + /* + * Update the nickname stored somewhere and call for an update of the player + * display name in that location. (Pending the "true" value of fetch display names) + * and a new config option to decide if the display name should be set. + */ + + Optional opm = PlayerMetaManager.getInstance().getPlayer(uuid); + + if (opm.isPresent()) { + + opm.get().nick = nick; + PlayerMetaManager.getInstance().updateDisplayName(uuid); + + } + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + if (ev.getIdentifier().getId().equals("multichat:prefix")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + UUID uuid = UUID.fromString(in.readUTF()); + String prefix = in.readUTF(); + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) return; + + synchronized (player) { + + /* + * Update the prefix stored somewhere and call for an update of the player + * display name in that location. (Pending the "true" value of fetch display names) + * and a new config option to decide if the display name should be set. + */ + + Optional opm = PlayerMetaManager.getInstance().getPlayer(uuid); + + if (opm.isPresent()) { + + opm.get().prefix = prefix; + PlayerMetaManager.getInstance().updateDisplayName(uuid); + + } + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + if (ev.getIdentifier().getId().equals("multichat:suffix")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + UUID uuid = UUID.fromString(in.readUTF()); + String suffix = in.readUTF(); + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) return; + + synchronized (player) { + + /* + * Update the suffix stored somewhere and call for an update of the player + * display name in that location. (Pending the "true" value of fetch display names) + * and a new config option to decide if the display name should be set. + */ + + Optional opm = PlayerMetaManager.getInstance().getPlayer(uuid); + + if (opm.isPresent()) { + + opm.get().suffix = suffix; + PlayerMetaManager.getInstance().updateDisplayName(uuid); + + } + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + if (ev.getIdentifier().getId().equals("multichat:dn")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + DebugManager.log("[multichat:dn] Got an incoming channel message!"); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + UUID uuid = UUID.fromString(in.readUTF()); + String spigotDisplayName = in.readUTF(); + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) return; + + synchronized (player) { + + DebugManager.log("[multichat:dn] Player exists!"); + + Optional opm = PlayerMetaManager.getInstance().getPlayer(uuid); + + if (opm.isPresent()) { + + DebugManager.log("[multichat:dn] Player meta exists!"); + + DebugManager.log("[multichat:dn] The displayname received is: " + spigotDisplayName); + + opm.get().spigotDisplayName = spigotDisplayName; + PlayerMetaManager.getInstance().updateDisplayName(uuid); + + } + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + if (ev.getIdentifier().getId().equals("multichat:world")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + DebugManager.log("[multichat:world] Got an incoming channel message!"); + + try { + + UUID uuid = UUID.fromString(in.readUTF()); + String world = in.readUTF(); + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) return; + + DebugManager.log("[multichat:world] Player is online!"); + + synchronized (player) { + + /* + * Update the world stored somewhere + */ + + Optional opm = PlayerMetaManager.getInstance().getPlayer(uuid); + + if (opm.isPresent()) { + + DebugManager.log("[multichat:world] Got their meta data correctly"); + + opm.get().world = world; + + DebugManager.log("[multichat:world] Set their world to: " + world); + + } + + } + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + if (ev.getIdentifier().getId().equals("multichat:pxe")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + DebugManager.log("[multichat:pxe] Got an incoming pexecute message!"); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + String command = in.readUTF(); + DebugManager.log("[multichat:pxe] Command is: " + command); + MultiChat.getInstance().getServer().getCommandManager().executeAsync(MultiChat.getInstance().getServer().getConsoleCommandSource(), command); + + } catch (IOException e) { + e.printStackTrace(); + } + + } + + if (ev.getIdentifier().getId().equals("multichat:ppxe")) { + + ev.setResult(PluginMessageEvent.ForwardResult.handled()); + + DebugManager.log("[multichat:ppxe] Got an incoming pexecute message (for a player)!"); + + ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); + DataInputStream in = new DataInputStream(stream); + + try { + + String command = in.readUTF(); + String playerRegex = in.readUTF(); + + DebugManager.log("[multichat:ppxe] Command is: " + command); + DebugManager.log("[multichat:ppxe] Player regex is: " + playerRegex); + + for (Player p : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (p.getUsername().matches(playerRegex)) { + + MultiChat.getInstance().getServer().getCommandManager().executeAsync(p, command); + + } + + } + + } catch (IOException e) { + e.printStackTrace(); + } catch (PatternSyntaxException e2) { + MessageManager.sendMessage(MultiChat.getInstance().getServer().getConsoleCommandSource(), "command_execute_regex"); + } + + } + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/CastControl.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/CastControl.java new file mode 100644 index 00000000..09727a40 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/CastControl.java @@ -0,0 +1,36 @@ +package xyz.olivermartin.multichat.velocity; + +import java.util.HashMap; +import java.util.Map; + +import com.velocitypowered.api.command.CommandSource; +import xyz.olivermartin.multichat.bungee.MultiChatUtil; + +/** + * Cast Control + *

Manages the creation, deletion and displaying of Custom broadcASTs (CASTs)

+ * + * @author Oliver Martin (Revilo410) + */ +public class CastControl { + + public static Map castList = new HashMap(); + + public static void sendCast(String castName, String castMessage, Channel chatStream, CommandSource sender) { + castMessage = ChatControl.applyChatRules(castMessage, "casts", "").get(); + chatStream.sendMessage(castList.get(castName.toLowerCase()) + " " + castMessage, sender); + } + + public static void addCast(String castName, String castFormat) { + castList.put(castName.toLowerCase(), MultiChatUtil.reformatRGB(castFormat)); + } + + public static void removeCast(String castName) { + castList.remove(castName.toLowerCase()); + } + + public static boolean existsCast(String castName) { + return castList.containsKey(castName.toLowerCase()); + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Channel.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Channel.java new file mode 100644 index 00000000..78d15103 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Channel.java @@ -0,0 +1,336 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.proxy.common.ServerGroups; +import xyz.olivermartin.multichat.velocity.events.PostBroadcastEvent; +import xyz.olivermartin.multichat.velocity.events.PostGlobalChatEvent; + +import java.util.*; + +/** + * Channel + *

A class to represent a chat channel and control the messages sent etc.

+ * + * @author Oliver Martin (Revilo410) + */ +public class Channel { + + private static final GlobalChannel global; + private static final LocalChannel local; + + static { + global = new GlobalChannel("&f%DISPLAYNAME%&f: "); + local = new LocalChannel(); + } + + public static GlobalChannel getGlobalChannel() { + return global; + } + + public static LocalChannel getLocalChannel() { + return local; + } + + public static Map playerChannels = new HashMap<>(); + + public static void setChannel(UUID uuid, Channel channel) { + Channel.playerChannels.put(uuid, channel); + } + + public static Channel getChannel(UUID uuid) { + return Channel.playerChannels.get(uuid); + } + + public static void removePlayer(UUID uuid) { + Channel.playerChannels.remove(uuid); + } + + /* END STATIC */ + + boolean whitelistMembers; + protected List members; + + boolean whitelistServers; + protected List servers; + + protected String name; + protected String format; + + public Channel(String name, String format, boolean whitelistServers, boolean whitelistMembers) { + + this.name = name; + this.whitelistServers = whitelistServers; + this.format = format; + this.servers = new ArrayList<>(); + this.members = new ArrayList<>(); + this.whitelistMembers = whitelistMembers; + + } + + public boolean isMember(UUID player) { + if (this.whitelistMembers) { + return this.members.contains(player); + } else { + return !this.members.contains(player); + } + } + + public void removeMember(UUID player) { + this.members.remove(player); + } + + public List getMembers() { + return this.members; + } + + public boolean isWhitelistMembers() { + return this.whitelistMembers; + } + + public void addServer(String server) { + if (!servers.contains(server)) servers.add(server); + } + + public void setServers(List servers) { + this.servers = servers; + } + + public void clearServers() { + this.servers = new ArrayList<>(); + } + + public void addMember(UUID member) { + if (!members.contains(member)) members.add(member); + } + + public void setMembers(List members) { + this.members = members; + } + + public String getName() { + return this.name; + } + + public String getFormat() { + return this.format; + } + + public void setFormat(String format) { + this.format = format; + } + + public void sendMessage(Player sender, String message, String format) { + + DebugManager.log("CHANNEL #" + getName() + ": Got a message for the channel"); + DebugManager.log("CHANNEL #" + getName() + ": SENDER = " + sender.getUsername()); + DebugManager.log("CHANNEL #" + getName() + ": MESSAGE = " + message); + DebugManager.log("CHANNEL #" + getName() + ": FORMAT = " + format); + + Boolean serverGroupsEnabled = ServerGroups.getServerGroupsEnabled(); + ArrayList serverGroupList = ServerGroups.getServerGroupList(sender); + + for (Player receiver : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (receiver != null) { + + synchronized (receiver) { + + if (sender.getCurrentServer().isPresent() && receiver.getCurrentServer().isPresent()) { + + if ((whitelistMembers && members.contains(receiver.getUniqueId())) || (!whitelistMembers && !members.contains(receiver.getUniqueId()))) { + + if (!serverGroupsEnabled || serverGroupsEnabled == null) { + if ((whitelistServers && servers.contains(receiver.getCurrentServer().get().getServerInfo().getName())) || + (!whitelistServers && !servers.contains(receiver.getCurrentServer().get().getServerInfo().getName()))) { + + if (!ChatControl.ignores(sender.getUniqueId(), receiver.getUniqueId(), "global_chat")) { + if (!receiver.getCurrentServer().get().getServerInfo().getName().equals(sender.getCurrentServer().get().getServerInfo().getName())) { + receiver.sendMessage(Component.join(Component.text(), buildFormat(sender, receiver, format, message))); + } + } else { + ChatControl.sendIgnoreNotifications(receiver, sender, "global_chat"); + } + } + } else { + if (serverGroupList != null && serverGroupList.contains(receiver.getCurrentServer().get().getServerInfo().getName())) { + + if (!ChatControl.ignores(sender.getUniqueId(), receiver.getUniqueId(), "global_chat")) { + if (!receiver.getCurrentServer().get().getServerInfo().getName().equals(sender.getCurrentServer().get().getServerInfo().getName())) { + receiver.sendMessage(Component.join(Component.text(), buildFormat(sender, receiver, format, message))); + } + } else { + ChatControl.sendIgnoreNotifications(receiver, sender, "global_chat"); + } + } + } + } + } + } + } + } + + // Trigger PostGlobalChatEvent + MultiChat.getInstance().getServer().getEventManager().fire(new PostGlobalChatEvent(sender, format, message)); + + sendToConsole(sender, format, message); + + } + + public void sendMessage(String message, CommandSource sender) { + LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().character('&').hexCharacter('#').hexColors().build(); + + for (Player receiver : MultiChat.getInstance().getServer().getAllPlayers()) { + if (receiver != null && sender != null) { + if (receiver.getCurrentServer().isPresent()) { + if ((whitelistMembers && members.contains(receiver.getUniqueId())) || (!whitelistMembers && !members.contains(receiver.getUniqueId()))) { + if ((whitelistServers && servers.contains(receiver.getCurrentServer().get().getServerInfo().getName())) || + (!whitelistServers && !servers.contains(receiver.getCurrentServer().get().getServerInfo().getName()))) { + //TODO hiding & showing streams + + if (MultiChat.legacyServers.contains(receiver.getCurrentServer().get().getServerInfo().getName())) { + receiver.sendMessage(serializer.deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + receiver.sendMessage(serializer.deserialize(message)); + } + + } + } + } + } + } + + // Trigger PostBroadcastEvent + MultiChat.getInstance().getServer().getEventManager().fire(new PostBroadcastEvent("cast", message)); + + ConsoleManager.logDisplayMessage(message); + + } + + public Component buildFormat(Player sender, Player receiver, String format, String message) { + + String newFormat = format; + newFormat = newFormat + "%MESSAGE%"; + + Component toSend; + + LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().character('&').hexCharacter('#').hexColors().build(); + + if (sender.hasPermission("multichat.chat.colour") || sender.hasPermission("multichat.chat.color")) { + newFormat = newFormat.replace("%MESSAGE%", message); + + if (MultiChat.legacyServers.contains(receiver.getCurrentServer().get().getServerInfo().getName())) { + newFormat = MultiChatUtil.approximateHexCodes(newFormat); + } + + toSend = serializer.deserialize(MultiChatUtil.approximateHexCodes(MultiChatUtil.reformatRGB(newFormat))); + } else { + newFormat = newFormat.replace("%MESSAGE%", ""); + + if (MultiChat.legacyServers.contains(receiver.getCurrentServer().get().getServerInfo().getName())) { + newFormat = MultiChatUtil.approximateHexCodes(newFormat); + } + + toSend = serializer.deserialize(MultiChatUtil.approximateHexCodes(MultiChatUtil.reformatRGB(newFormat))).append(Component.text(message)); + } + + return toSend; + + } + + public Component buildFormat(String name, String displayName, String server, String world, Player receiver, String format, String message) { + + String newFormat = format; + + newFormat = newFormat.replace("%DISPLAYNAME%", displayName); + newFormat = newFormat.replace("%NAME%", name); + newFormat = newFormat.replace("%DISPLAYNAMET%", receiver.getUsername()); + newFormat = newFormat.replace("%NAMET%", receiver.getUsername()); + + Optional opmt = PlayerMetaManager.getInstance().getPlayer(receiver.getUniqueId()); + if (opmt.isPresent()) { + newFormat = newFormat.replace("%PREFIXT%", opmt.get().prefix); + newFormat = newFormat.replace("%SUFFIXT%", opmt.get().suffix); + newFormat = newFormat.replace("%NICKT%", opmt.get().nick); + newFormat = newFormat.replace("%WORLDT%", opmt.get().world); + } + + newFormat = newFormat.replace("%SERVER%", server); + newFormat = newFormat.replace("%SERVERT%", receiver.getCurrentServer().get().getServerInfo().getName()); + + newFormat = newFormat.replace("%WORLD%", world); + + newFormat = newFormat + "%MESSAGE%"; + + Component toSend; + + newFormat = newFormat.replace("%MESSAGE%", message); + if (MultiChat.legacyServers.contains(receiver.getCurrentServer().get().getServerInfo().getName())) { + newFormat = MultiChatUtil.approximateHexCodes(newFormat); + } + toSend = LegacyComponentSerializer.legacyAmpersand().deserialize(newFormat); + + return toSend; + + } + + public void sendToConsole(Player sender, String format, String message) { + + String newFormat = format; + + newFormat = newFormat.replace("%DISPLAYNAME%", sender.getUsername()); + newFormat = newFormat.replace("%NAME%", sender.getUsername()); + + Optional opm = PlayerMetaManager.getInstance().getPlayer(sender.getUniqueId()); + if (opm.isPresent()) { + newFormat = newFormat.replace("%PREFIX%", opm.get().prefix); + newFormat = newFormat.replace("%SUFFIX%", opm.get().suffix); + newFormat = newFormat.replace("%NICK%", opm.get().nick); + newFormat = newFormat.replace("%WORLD%", opm.get().world); + } + + newFormat = newFormat.replace("%DISPLAYNAMET%", "CONSOLE"); + newFormat = newFormat.replace("%NAMET%", "CONSOLE"); + newFormat = newFormat.replace("%SERVER%", sender.getCurrentServer().get().getServerInfo().getName()); + newFormat = newFormat.replace("%SERVERT%", "CONSOLE"); + newFormat = newFormat.replace("%WORLDT%", "CONSOLE"); + + newFormat = newFormat + "%MESSAGE%"; + + if (sender.hasPermission("multichat.chat.colour") || sender.hasPermission("multichat.chat.color")) { + + newFormat = newFormat.replace("%MESSAGE%", message); + ConsoleManager.logChat(newFormat); + + } else { + + newFormat = newFormat.replace("%MESSAGE%", ""); + ConsoleManager.logBasicChat(newFormat, message); + + } + + } + + public void sendToConsole(String name, String displayName, String server, String world, String format, String message) { + + String newFormat = format; + + newFormat = newFormat.replace("%DISPLAYNAME%", displayName); + newFormat = newFormat.replace("%NAME%", name); + newFormat = newFormat.replace("%DISPLAYNAMET%", "CONSOLE"); + newFormat = newFormat.replace("%NAMET%", "CONSOLE"); + newFormat = newFormat.replace("%SERVER%", server); + newFormat = newFormat.replace("%SERVERT%", "CONSOLE"); + newFormat = newFormat.replace("%WORLD%", world); + newFormat = newFormat.replace("%WORLDT%", "CONSOLE"); + + newFormat = newFormat + "%MESSAGE%"; + + newFormat = newFormat.replace("%MESSAGE%", message); + + ConsoleManager.logChat(newFormat); + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatControl.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatControl.java new file mode 100644 index 00000000..56586c65 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatControl.java @@ -0,0 +1,436 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.ServerInfo; +import ninja.leaping.configurate.ConfigurationNode; + +import java.util.*; + +public class ChatControl { + + static { + mutedPlayers = new HashSet<>(); + ignoreMap = new HashMap<>(); + spamMap = new HashMap<>(); + } + + private static Set mutedPlayers; + private static Map> ignoreMap; + private static final Map spamMap; + + public static boolean controlLinks = false; + public static String linkRegex = "((https|http)://)?(www\\.)?([-a-zA-Z0-9@:%._+~#=]{2,256}\\.)+[a-zA-Z]{2,4}\\b([-a-zA-Z0-9@:%_+.~#?&/=]*)"; + public static String linkMessage = "[LINK REMOVED]"; + + public static Set getMutedPlayers() { + return mutedPlayers; + } + + public static void setMutedPlayers(Set mutedPlayers) { + ChatControl.mutedPlayers = mutedPlayers; + } + + public static Map> getIgnoreMap() { + return ignoreMap; + } + + public static void setIgnoreMap(Map> ignoreMap) { + ChatControl.ignoreMap = ignoreMap; + } + + /** + * @param input The input message + * @param chatType The type of chat the message was sent in + * @return The message to send with rules applied, or empty if the chat message should be cancelled + */ + @SuppressWarnings("rawtypes") + public static Optional applyChatRules(String input, String chatType, String playerName) { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + boolean cancel = false; + + Player pp = MultiChat.getInstance().getServer().getPlayer(playerName).orElse(null); + + if (config.getNode("apply_rules_to").getChildrenMap().containsKey(chatType)) { + if (config.getNode("apply_rules_to").getNode(chatType).getBoolean()) { + + List rules = config.getNode("regex_rules").getList(o -> o); + + for (Object rule : rules) { + Map dictionary = (Map) rule; + + if (pp != null) { + if (dictionary.containsKey("permission")) { + String permission = String.valueOf(dictionary.get("permission")); + if (permission.startsWith("!")) { + permission = permission.substring(1); + if (pp.hasPermission(permission)) continue; + } else { + if (!pp.hasPermission(permission)) continue; + } + } + } + + input = input.replaceAll(String.valueOf(dictionary.get("look_for")), String.valueOf(dictionary.get("replace_with"))); + } + + } + } + + if (config.getNode("apply_actions_to").getChildrenMap().containsKey(chatType)) { + if (config.getNode("apply_actions_to").getNode(chatType).getBoolean()) { + + List actions = config.getNode("regex_actions").getList(o -> o); + + for (Object action : actions) { + Map dictionary = (Map) action; + + if (input.matches(String.valueOf(dictionary.get("look_for")))) { + + if (pp != null) { + if (dictionary.containsKey("permission")) { + String permission = String.valueOf(dictionary.get("permission")); + if (permission.startsWith("!")) { + permission = permission.substring(1); + if (pp.hasPermission(permission)) continue; + } else { + if (!pp.hasPermission(permission)) continue; + } + } + } + + if ((Boolean) dictionary.get("cancel")) { + cancel = true; + } + + if ((Boolean) dictionary.get("spigot")) { + + ServerInfo server = MultiChat.getInstance().getServer().getPlayer(playerName).get().getCurrentServer().get().getServerInfo(); + BungeeComm.sendCommandMessage(String.valueOf(dictionary.get("command")).replaceAll("%PLAYER%", playerName), server); + + } else { + MultiChat.getInstance().getServer().getCommandManager().executeAsync(MultiChat.getInstance().getServer().getConsoleCommandSource(), String.valueOf(dictionary.get("command")).replaceAll("%PLAYER%", playerName)); + } + + } + + } + + } + } + + if (cancel) { + return Optional.empty(); + } else { + return Optional.of(input); + } + + } + + public static boolean isMuted(UUID uuid, String chatType) { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (!config.getNode("mute").getBoolean()) return false; + + if (!mutedPlayers.contains(uuid)) return false; + + if (!config.getNode("apply_mute_to").getChildrenMap().containsKey(chatType)) return false; + + return config.getNode("apply_mute_to").getNode(chatType).getBoolean(); + + } + + public static boolean isMutedAnywhere(UUID uuid) { + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (!config.getNode("mute").getBoolean()) return false; + + return mutedPlayers.contains(uuid); + + } + + public static void mute(UUID uuid) { + + mutedPlayers.add(uuid); + + } + + public static void unmute(UUID uuid) { + + mutedPlayers.remove(uuid); + + } + + /** + * Tests if the target is ignoring the sender, and hence should not receive the message + * + * @param sender The player trying to send a message + * @param target The player who will see the message + * @return TRUE if the target ignores the sender and the message should not be sent, FALSE otherwise + */ + public static boolean ignores(UUID sender, UUID target, String chatType) { + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (!ignoreMap.containsKey(target)) return false; + + Set ignoredPlayers = ignoreMap.get(target); + + if (ignoredPlayers == null) return false; + + if (!ignoredPlayers.contains(sender)) return false; + + if (!config.getNode("apply_ignore_to").getChildrenMap().containsKey(chatType)) return false; + + return config.getNode("apply_ignore_to").getNode(chatType).getBoolean(); + } + + /** + * Tests if the target is ignoring the sender, and hence should not receive the message + * + * @param sender The player trying to send a message + * @param target The player who will see the message + * @return TRUE if the target ignores the sender and the message should not be sent, FALSE otherwise + */ + public static boolean ignoresAnywhere(UUID sender, UUID target) { + + if (!ignoreMap.containsKey(target)) return false; + + Set ignoredPlayers = ignoreMap.get(target); + + if (ignoredPlayers == null) return false; + + return ignoredPlayers.contains(sender); + } + + public static void ignore(UUID ignorer, UUID ignoree) { + + Set ignoredPlayers; + + if (ignoreMap.containsKey(ignorer)) { + + ignoredPlayers = ignoreMap.get(ignorer); + + } else { + + ignoredPlayers = new HashSet<>(); + + } + + ignoredPlayers.add(ignoree); + ignoreMap.put(ignorer, ignoredPlayers); + + } + + public static void unignore(UUID ignorer, UUID ignoree) { + + Set ignoredPlayers; + + if (ignoreMap.containsKey(ignorer)) { + + ignoredPlayers = ignoreMap.get(ignorer); + + } else { + + return; + + } + + ignoredPlayers.remove(ignoree); + + if (ignoredPlayers.size() < 1) { + ignoreMap.remove(ignorer); + } else { + ignoreMap.put(ignorer, ignoredPlayers); + } + + } + + public static void unignoreAll(UUID ignorer) { + + ignoreMap.remove(ignorer); + + } + + public static void sendIgnoreNotifications(CommandSource ignorer, CommandSource ignoree, String chatType) { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (config.getNode("notify_ignore").getBoolean()) { + MessageManager.sendSpecialMessage(ignorer, "ignore_target", ignoree instanceof Player ? ((Player) ignoree).getUsername() : "CONSOLE"); + } + + if (!chatType.equals("private_messages")) return; + + MessageManager.sendMessage(ignoree, "ignore_sender"); + + } + + /** + * If sessional ignore is enabled, removes any offline players from the ignore map + */ + public static void reload() { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (config.getNode("session_ignore").getBoolean()) { + + for (UUID uuid : ignoreMap.keySet()) { + + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (player == null) ignoreMap.remove(uuid); + + } + + } + + } + + public static String replaceLinks(String message) { + if (!controlLinks) return message; + return message.replaceAll(linkRegex, linkMessage); + //return message.replaceAll("((https|http):\\/\\/)?(www\\.)?([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.)+[a-zA-Z]{2,4}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)", linkMessage); + } + + public static void spamPardonPlayer(UUID uuid) { + spamMap.remove(uuid); + } + + /** + * @return true if the player is spamming and the message should be blocked + */ + public static boolean handleSpam(Player player, String message, String chatType) { + + DebugManager.log(player.getUsername() + " - checking for spam..."); + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (player.hasPermission("multichat.spam.bypass")) return false; + + DebugManager.log(player.getUsername() + " - does not have bypass perm..."); + + if (!config.getNode("anti_spam").getBoolean()) return false; + + DebugManager.log(player.getUsername() + " - anti spam IS enabled..."); + + if (!config.getNode("apply_anti_spam_to").getChildrenMap().containsKey(chatType)) return false; + + if (!config.getNode("apply_anti_spam_to").getNode(chatType).getBoolean()) return false; + + DebugManager.log(player.getUsername() + " - anti spam IS enabled for " + chatType + "..."); + + if (!spamMap.containsKey(player.getUniqueId())) spamMap.put(player.getUniqueId(), new PlayerSpamInfo()); + + PlayerSpamInfo spamInfo = spamMap.get(player.getUniqueId()); + + boolean spam = spamInfo.checkSpam(message); + + if (spam) { + + DebugManager.log(player.getUsername() + " - PLAYER IS SPAMMING!"); + + MessageManager.sendSpecialMessage(player, "anti_spam_cooldown", String.valueOf(spamInfo.getCooldownSeconds())); + + DebugManager.log(player.getUsername() + " - sent cooldown message to player..."); + + if (spamInfo.getSpamTriggerCount() >= config.getNode("anti_spam_trigger").getInt()) { + + DebugManager.log(player.getUsername() + " - they have set off the trigger..."); + + spamInfo.resetSpamTriggerCount(); + + if (config.getNode("anti_spam_action").getBoolean()) { + + DebugManager.log(player.getUsername() + " - trigger IS enabled..."); + + if (config.getNode("anti_spam_spigot").getBoolean()) { + ServerInfo server = player.getCurrentServer().get().getServerInfo(); + BungeeComm.sendCommandMessage(config.getNode("anti_spam_command").getString().replaceAll("%PLAYER%", player.getUsername()), server); + } else { + MultiChat.getInstance().getServer().getCommandManager().executeAsync(MultiChat.getInstance().getServer().getConsoleCommandSource(), config.getNode("anti_spam_command").getString().replaceAll("%PLAYER%", player.getUsername())); + } + + } + + } + + } + DebugManager.log(player.getUsername() + " - returning " + spam); + + return spam; + + } + + public static class PlayerSpamInfo { + + int spamTriggerCount = 0; + long lastSpamTime = 0L; + long[] messageTimeBuffer = {0L, 0L, 0L}; + int sameMessageCounter = 0; + String lastMessage = ""; + + /** + * @return true if the user is spamming and message should be cancelled + */ + public boolean checkSpam(String message) { + + boolean spam = false; + long currentTime = System.currentTimeMillis(); + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + // If the user triggered anti-spam, check if they are still on cooldown + if (currentTime - lastSpamTime < (1000L * config.getNode("anti_spam_cooldown").getInt())) return true; + + long deltaTime = currentTime - messageTimeBuffer[2]; + + if (lastMessage.equalsIgnoreCase(message)) { + // This is a hard coded test. If the same message is sent 4 times in a row, it is spam... + // However; this extra bit states that if it has been longer than 10 times the usual spam time + // then this should not be considered spam. And hence the counter is reset. + if ((currentTime - messageTimeBuffer[0]) < (1000L * config.getNode("anti_spam_time").getInt() * 10)) { + sameMessageCounter++; + } else { + sameMessageCounter = 0; + } + } else { + sameMessageCounter = 0; + lastMessage = message; + } + + rotateMessages(currentTime); + + // Max messages in time limit or same message in row check + if (deltaTime < (1000L * config.getNode("anti_spam_time").getInt()) + || !(sameMessageCounter + 1 < config.getNode("spam_same_message").getInt())) { + spam = true; + lastSpamTime = currentTime; + spamTriggerCount++; + } + + return spam; + } + + private void rotateMessages(long currentTime) { + messageTimeBuffer[2] = messageTimeBuffer[1]; + messageTimeBuffer[1] = messageTimeBuffer[0]; + messageTimeBuffer[0] = currentTime; + } + + public int getSpamTriggerCount() { + return spamTriggerCount; + } + + public void resetSpamTriggerCount() { + spamTriggerCount = spamTriggerCount - 1; + } + + public long getCooldownSeconds() { + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + return config.getNode("anti_spam_cooldown").getInt() - ((System.currentTimeMillis() - lastSpamTime) / 1000); + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatManipulation.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatManipulation.java new file mode 100644 index 00000000..e28101a1 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatManipulation.java @@ -0,0 +1,152 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.proxy.Player; + +import java.util.Optional; + +/** + * LEGACY ** TO BE REMOVED ** Chat Manipulation Class + *

This class now only serves the purpose of replacing the placeholders in message formats

+ * + *

It used to manage "fixing format codes" and "getting URLBIT" before these were made redundant

+ * + * @author Oliver Martin (Revilo410) + * + */ +public class ChatManipulation { + + public String replaceMsgVars(String messageFormat, String message, Player sender, Player target) { + + messageFormat = messageFormat.replace("%MESSAGE%", message); + messageFormat = messageFormat.replace("%DISPLAYNAME%", sender.getUsername()); + messageFormat = messageFormat.replace("%NAME%", sender.getUsername()); + + Optional opm = PlayerMetaManager.getInstance().getPlayer(sender.getUniqueId()); + if (opm.isPresent()) { + messageFormat = messageFormat.replace("%PREFIX%", opm.get().prefix); + messageFormat = messageFormat.replace("%SUFFIX%", opm.get().suffix); + messageFormat = messageFormat.replace("%NICK%", opm.get().nick); + } + + messageFormat = messageFormat.replace("%DISPLAYNAMET%", target.getUsername()); + messageFormat = messageFormat.replace("%NAMET%", target.getUsername()); + + Optional opmt = PlayerMetaManager.getInstance().getPlayer(target.getUniqueId()); + if (opmt.isPresent()) { + messageFormat = messageFormat.replace("%PREFIXT%", opmt.get().prefix); + messageFormat = messageFormat.replace("%SUFFIXT%", opmt.get().suffix); + messageFormat = messageFormat.replace("%NICKT%", opmt.get().nick); + } + + messageFormat = messageFormat.replace("%SERVER%", sender.getCurrentServer().get().getServerInfo().getName()); + messageFormat = messageFormat.replace("%SERVERT%", target.getCurrentServer().get().getServerInfo().getName()); + + messageFormat = messageFormat.replace("%WORLD%", opm.get().world); + messageFormat = messageFormat.replace("%WORLDT%", opmt.get().world); + + return messageFormat; + + } + + public String replaceMsgConsoleTargetVars(String messageFormat, String message, Player sender) { + + messageFormat = messageFormat.replace("%MESSAGE%", message); + messageFormat = messageFormat.replace("%DISPLAYNAME%", sender.getUsername()); + messageFormat = messageFormat.replace("%NAME%", sender.getUsername()); + + Optional opm = PlayerMetaManager.getInstance().getPlayer(sender.getUniqueId()); + if (opm.isPresent()) { + messageFormat = messageFormat.replace("%PREFIX%", opm.get().prefix); + messageFormat = messageFormat.replace("%SUFFIX%", opm.get().suffix); + messageFormat = messageFormat.replace("%NICK%", opm.get().nick); + } + + messageFormat = messageFormat.replace("%DISPLAYNAMET%", "CONSOLE"); + messageFormat = messageFormat.replace("%NAMET%", "CONSOLE"); + + messageFormat = messageFormat.replace("%PREFIXT%", ""); + messageFormat = messageFormat.replace("%SUFFIXT%", ""); + messageFormat = messageFormat.replace("%NICKT%", "CONSOLE"); + + messageFormat = messageFormat.replace("%SERVER%", sender.getCurrentServer().get().getServerInfo().getName()); + messageFormat = messageFormat.replace("%SERVERT%", "CONSOLE"); + + messageFormat = messageFormat.replace("%WORLD%", opm.get().world); + messageFormat = messageFormat.replace("%WORLDT%", "CONSOLE"); + + return messageFormat; + + } + + public String replaceMsgConsoleSenderVars(String messageFormat, String message, Player target) { + + messageFormat = messageFormat.replace("%MESSAGE%", message); + messageFormat = messageFormat.replace("%DISPLAYNAME%", "CONSOLE"); + messageFormat = messageFormat.replace("%NAME%", "CONSOLE"); + + messageFormat = messageFormat.replace("%PREFIX%", ""); + messageFormat = messageFormat.replace("%SUFFIX%", ""); + messageFormat = messageFormat.replace("%NICK%", "CONSOLE"); + + messageFormat = messageFormat.replace("%DISPLAYNAMET%", target.getUsername()); + messageFormat = messageFormat.replace("%NAMET%", target.getUsername()); + + Optional opmt = PlayerMetaManager.getInstance().getPlayer(target.getUniqueId()); + if (opmt.isPresent()) { + messageFormat = messageFormat.replace("%PREFIXT%", opmt.get().prefix); + messageFormat = messageFormat.replace("%SUFFIXT%", opmt.get().suffix); + messageFormat = messageFormat.replace("%NICKT%", opmt.get().nick); + } + + messageFormat = messageFormat.replace("%SERVER%", "CONSOLE"); + messageFormat = messageFormat.replace("%SERVERT%", target.getCurrentServer().get().getServerInfo().getName()); + + messageFormat = messageFormat.replace("%WORLD%", "CONSOLE"); + messageFormat = messageFormat.replace("%WORLDT%", opmt.get().world); + + return messageFormat; + + } + + public String replaceModChatVars(String messageFormat, String playername, String displayname, String server, String message, Player target) { + + messageFormat = messageFormat.replace("%DISPLAYNAME%", displayname); + messageFormat = messageFormat.replace("%NAME%", playername); + messageFormat = messageFormat.replace("%SERVER%", server); + messageFormat = messageFormat.replace("%MESSAGE%", message); + messageFormat = messageFormat.replace("%CC%", "&" + MultiChat.modchatpreferences.get(target.getUniqueId()).getChatColor()); + messageFormat = messageFormat.replace("%NC%", "&" + MultiChat.modchatpreferences.get(target.getUniqueId()).getNameColor()); + return messageFormat; + + } + + public String replaceAdminChatVars(String messageFormat, String playername, String displayname, String server, String message, Player target) { + + messageFormat = messageFormat.replace("%DISPLAYNAME%",displayname); + messageFormat = messageFormat.replace("%NAME%", playername); + messageFormat = messageFormat.replace("%SERVER%", server); + messageFormat = messageFormat.replace("%MESSAGE%", message); + messageFormat = messageFormat.replace("%CC%", "&" + MultiChat.adminchatpreferences.get(target.getUniqueId()).getChatColor()); + messageFormat = messageFormat.replace("%NC%", "&" + MultiChat.adminchatpreferences.get(target.getUniqueId()).getNameColor()); + return messageFormat; + + } + + public String replaceGroupChatVars(String messageFormat, String sendername, String message, String groupName) { + + messageFormat = messageFormat.replace("%NAME%", sendername); + messageFormat = messageFormat.replace("%MESSAGE%", message); + messageFormat = messageFormat.replace("%CC%", "&" + MultiChat.groupchats.get(groupName).getChatColor()); + messageFormat = messageFormat.replace("%NC%", "&" + MultiChat.groupchats.get(groupName).getNameColor()); + messageFormat = messageFormat.replace("%GROUPNAME%", groupName.toUpperCase()); + return messageFormat; + + } + + public String replaceJoinMsgVars(String MessageFormat, String sendername) { + + MessageFormat = MessageFormat.replace("%NAME%", sendername); + return MessageFormat; + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatModeManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatModeManager.java new file mode 100644 index 00000000..333191ee --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ChatModeManager.java @@ -0,0 +1,99 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.proxy.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class ChatModeManager { + + private static final ChatModeManager instance; + + public static ChatModeManager getInstance() { + return instance; + } + + static { + instance = new ChatModeManager(); + } + + /* END STATIC */ + + private Map globalPlayers; + + private ChatModeManager() { + globalPlayers = new HashMap<>(); + } + + public void setLocal(UUID uuid) { + + globalPlayers.put(uuid, false); + + // TODO + Channel.setChannel(uuid, Channel.getLocalChannel()); + + // TODO + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + if (player == null) return; + + Channel local = Channel.getLocalChannel(); + if (!local.isMember(uuid)) { + local.removeMember(uuid); + MessageManager.sendSpecialMessage(player, "command_channel_show", "LOCAL"); + } + + BungeeComm.sendPlayerChannelMessage(player.getUsername(), Channel.getChannel(uuid).getName(), Channel.getChannel(uuid), player.getCurrentServer().get().getServerInfo(), (player.hasPermission("multichat.chat.colour") || player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.colour.simple") || player.hasPermission("multichat.chat.color.simple")), (player.hasPermission("multichat.chat.colour") || player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.colour.rgb") || player.hasPermission("multichat.chat.color.rgb"))); + + } + + public void setGlobal(UUID uuid) { + + globalPlayers.put(uuid, true); + + // TODO + Channel.setChannel(uuid, Channel.getGlobalChannel()); + + // TODO + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + if (player == null) return; + + Channel global = Channel.getGlobalChannel(); + if (!global.isMember(uuid)) { + global.removeMember(uuid); + MessageManager.sendSpecialMessage(player, "command_channel_show", "GLOBAL"); + } + + BungeeComm.sendPlayerChannelMessage(player.getUsername(), Channel.getChannel(uuid).getName(), Channel.getChannel(uuid), player.getCurrentServer().get().getServerInfo(), (player.hasPermission("multichat.chat.colour") || player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.colour.simple") || player.hasPermission("multichat.chat.color.simple")), (player.hasPermission("multichat.chat.colour") || player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.colour.rgb") || player.hasPermission("multichat.chat.color.rgb"))); + + } + + public void registerPlayer(UUID uuid, boolean global) { + + globalPlayers.put(uuid, global); + + } + + public boolean existsPlayer(UUID uuid) { + + return globalPlayers.containsKey(uuid); + + } + + public Map getData() { + return globalPlayers; + } + + public void loadData(Map data) { + this.globalPlayers = data; + if (this.globalPlayers == null) { + DebugManager.log("The global players data loaded was null... So made a new map!"); + globalPlayers = new HashMap<>(); + } + } + + public boolean isGlobal(UUID uuid) { + return globalPlayers.getOrDefault(uuid, true); + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/CommandManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/CommandManager.java new file mode 100644 index 00000000..a30ebe16 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/CommandManager.java @@ -0,0 +1,479 @@ +package xyz.olivermartin.multichat.velocity; + +import xyz.olivermartin.multichat.velocity.commands.*; + +public class CommandManager { + + static { + + acc = new ACCCommand(); + ac = new ACCommand(); + announcement = new AnnouncementCommand(); + bulletin = new BulletinCommand(); + cast = new CastCommand(); + channel = new ChannelCommand(); + clearchat = new ClearChatCommand(); + display = new DisplayCommand(); + freezechat = new FreezeChatCommand(); + gc = new GCCommand(); + global = new GlobalCommand(); + group = new GroupCommand(); + grouplist = new GroupListCommand(); + helpme = new HelpMeCommand(); + ignore = new IgnoreCommand(); + local = new LocalCommand(); + mcc = new MCCCommand(); + mc = new MCCommand(); + msg = new MsgCommand(); + multichat = new MultiChatCommand(); + multichatbypass = new MultiChatBypassCommand(); + multichatexecute = new MultiChatExecuteCommand(); + mute = new MuteCommand(); + reply = new ReplyCommand(); + socialspy = new SocialSpyCommand(); + stafflist = new StaffListCommand(); + usecast = new UseCastCommand(); + + } + + private static Command acc; + private static Command ac; + private static Command announcement; + private static Command bulletin; + private static Command cast; + private static Command channel; + private static Command clearchat; + private static Command display; + private static Command freezechat; + private static Command gc; + private static Command global; + private static Command group; + private static Command grouplist; + private static Command helpme; + private static Command ignore; + private static Command local; + private static Command mcc; + private static Command mc; + private static Command msg; + private static Command multichat; + private static Command multichatbypass; + private static Command multichatexecute; + + /** + * @return the multichatexecute + */ + public static Command getMultiChatExecute() { + return multichatexecute; + } + + /** + * @param multichatexecute the multichatexecute to set + */ + public static void setMultiChatExecute(Command multichatexecute) { + CommandManager.multichatexecute = multichatexecute; + } + + private static Command mute; + private static Command reply; + private static Command socialspy; + private static Command stafflist; + private static Command usecast; + + /** + * @return the acc + */ + public static Command getAcc() { + return acc; + } + + /** + * @param acc the acc to set + */ + public static void setAcc(Command acc) { + CommandManager.acc = acc; + } + + /** + * @return the ac + */ + public static Command getAc() { + return ac; + } + + /** + * @param ac the ac to set + */ + public static void setAc(Command ac) { + CommandManager.ac = ac; + } + + /** + * @return the announcement + */ + public static Command getAnnouncement() { + return announcement; + } + + /** + * @param announcement the announcement to set + */ + public static void setAnnouncement(Command announcement) { + CommandManager.announcement = announcement; + } + + /** + * @return the bulletin + */ + public static Command getBulletin() { + return bulletin; + } + + /** + * @param bulletin the bulletin to set + */ + public static void setBulletin(Command bulletin) { + CommandManager.bulletin = bulletin; + } + + /** + * @return the cast + */ + public static Command getCast() { + return cast; + } + + /** + * @param cast the cast to set + */ + public static void setCast(Command cast) { + CommandManager.cast = cast; + } + + /** + * @return the channel + */ + public static Command getChannel() { + return channel; + } + + /** + * @param channel the channel to set + */ + public static void setChannel(Command channel) { + CommandManager.channel = channel; + } + + /** + * @return the clearchat + */ + public static Command getClearchat() { + return clearchat; + } + + /** + * @param clearchat the clearchat to set + */ + public static void setClearchat(Command clearchat) { + CommandManager.clearchat = clearchat; + } + + /** + * @return the display + */ + public static Command getDisplay() { + return display; + } + + /** + * @param display the display to set + */ + public static void setDisplay(Command display) { + CommandManager.display = display; + } + + /** + * @return the freezechat + */ + public static Command getFreezechat() { + return freezechat; + } + + /** + * @param freezechat the freezechat to set + */ + public static void setFreezechat(Command freezechat) { + CommandManager.freezechat = freezechat; + } + + /** + * @return the gc + */ + public static Command getGc() { + return gc; + } + + /** + * @param gc the gc to set + */ + public static void setGc(Command gc) { + CommandManager.gc = gc; + } + + /** + * @return the global + */ + public static Command getGlobal() { + return global; + } + + /** + * @param global the global to set + */ + public static void setGlobal(Command global) { + CommandManager.global = global; + } + + /** + * @return the group + */ + public static Command getGroup() { + return group; + } + + /** + * @param group the group to set + */ + public static void setGroup(Command group) { + CommandManager.group = group; + } + + /** + * @return the grouplist + */ + public static Command getGrouplist() { + return grouplist; + } + + /** + * @param grouplist the grouplist to set + */ + public static void setGrouplist(Command grouplist) { + CommandManager.grouplist = grouplist; + } + + /** + * @return the helpme + */ + public static Command getHelpme() { + return helpme; + } + + /** + * @param helpme the helpme to set + */ + public static void setHelpme(Command helpme) { + CommandManager.helpme = helpme; + } + + /** + * @return the ignore + */ + public static Command getIgnore() { + return ignore; + } + + /** + * @param ignore the ignore to set + */ + public static void setIgnore(Command ignore) { + CommandManager.ignore = ignore; + } + + /** + * @return the local + */ + public static Command getLocal() { + return local; + } + + /** + * @param local the local to set + */ + public static void setLocal(Command local) { + CommandManager.local = local; + } + + /** + * @return the mcc + */ + public static Command getMcc() { + return mcc; + } + + /** + * @param mcc the mcc to set + */ + public static void setMcc(Command mcc) { + CommandManager.mcc = mcc; + } + + /** + * @return the mc + */ + public static Command getMc() { + return mc; + } + + /** + * @param mc the mc to set + */ + public static void setMc(Command mc) { + CommandManager.mc = mc; + } + + /** + * @return the msg + */ + public static Command getMsg() { + return msg; + } + + /** + * @param msg the msg to set + */ + public static void setMsg(Command msg) { + CommandManager.msg = msg; + } + + /** + * @return the multichat + */ + public static Command getMultichat() { + return multichat; + } + + /** + * @param multichat the multichat to set + */ + public static void setMultichat(Command multichat) { + CommandManager.multichat = multichat; + } + + /** + * @return the multichatbypass + */ + public static Command getMultichatBypass() { + return multichatbypass; + } + + /** + * @param multichatbypass the multichatbypass to set + */ + public static void setMultichatBypass(Command multichatbypass) { + CommandManager.multichatbypass = multichatbypass; + } + + /** + * @return the mute + */ + public static Command getMute() { + return mute; + } + + /** + * @param mute the mute to set + */ + public static void setMute(Command mute) { + CommandManager.mute = mute; + } + + /** + * @return the reply + */ + public static Command getReply() { + return reply; + } + + /** + * @param reply the reply to set + */ + public static void setReply(Command reply) { + CommandManager.reply = reply; + } + + /** + * @return the socialspy + */ + public static Command getSocialspy() { + return socialspy; + } + + /** + * @param socialspy the socialspy to set + */ + public static void setSocialspy(Command socialspy) { + CommandManager.socialspy = socialspy; + } + + /** + * @return the stafflist + */ + public static Command getStafflist() { + return stafflist; + } + + /** + * @param stafflist the stafflist to set + */ + public static void setStafflist(Command stafflist) { + CommandManager.stafflist = stafflist; + } + + /** + * @return the usecast + */ + public static Command getUsecast() { + return usecast; + } + + /** + * @param usecast the usecast to set + */ + public static void setUsecast(Command usecast) { + CommandManager.usecast = usecast; + } + + /** + * Generates new instances of all commands + */ + public static void reload() { + acc = new ACCCommand(); + ac = new ACCommand(); + announcement = new AnnouncementCommand(); + bulletin = new BulletinCommand(); + cast = new CastCommand(); + channel = new ChannelCommand(); + clearchat = new ClearChatCommand(); + display = new DisplayCommand(); + freezechat = new FreezeChatCommand(); + gc = new GCCommand(); + global = new GlobalCommand(); + group = new GroupCommand(); + grouplist = new GroupListCommand(); + helpme = new HelpMeCommand(); + ignore = new IgnoreCommand(); + local = new LocalCommand(); + mcc = new MCCCommand(); + mc = new MCCommand(); + msg = new MsgCommand(); + multichat = new MultiChatCommand(); + multichatbypass = new MultiChatBypassCommand(); + multichatexecute = new MultiChatExecuteCommand(); + mute = new MuteCommand(); + reply = new ReplyCommand(); + socialspy = new SocialSpyCommand(); + stafflist = new StaffListCommand(); + usecast = new UseCastCommand(); + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConfigHandler.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConfigHandler.java new file mode 100644 index 00000000..60b03e19 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConfigHandler.java @@ -0,0 +1,88 @@ +package xyz.olivermartin.multichat.velocity; + + +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.yaml.YAMLConfigurationLoader; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Objects; + +/** + * Configuration Handler Class + *

Manages loading / creation of an individual configuration file

+ * + * @author Oliver Martin (Revilo410) + */ +public class ConfigHandler { + + // The config file + private ConfigurationNode config; + // Path of config file + private final File configPath; + // Name of config file + private final String fileName; + + public ConfigHandler(File configPath, String fileName) { + + this.configPath = configPath; + this.config = null; + this.fileName = fileName; + this.startupConfig(); + + } + + public ConfigurationNode getConfig() { + if (config == null) startupConfig(); + return config; + } + + public void startupConfig() { + + try { + + File file = new File(configPath, fileName); + + if (!file.exists()) { + + MultiChat.getInstance().getLogger().info("Config file " + fileName + " not found... Creating new one."); + saveDefaultConfig(); + + loadConfig(); + + } else { + + MultiChat.getInstance().getLogger().info("Loading " + fileName + "..."); + loadConfig(); + + } + + } catch (Exception e) { + MultiChat.getInstance().getLogger().info("[ERROR] Could not load " + fileName); + e.printStackTrace(); + } + } + + private void saveDefaultConfig() { + + // Load default file into input stream + // Copy to desired location + try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName)) { + Files.copy(Objects.requireNonNull(inputStream), new File(configPath, fileName).toPath()); + } catch (IOException | NullPointerException e) { + MultiChat.getInstance().getLogger().info("[ERROR] Could not create new " + fileName + " file..."); + e.printStackTrace(); + } + } + + private void loadConfig() { + try { + this.config = YAMLConfigurationLoader.builder().setFile(new File(configPath, fileName)).build().load(); + } catch (IOException e) { + MultiChat.getInstance().getLogger().info("[ERROR] Could not load " + fileName + " file..."); + e.printStackTrace(); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConfigManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConfigManager.java new file mode 100644 index 00000000..d44d84f3 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConfigManager.java @@ -0,0 +1,71 @@ +package xyz.olivermartin.multichat.velocity; + + +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +/** + * Configuration Manager Class + *

Manages all access and creation of the config.yml file

+ * + * @author Oliver Martin (Revilo410) + */ +public class ConfigManager { + + private static final ConfigManager instance; + + static { + + instance = new ConfigManager(); + + } + + public static ConfigManager getInstance() { + return instance; + } + + // END OF STATIC + + private final Map handlerMap; + + private ConfigManager() { + + handlerMap = new HashMap(); + + } + + /** + * Create a new configHandler for a given filename and path + * + * @param fileName filename i.e. config.yml + * @param configPath THE PATH WITHOUT THE FILE NAME + */ + public void registerHandler(String fileName, File configPath) { + + handlerMap.put(fileName, new ConfigHandler(configPath, fileName)); + + } + + public Optional getSafeHandler(String fileName) { + + if (handlerMap.containsKey(fileName)) { + return Optional.of(handlerMap.get(fileName)); + } + + return Optional.empty(); + + } + + public ConfigHandler getHandler(String fileName) { + + if (handlerMap.containsKey(fileName)) { + return handlerMap.get(fileName); + } + + return null; + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConsoleManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConsoleManager.java new file mode 100644 index 00000000..b502d942 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/ConsoleManager.java @@ -0,0 +1,88 @@ +package xyz.olivermartin.multichat.velocity; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +public class ConsoleManager { + + public static void log(String message) { + logToConsole(message); + } + + public static void logDisplayMessage(String message) { + logToConsole(MessageManager.getMessage("console_display_prefix") + message); + } + + public static void logChat(String message) { + + logToConsole(MessageManager.getMessage("console_chat_prefix") + message); + + } + + public static void logModChat(String message) { + + if (!MultiChat.logStaffChat) { + return; + } + + logToConsole(MessageManager.getMessage("console_modchat_prefix") + message); + + } + + public static void logGroupChat(String message) { + + if (!MultiChat.logGroupChat) { + return; + } + + logToConsole(MessageManager.getMessage("console_groupchat_prefix") + message); + + } + + public static void logAdminChat(String message) { + + if (!MultiChat.logStaffChat) { + return; + } + + logToConsole(MessageManager.getMessage("console_adminchat_prefix") + message); + + } + + public static void logHelpMe(String message) { + + logToConsole(MessageManager.getMessage("console_helpme_prefix") + message); + + } + + + public static void logBasicChat(String prefix, String message) { + + logToConsole(MessageManager.getMessage("console_chat_prefix") + prefix, message); + + } + + public static void logSocialSpy(String p1, String p2, String message) { + + if (!MultiChat.logPMs) { + return; + } + + logToConsole(MessageManager.getMessage("console_socialspy_prefix") + "(" + p1 + " -> " + p2 + ") " + message); + + } + + private static void logToConsole(String message, String unformattedMessage) { + Component first = LegacyComponentSerializer.legacyAmpersand().deserialize(MessageManager.getMessage("console_main_prefix") + MultiChatUtil.approximateHexCodes(MultiChatUtil.reformatRGB(message))); + + Component second = LegacyComponentSerializer.legacySection().deserialize(unformattedMessage); + + Component both = first.append(second); + + MultiChat.getInstance().getServer().getConsoleCommandSource().sendMessage(both); + } + + private static void logToConsole(String message) { + logToConsole(message, ""); + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/DebugManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/DebugManager.java new file mode 100644 index 00000000..3cfb8e73 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/DebugManager.java @@ -0,0 +1,23 @@ +package xyz.olivermartin.multichat.velocity; + +public class DebugManager { + + private static boolean debug; + + static { + debug = false; + } + + public static void setDebug(boolean debug) { + DebugManager.debug = debug; + } + + public static void toggle() { + debug = !debug; + } + + public static void log(String message) { + if (debug) ConsoleManager.log("[DEBUG] " + message); + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Events.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Events.java new file mode 100644 index 00000000..c0bebb60 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/Events.java @@ -0,0 +1,547 @@ +package xyz.olivermartin.multichat.velocity; + +import com.olivermartin410.plugins.TChatInfo; +import com.olivermartin410.plugins.TGroupChatInfo; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; +import com.velocitypowered.api.event.connection.PostLoginEvent; +import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import ninja.leaping.configurate.ConfigurationNode; +import xyz.olivermartin.multichat.velocity.commands.GCCommand; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * Events Manager + *

Manages the majority of the event listeners, chat message, login and logout

+ * + * @author Oliver Martin (Revilo410) + */ +public class Events { + + public static List mcbPlayers = new ArrayList<>(); + + private static final List MCToggle = new ArrayList<>(); + private static final List ACToggle = new ArrayList<>(); + private static final List GCToggle = new ArrayList<>(); + public static Map PMToggle = new HashMap<>(); + + public static Set hiddenStaff = new HashSet<>(); + + public static boolean toggleMC(UUID uuid) { + + if (MCToggle.contains(uuid)) { + MCToggle.remove(uuid); + return false; + } + + ACToggle.remove(uuid); + GCToggle.remove(uuid); + PMToggle.remove(uuid); + + MCToggle.add(uuid); + return true; + + } + + public static boolean toggleAC(UUID uuid) { + + if (ACToggle.contains(uuid)) { + ACToggle.remove(uuid); + return false; + } + + MCToggle.remove(uuid); + GCToggle.remove(uuid); + PMToggle.remove(uuid); + + ACToggle.add(uuid); + return true; + + } + + public static boolean toggleGC(UUID uuid) { + + if (GCToggle.contains(uuid)) { + GCToggle.remove(uuid); + return false; + } + + MCToggle.remove(uuid); + ACToggle.remove(uuid); + PMToggle.remove(uuid); + + GCToggle.add(uuid); + return true; + + } + + public static boolean togglePM(UUID uuid, UUID uuidt) { + + if (PMToggle.containsKey(uuid)) { + PMToggle.remove(uuid); + return false; + } + + MCToggle.remove(uuid); + ACToggle.remove(uuid); + GCToggle.remove(uuid); + + PMToggle.put(uuid, uuidt); + return true; + + } + + @Subscribe(async = false) + public void onChat(PlayerChatEvent event) { + + Player player = event.getPlayer(); + + // New null pointer checks + if (player.getCurrentServer().isEmpty()) { + DebugManager.log("Player sending chat message has null server! Abandoning..."); + return; + } else { + if (player.getCurrentServer().get().getServerInfo() == null) { + DebugManager.log("Player sending chat message has null server info! Abandoning..."); + return; + } + } + + // If player is bypassing MultiChat + if (mcbPlayers.contains(player.getUniqueId())) { + return; + } + + /// + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + if (player.getCurrentServer().isPresent()) { + BungeeComm.sendMessage(player.getUsername(), player.getCurrentServer().get().getServerInfo()); + } + } + /// + + if (MCToggle.contains(player.getUniqueId())) { + + String message = event.getMessage(); + + if (!event.getMessage().trim().startsWith("/")) { + StaffChatManager chatman = new StaffChatManager(); + event.setResult(PlayerChatEvent.ChatResult.denied()); + chatman.sendModMessage(player.getUsername(), player.getUsername(), player.getCurrentServer().get().getServerInfo().getName(), message); + } + } + + if (ACToggle.contains(player.getUniqueId())) { + + String message = event.getMessage(); + + if (!event.getMessage().trim().startsWith("/")) { + StaffChatManager chatman = new StaffChatManager(); + event.setResult(PlayerChatEvent.ChatResult.denied()); + chatman.sendAdminMessage(player.getUsername(), player.getUsername(), player.getCurrentServer().get().getServerInfo().getName(), message); + } + } + + if (GCToggle.contains(player.getUniqueId())) { + + String message = event.getMessage(); + + if (!event.getMessage().trim().startsWith("/")) { + + + event.setResult(PlayerChatEvent.ChatResult.denied()); + + if (MultiChat.viewedchats.get(player.getUniqueId()) != null) { + + String chatName = MultiChat.viewedchats.get(player.getUniqueId()).toLowerCase(); + + if (MultiChat.groupchats.containsKey(chatName)) { + + TGroupChatInfo chatInfo = MultiChat.groupchats.get(chatName); + String playerName = player.getUsername(); + + if (chatInfo.getFormal() + && chatInfo.getAdmins().contains(player.getUniqueId())) { + + playerName = "&o" + playerName; + + } + + GCCommand.sendMessage(message, playerName, chatInfo); + + } else { + MessageManager.sendMessage(player, "groups_toggled_but_no_longer_exists_1"); + MessageManager.sendMessage(player, "groups_toggled_but_no_longer_exists_2"); + } + + } else { + MessageManager.sendMessage(player, "groups_toggled_but_no_longer_exists_1"); + MessageManager.sendMessage(player, "groups_toggled_but_no_longer_exists_2"); + } + } + } + + if (PMToggle.containsKey(player.getUniqueId())) { + + String message = event.getMessage(); + + if (!event.getMessage().trim().startsWith("/")) { + + Optional crm; + + + event.setResult(PlayerChatEvent.ChatResult.denied()); + + if (ChatControl.isMuted(player.getUniqueId(), "private_messages")) { + MessageManager.sendMessage(player, "mute_cannot_send_message"); + return; + } + + if (ChatControl.handleSpam(player, message, "private_messages")) { + return; + } + + crm = ChatControl.applyChatRules(message, "private_messages", player.getUsername()); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return; + } + + if (MultiChat.getInstance().getServer().getPlayer(PMToggle.get(player.getUniqueId())).isPresent()) { + + Player target = MultiChat.getInstance().getServer().getPlayer(PMToggle.get(player.getUniqueId())).orElse(null); + + BungeeComm.sendMessage(player.getUsername(), player.getCurrentServer().get().getServerInfo()); + BungeeComm.sendMessage(target.getUsername(), target.getCurrentServer().get().getServerInfo()); + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(player.getCurrentServer().get().getServerInfo().getName())) { + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(target.getCurrentServer().get().getServerInfo().getName())) { + + if (ChatControl.ignores(player.getUniqueId(), target.getUniqueId(), "private_messages")) { + ChatControl.sendIgnoreNotifications(target, player, "private_messages"); + return; + } + + PrivateMessageManager.getInstance().sendMessage(message, player, target); + + } else { + MessageManager.sendMessage(player, "command_msg_disabled_target"); + } + + } else { + MessageManager.sendMessage(player, "command_msg_disabled_sender"); + } + + } else { + MessageManager.sendMessage(player, "command_msg_not_online"); + } + + } + } + + if (event.getMessage().trim().startsWith("/")) { + + String[] parts = event.getMessage().split(" "); + + if (CastControl.castList.containsKey(parts[0].substring(1).toLowerCase())) { + + if (player.hasPermission("multichat.cast." + parts[0].substring(1).toLowerCase()) + || player.hasPermission("multichat.cast.admin")) { + + String message = MultiChatUtil.getMessageFromArgs(parts, 1); + + CastControl.sendCast(parts[0].substring(1), message, Channel.getChannel(player.getUniqueId()), player); + + + event.setResult(PlayerChatEvent.ChatResult.denied()); + + } + + } + } + + if (event.getResult() == PlayerChatEvent.ChatResult.allowed() && !event.getMessage().trim().startsWith("/")) { + if (!MultiChat.frozen || player.hasPermission("multichat.chat.always")) { + + String message = event.getMessage(); + + if (ChatControl.isMuted(player.getUniqueId(), "global_chat")) { + MessageManager.sendMessage(player, "mute_cannot_send_message"); + + event.setResult(PlayerChatEvent.ChatResult.denied()); + return; + } + + DebugManager.log(player.getUsername() + "- about to check for spam"); + + if (ChatControl.handleSpam(player, message, "global_chat")) { + DebugManager.log(player.getUsername() + " - chat message being cancelled due to spam"); + + event.setResult(PlayerChatEvent.ChatResult.denied()); + return; + } + + Optional crm; + + crm = ChatControl.applyChatRules(message, "global_chat", player.getUsername()); + + if (crm.isPresent()) { + message = crm.get(); + event.setResult(PlayerChatEvent.ChatResult.message(message)); + } else { + + event.setResult(PlayerChatEvent.ChatResult.denied()); + return; + } + + if (!player.hasPermission("multichat.chat.link")) { + message = ChatControl.replaceLinks(message); + event.setResult(PlayerChatEvent.ChatResult.message(message)); + } + + DebugManager.log("Does player have ALL colour permission? " + (player.hasPermission("multichat.chat.colour") || player.hasPermission("multichat.chat.color"))); + + DebugManager.log("Does player have simple colour permission? " + (player.hasPermission("multichat.chat.colour.simple") || player.hasPermission("multichat.chat.color.simple"))); + + DebugManager.log("Does player have rgb colour permission? " + (player.hasPermission("multichat.chat.colour.rgb") || player.hasPermission("multichat.chat.color.rgb"))); + + if (Channel.getChannel(player.getUniqueId()) == null) { + return; + } + + // Let server know players channel preference + BungeeComm.sendPlayerChannelMessage(player.getUsername(), + Channel.getChannel(player.getUniqueId()).getName(), + Channel.getChannel(player.getUniqueId()), + player.getCurrentServer().get().getServerInfo(), + (player.hasPermission("multichat.chat.colour") + || player.hasPermission("multichat.chat.color") + || player.hasPermission("multichat.chat.colour.simple") + || player.hasPermission("multichat.chat.color.simple")), + (player.hasPermission("multichat.chat.colour") + || player.hasPermission("multichat.chat.color") + || player.hasPermission("multichat.chat.colour.rgb") + || player.hasPermission("multichat.chat.color.rgb"))); + + // Message passes through to spigot here + + hiddenStaff.remove(player.getUniqueId()); + + } else { + MessageManager.sendMessage(player, "freezechat_frozen"); + + event.setResult(PlayerChatEvent.ChatResult.denied()); + } + + } + } + + @Subscribe + public void onLogin(PostLoginEvent event) { + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + boolean firstJoin = false; + + if (player.hasPermission("multichat.staff.mod")) { + if (!MultiChat.modchatpreferences.containsKey(uuid)) { + TChatInfo chatinfo = new TChatInfo(); + chatinfo.setChatColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("modchat").getNode("ccdefault").getString().toCharArray()[0]); + chatinfo.setNameColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("modchat").getNode("ncdefault").getString().toCharArray()[0]); + MultiChat.modchatpreferences.put(uuid, chatinfo); + } + } + + if (player.hasPermission("multichat.staff.admin")) { + if (!MultiChat.adminchatpreferences.containsKey(uuid)) { + TChatInfo chatinfo = new TChatInfo(); + chatinfo.setChatColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("adminchat").getNode("ccdefault").getString().toCharArray()[0]); + chatinfo.setNameColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("adminchat").getNode("ncdefault").getString().toCharArray()[0]); + MultiChat.adminchatpreferences.put(uuid, chatinfo); + } + } + + PlayerMetaManager.getInstance().registerPlayer(uuid, event.getPlayer().getUsername()); + + if (!MultiChat.viewedchats.containsKey(uuid)) { + MultiChat.viewedchats.put(uuid, null); + ConsoleManager.log("Registered player " + player.getUsername()); + } + + if (!ChatModeManager.getInstance().existsPlayer(uuid)) { + boolean globalMode; + globalMode = !MultiChat.defaultChannel.equalsIgnoreCase("local"); + ChatModeManager.getInstance().registerPlayer(uuid, globalMode); + firstJoin = true; + } + + if (MultiChat.forceChannelOnJoin) { + boolean globalMode; + globalMode = !MultiChat.defaultChannel.equalsIgnoreCase("local"); + ChatModeManager.getInstance().registerPlayer(uuid, globalMode); + } + + // Set player to appropriate channels + if (ChatModeManager.getInstance().isGlobal(uuid)) { + Channel.setChannel(player.getUniqueId(), Channel.getGlobalChannel()); + } else { + Channel.setChannel(player.getUniqueId(), Channel.getLocalChannel()); + } + + if (UUIDNameManager.existsUUID(uuid)) { + UUIDNameManager.removeUUID(uuid); + } + + UUIDNameManager.addNew(uuid, player.getUsername()); + + ConsoleManager.log("Refreshed UUID-Name lookup: " + uuid.toString()); + + if (ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("showjoin").getBoolean()) { + + String joinformat = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("serverjoin").getString(); + String silentformat = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("silentjoin").getString(); + String welcomeMessage = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("welcome_message").getString(); + String privateWelcomeMessage = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("private_welcome_message").getString(); + + ChatManipulation chatman = new ChatManipulation(); + + joinformat = chatman.replaceJoinMsgVars(joinformat, player.getUsername()); + silentformat = chatman.replaceJoinMsgVars(silentformat, player.getUsername()); + welcomeMessage = chatman.replaceJoinMsgVars(welcomeMessage, player.getUsername()); + privateWelcomeMessage = chatman.replaceJoinMsgVars(privateWelcomeMessage, player.getUsername()); + + boolean broadcastWelcome = true; + if (ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getChildrenMap().containsKey("welcome")) { + broadcastWelcome = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("welcome").getBoolean(); + } + + boolean privateWelcome = false; + if (ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getChildrenMap().containsKey("private_welcome")) { + privateWelcome = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("private_welcome").getBoolean(); + } + + boolean broadcastJoin = !player.hasPermission("multichat.staff.silentjoin"); + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (broadcastJoin) { + + if (firstJoin && broadcastWelcome) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(welcomeMessage)); + } + + if (firstJoin && privateWelcome && onlineplayer.getUsername().equals(player.getUsername())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(privateWelcomeMessage)); + } + + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(joinformat)); + } else { + + hiddenStaff.add(player.getUniqueId()); + + if (onlineplayer.hasPermission("multichat.staff.silentjoin")) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(silentformat)); + } + + } + } + } + } + + @Subscribe + public void onLogout(DisconnectEvent event) { + + Player player = event.getPlayer(); + UUID uuid = event.getPlayer().getUniqueId(); + + hiddenStaff.remove(uuid); + + mcbPlayers.remove(uuid); + + MCToggle.remove(uuid); + ACToggle.remove(uuid); + GCToggle.remove(uuid); + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (config.getNode("session_ignore").getBoolean()) { + ChatControl.unignoreAll(uuid); + } + + // Reset their spam data on logout (nothing is stored persistantly) + ChatControl.spamPardonPlayer(uuid); + + /// + Channel.removePlayer(player.getUniqueId()); + /// + + MultiChat.viewedchats.remove(uuid); + + PlayerMetaManager.getInstance().unregisterPlayer(uuid); + + ConsoleManager.log("Un-Registered player " + player.getUsername()); + + if (!Channel.getGlobalChannel().isMember(player.getUniqueId())) { + Channel.getGlobalChannel().removeMember(uuid); + } + + if (!Channel.getLocalChannel().isMember(player.getUniqueId())) { + Channel.getLocalChannel().removeMember(uuid); + } + + if (ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("showquit").getBoolean()) { + + String joinformat = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("networkquit").getString(); + String silentformat = ConfigManager.getInstance().getHandler("joinmessages.yml").getConfig().getNode("silentquit").getString(); + + ChatManipulation chatman = new ChatManipulation(); + + joinformat = chatman.replaceJoinMsgVars(joinformat, player.getUsername()); + silentformat = chatman.replaceJoinMsgVars(silentformat, player.getUsername()); + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (!player.hasPermission("multichat.staff.silentjoin")) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(joinformat)); + } else { + if (onlineplayer.hasPermission("multichat.staff.silentjoin")) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(silentformat)); + } + } + } + } + } + + + @Subscribe + public void onServerSwitch(ServerConnectedEvent event) { + // Tell the new server the player's channel preference + MultiChat.getInstance().getServer().getScheduler().buildTask(MultiChat.getInstance(), () -> { + try { + BungeeComm.sendPlayerChannelMessage(event.getPlayer().getUsername(), + Channel.getChannel(event.getPlayer().getUniqueId()).getName(), + Channel.getChannel(event.getPlayer().getUniqueId()), + event.getPlayer().getCurrentServer().get().getServerInfo(), + event.getPlayer().hasPermission("multichat.chat.color") || event.getPlayer().hasPermission("multichat.chat.colour.simple"), + event.getPlayer().hasPermission("multichat.chat.color") || event.getPlayer().hasPermission("multichat.chat.colour.rgb")); + + // LEGACY SERVER HACK + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("legacy_servers").getList(String::valueOf).contains(event.getPlayer().getCurrentServer().get().getServerInfo().getName())) { + DebugManager.log("Player: " + event.getPlayer().getUsername() + ", switching to server: " + event.getPlayer().getCurrentServer().get().getServerInfo().getName() + ", is a LEGACY server!"); + BungeeComm.sendCommandMessage("!!!LEGACYSERVER!!!", event.getPlayer().getCurrentServer().get().getServerInfo()); + } else { + BungeeComm.sendCommandMessage("!!!NOTLEGACYSERVER!!!", event.getPlayer().getCurrentServer().get().getServerInfo()); + } + + } catch (NullPointerException ex) { /* EMPTY */ } + }).delay(500L, TimeUnit.MILLISECONDS).schedule(); + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/GlobalChannel.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/GlobalChannel.java new file mode 100644 index 00000000..ef475633 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/GlobalChannel.java @@ -0,0 +1,9 @@ +package xyz.olivermartin.multichat.velocity; + +public class GlobalChannel extends Channel { + + public GlobalChannel(String format) { + super("global", format, false, false); + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/GroupManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/GroupManager.java new file mode 100644 index 00000000..f8456f56 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/GroupManager.java @@ -0,0 +1,216 @@ +package xyz.olivermartin.multichat.velocity; + +import com.olivermartin410.plugins.TGroupChatInfo; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.commands.GCCommand; + +import java.util.UUID; + +/** + * Group Chat Management Class + *

Handles Group Chat Operations

+ * + * @author Oliver Martin (Revilo410) + */ +public class GroupManager { + + /** + * Creates a new informal group chat based on the specified parameters + * Also adds the creator to the group as the owner + */ + public void createGroup(String groupname, UUID owneruuid, boolean secret, String password) { + + TGroupChatInfo newgroup = new TGroupChatInfo(); + + newgroup.addMember(owneruuid); + newgroup.addViewer(owneruuid); + newgroup.addAdmin(owneruuid); + newgroup.setName(groupname.toLowerCase()); + newgroup.setChatColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("groupchat").getNode("ccdefault").getString().toCharArray()[0]); + newgroup.setNameColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("groupchat").getNode("ncdefault").getString().toCharArray()[0]); + newgroup.setSecret(secret); + newgroup.setPassword(password); + newgroup.setFormal(false); + + MultiChat.groupchats.put(groupname.toLowerCase(), newgroup); + + } + + /** + * Adds a player to a group chat while removing them from the spy list if they were spying on it before + * This will also check if they are banned and stop them being added + * It will also check if they are already a member + * Passwords for the group are also checked + */ + public boolean joinGroup(String groupname, Player player, String password) { + + boolean success = false; + + TGroupChatInfo groupchat = MultiChat.groupchats.get(groupname.toLowerCase()); + + if (!groupchat.existsBanned(player.getUniqueId())) { + + if (!groupchat.existsMember(player.getUniqueId())) { + + if (!groupchat.getSecret()) { + + if (groupchat.existsViewer(player.getUniqueId())) { + + if (player.hasPermission("multichat.staff.spy")) { + + MessageManager.sendSpecialMessage(player, "command_group_spy_off", groupname.toUpperCase()); + groupchat.delViewer(player.getUniqueId()); + + } else { + + groupchat.delViewer(player.getUniqueId()); + + } + + } + + groupchat.addMember(player.getUniqueId()); + groupchat.addViewer(player.getUniqueId()); + + MultiChat.groupchats.remove(groupname.toLowerCase()); + MultiChat.groupchats.put(groupname.toLowerCase(), groupchat); + + success = true; + + } else { + + if (password.equals("")) { + + MessageManager.sendSpecialMessage(player, "groups_password_protected", groupname.toUpperCase()); + + } else { + + if (password.equals(groupchat.getPassword())) { + + if (groupchat.existsViewer(player.getUniqueId())) { + + if (player.hasPermission("multichat.staff.spy")) { + + MessageManager.sendSpecialMessage(player, "command_group_spy_off", groupname.toUpperCase()); + groupchat.delViewer(player.getUniqueId()); + + } else { + groupchat.delViewer(player.getUniqueId()); + } + + } + + groupchat.addMember(player.getUniqueId()); + groupchat.addViewer(player.getUniqueId()); + + MultiChat.groupchats.remove(groupname.toLowerCase()); + MultiChat.groupchats.put(groupname.toLowerCase(), groupchat); + + success = true; + + } else { + + MessageManager.sendSpecialMessage(player, "groups_password_incorrect", groupname.toUpperCase()); + + } + + } + } + + } else { + MessageManager.sendSpecialMessage(player, "groups_already_joined", groupname.toUpperCase()); + } + + } else { + MessageManager.sendSpecialMessage(player, "groups_banned", groupname.toUpperCase()); + } + return success; + } + + /** + * Sets the selected group of a player to the specified group + */ + public void setViewedChat(UUID playeruuid, String groupname) { + + String viewedchat = groupname.toLowerCase(); + MultiChat.viewedchats.remove(playeruuid); + MultiChat.viewedchats.put(playeruuid, viewedchat); + + } + + /** + * The INFO announce in a group that a player has joined + */ + public void announceJoinGroup(String playername, String groupname) { + + GCCommand.sendMessage(playername + MessageManager.getMessage("groups_info_joined"), "&lINFO", MultiChat.groupchats.get(groupname.toLowerCase())); + + } + + /** + * The INFO announce in a group that a player has left + */ + public void announceQuitGroup(String playername, String groupname) { + + GCCommand.sendMessage(playername + MessageManager.getMessage("groups_info_quit"), "&lINFO", MultiChat.groupchats.get(groupname.toLowerCase())); + + } + + /** + * Quits a group, announces in the group chat and notifies the player quitting + */ + public void quitGroup(String groupname, UUID player, Player pinstance) { + + TGroupChatInfo groupchatinfo = MultiChat.groupchats.get(groupname.toLowerCase()); + + if (groupchatinfo.existsMember(player)) { + + if ((!groupchatinfo.existsAdmin(player)) || (groupchatinfo.getAdmins().size() > 1)) { + + groupchatinfo.delMember(player); + groupchatinfo.delViewer(player); + + if (groupchatinfo.existsAdmin(player)) { + groupchatinfo.delAdmin(player); + } + + MultiChat.viewedchats.remove(player); + MultiChat.viewedchats.put(player, null); + MultiChat.groupchats.remove(groupname.toLowerCase()); + MultiChat.groupchats.put(groupname.toLowerCase(), groupchatinfo); + + MessageManager.sendSpecialMessage(pinstance, "groups_quit", groupname.toUpperCase()); + announceQuitGroup(pinstance.getUsername(), groupname); + + } else if (!groupchatinfo.getFormal()) { + + MessageManager.sendSpecialMessage(pinstance, "groups_cannot_quit_owner_1", groupname.toUpperCase()); + MessageManager.sendSpecialMessage(pinstance, "groups_cannot_quit_owner_2", groupname.toUpperCase()); + + } else { + + MessageManager.sendSpecialMessage(pinstance, "groups_cannot_quit_admin_1", groupname.toUpperCase()); + MessageManager.sendSpecialMessage(pinstance, "groups_cannot_quit_admin_2", groupname.toUpperCase()); + } + + } else { + + MessageManager.sendSpecialMessage(pinstance, "command_group_not_a_member", groupname.toUpperCase()); + + } + } + + public void displayHelp(int page, CommandSource sender) { + + if (page == 1) { + + MessageManager.sendMessage(sender, "groups_help_1"); + + } else { + + MessageManager.sendMessage(sender, "groups_help_2"); + + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/LocalChannel.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/LocalChannel.java new file mode 100644 index 00000000..07115f69 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/LocalChannel.java @@ -0,0 +1,32 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; + +public class LocalChannel extends Channel { + + public LocalChannel() { + super("local", "", false, false); + } + + /** + * This has no purpose as local chat for players is handled by the local servers + */ + @Override + public void sendMessage(Player sender, String message, String format) { + /* EMPTY */ + } + + @Override + public void sendMessage(String message, CommandSource sender) { + + DebugManager.log("LocalChannel wants to send a cast message!"); + + // Use this to relay CASTS to local chat! + if (sender instanceof Player) { + BungeeComm.sendChatMessage(message, ((Player) sender).getCurrentServer().get().getServerInfo()); + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MessageManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MessageManager.java new file mode 100644 index 00000000..fc3fe787 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MessageManager.java @@ -0,0 +1,455 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.command.CommandSource; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import ninja.leaping.configurate.ConfigurationNode; +import com.velocitypowered.api.proxy.Player; + +import java.util.HashMap; +import java.util.Map; + +/** + * Message Manager + *

Used to display all plugin messages to players

+ * + * @author Oliver Martin (Revilo410) + */ +public class MessageManager { + + private static final Map defaultMessages; + + private static String prefix; + + static { + + defaultMessages = new HashMap<>(); + + // *** CONSOLE LOGS *** // + + defaultMessages.put("console_main_prefix", "&8[&2M&aC&8]&f "); + defaultMessages.put("console_chat_prefix", "&fCHAT &f> "); + defaultMessages.put("console_modchat_prefix", "&3STAFFCHAT &f> &3"); + defaultMessages.put("console_adminchat_prefix", "&5STAFFCHAT &f> &5"); + defaultMessages.put("console_groupchat_prefix", "&2GROUPCHAT &f> &2"); + defaultMessages.put("console_display_prefix", "&fDISPLAY &f> "); + defaultMessages.put("console_socialspy_prefix", "&cSOCIALSPY &f> &c"); + defaultMessages.put("console_helpme_prefix", "&4HELPME &f> &4"); + + + // *** PREFIX *** // + + defaultMessages.put("prefix", "&8&l[&2&lM&a&lC&8&l]&f "); + + // *** COMMANDS *** // + + defaultMessages.put("command_acc_usage", "&aUsage: /acc "); + defaultMessages.put("command_acc_only_players", "&cOnly players can change chat colours!"); + defaultMessages.put("command_acc_updated", "&aAdmin-Chat colours updated!"); + defaultMessages.put("command_acc_invalid", "&cInvalid color codes specified: Must be letters a-f or numbers 0-9"); + defaultMessages.put("command_acc_invalid_usage", "&cUsage: /acc "); + + defaultMessages.put("command_ac_toggle_on", "&dAdmin chat toggled on!"); + defaultMessages.put("command_ac_toggle_off", "&cAdmin chat toggled off!"); + defaultMessages.put("command_ac_only_players", "&cOnly players can toggle the chat!"); + + defaultMessages.put("command_announcement_list", "&aList of avaliable announcements:"); + defaultMessages.put("command_announcement_list_item", "&b -> %SPECIAL%"); + defaultMessages.put("command_announcement_does_not_exist", "&cSorry, no such announcement found: %SPECIAL%"); + defaultMessages.put("command_announcement_removed", "&aRemoved announcement: %SPECIAL%"); + defaultMessages.put("command_announcement_stopped", "&aStopped announcement: %SPECIAL%"); + defaultMessages.put("command_announcement_stopped_error", "&cSorry, unable to stop announcement: %SPECIAL%"); + defaultMessages.put("command_announcement_started", "&aStarted announcement: %SPECIAL%"); + defaultMessages.put("command_announcement_started_error", "&cSorry, unable to start announcement: %SPECIAL%"); + defaultMessages.put("command_announcement_added", "&aAdded announcement: %SPECIAL%"); + defaultMessages.put("command_announcement_added_error", "&cSorry, announcement already exists: %SPECIAL%"); + defaultMessages.put("command_announcement_usage", "&aUsage:"); + + defaultMessages.put("command_bulletin_stopped", "&bBulletins stopped"); + defaultMessages.put("command_bulletin_list", "&aList of bulletin messages with index:"); + defaultMessages.put("command_bulletin_list_item", "&b -> %SPECIAL%"); + defaultMessages.put("command_bulletin_removed", "&bRemoved bulletin"); + defaultMessages.put("command_bulletin_started", "&bStarted bulletin"); + defaultMessages.put("command_bulletin_added", "&bAdded to bulletin"); + defaultMessages.put("command_bulletin_invalid_usage", "&cInvalid command usage!"); + defaultMessages.put("command_bulletin_usage", "&aUsage:"); + + defaultMessages.put("command_cast_usage", "&aUsage:"); + defaultMessages.put("command_cast_list", "&aList of avaliable casts:"); + defaultMessages.put("command_cast_list_item", "&b -> %SPECIAL%"); + defaultMessages.put("command_cast_removed", "&aRemoved cast: %SPECIAL%"); + defaultMessages.put("command_cast_does_not_exist", "&cSorry, no such cast found: %SPECIAL%"); + defaultMessages.put("command_cast_added", "&aAdded cast: %SPECIAL%"); + defaultMessages.put("command_cast_added_error", "&cSorry, cast already exists: %SPECIAL%"); + + defaultMessages.put("command_channel_help", + "&3&lChannel Command Help\n" + + "&bSwitch channel\n" + + "&f&o/channel switch \n" + + "&bShow/Hide channel\n" + + "&f&o/channel show/hide "); + defaultMessages.put("command_channel_switch", "&bSwitched to channel: &f&o%SPECIAL%"); + defaultMessages.put("command_channel_hide", "&bYou have hidden channel: &f&o%SPECIAL%"); + defaultMessages.put("command_channel_show", "&bYou have un-hidden channel: &f&o%SPECIAL%"); + defaultMessages.put("command_channel_already_hide", "&bYou have already hidden channel: &f&o%SPECIAL%"); + defaultMessages.put("command_channel_already_show", "&bYou have already un-hidden channel: &f&o%SPECIAL%"); + defaultMessages.put("command_channel_does_not_exist", "&cSorry, that channel does not exist"); + defaultMessages.put("command_channel_only_players", "&cSorry, only players can use chat channel commands"); + defaultMessages.put("command_channel_switch_no_permission", "&cYou are unable to switch channels"); + defaultMessages.put("command_channel_hide_no_permission", "&cYou are unable to hide channels"); + defaultMessages.put("command_channel_show_no_permission", "&cYou are unable to show channels"); + defaultMessages.put("command_channel_cannot_hide", "&cYou cannot hide your currently selected channel"); + + defaultMessages.put("command_clearchat_self", "&bYour chat has been cleared"); + defaultMessages.put("command_clearchat_server", "&bServer chat has been cleared"); + defaultMessages.put("command_clearchat_global", "&bGlobal chat has been cleared"); + defaultMessages.put("command_clearchat_all", "&bAll chat has been cleared"); + defaultMessages.put("command_clearchat_no_permission", "&cYou do not have permission to clear %SPECIAL% chat"); + defaultMessages.put("command_clearchat_usage", "&cUsage: /clearchat [self/server/global/all]"); + + defaultMessages.put("command_display_desc", "&3Display a message to the entire network"); + defaultMessages.put("command_display_usage", "&bUsage /display "); + + defaultMessages.put("command_freezechat_thawed", "&b&lChat was &3&lTHAWED &b&lby &a&l%SPECIAL%"); + defaultMessages.put("command_freezechat_frozen", "&b&lChat was &3&lFROZEN &b&lby &a&l%SPECIAL%"); + + defaultMessages.put("command_gc_toggle_on", "&aGroup chat toggled on!"); + defaultMessages.put("command_gc_toggle_off", "&cGroup chat toggled off!"); + defaultMessages.put("command_gc_only_players_toggle", "&cOnly players can toggle the chat!"); + defaultMessages.put("command_gc_no_longer_exists", "&cSorry your selected chat no longer exists, please select a chat with /group "); + defaultMessages.put("command_gc_no_chat_selected", "&cPlease select the chat you wish to message using /group "); + defaultMessages.put("command_gc_only_players_speak", "&cOnly players can speak in group chats"); + + defaultMessages.put("command_global_enabled_1", "&3GLOBAL CHAT ENABLED"); + defaultMessages.put("command_global_enabled_2", "&bYour messages will go to all servers!"); + defaultMessages.put("command_global_only_players", "&cOnly players can change their chat state"); + + defaultMessages.put("command_group_selected", "&aYour /gc messages will now go to group: %SPECIAL%"); + defaultMessages.put("command_group_not_a_member", "&cSorry you aren't a member of group: %SPECIAL%"); + defaultMessages.put("command_group_does_not_exist", "&cSorry the following group chat does not exist: %SPECIAL%"); + defaultMessages.put("command_group_only_players_select", "&cOnly players can select a group chat"); + defaultMessages.put("command_group_incorrect_usage", "&cIncorrect command usage, use /group to see a list of commands!"); + defaultMessages.put("command_group_member_list", "&a&lShowing members of group: %SPECIAL%"); + defaultMessages.put("command_group_member_list_item", "&b- %SPECIAL%"); + defaultMessages.put("command_group_member_list_item_admin", "&b- &b&o%SPECIAL%"); + defaultMessages.put("command_group_spy_all_disabled_1", "&cGlobal group spy disabled"); + defaultMessages.put("command_group_spy_all_disabled_2", "&cAny groups you previously activated spy for will still be spied on!"); + defaultMessages.put("command_group_spy_all_disabled_3", "&cDisable spy for individual groups with /group spy "); + defaultMessages.put("command_group_spy_all_enabled", "&aGlobal group spy enabled for all group chats!"); + defaultMessages.put("command_group_spy_no_permission", "&cSorry this command does not exist, use /group"); + defaultMessages.put("command_group_spy_off", "&cYou are no longer spying on: %SPECIAL%"); + defaultMessages.put("command_group_spy_on", "&aYou are now spying on: %SPECIAL%"); + defaultMessages.put("command_group_spy_already_a_member", "&cYou are already a member of this chat so can't spy on it!"); + defaultMessages.put("command_group_spy_does_not_exist", "&cSorry this group chat does not exist!"); + defaultMessages.put("command_group_created", "&aYou successfully created, joined, and selected the group: %SPECIAL%"); + defaultMessages.put("command_group_already_exists", "&cSorry the following group chat already exists: %SPECIAL%"); + defaultMessages.put("command_group_max_length", "&cSorry group name cannot exceed 20 characters!"); + defaultMessages.put("command_group_create_no_permission", "&cSorry you do not have permission to create new group chats"); + defaultMessages.put("command_group_joined", "&aYou successfully joined and selected the group: %SPECIAL%"); + defaultMessages.put("command_group_formal_not_owner", "&cSorry this command can only be used by the group chat owner"); + defaultMessages.put("command_group_formal_already_formal", "&cSorry this chat is already a formal group chat: %SPECIAL%"); + defaultMessages.put("command_group_formal_not_admin", "&cSorry this command can only be used by group admins/owners"); + defaultMessages.put("command_group_max_length_password", "&cSorry neither group name or password must exceed 20 characters"); + defaultMessages.put("command_group_transfer_not_member", "&cThis player is not already a member of the group!"); + defaultMessages.put("command_group_transfer_not_owner", "&cSorry you are not the owner of this chat!"); + defaultMessages.put("command_group_transfer_not_informal", "&cThis command can only be used on informal chats!"); + defaultMessages.put("command_group_player_not_online", "&cThis player is not online!"); + defaultMessages.put("command_group_formal_only_admin", "&cYou can't step down as a group admin because you are the only one!"); + defaultMessages.put("command_group_formal_cannot_demote", "&cYou can't demote another group admin!"); + defaultMessages.put("command_group_not_formal", "&cThis command can only be used on formal chats!"); + defaultMessages.put("command_group_banned", "&cYou were banned from group: %SPECIAL%"); + defaultMessages.put("command_group_unbanned", "&aYou were unbanned from group: %SPECIAL%"); + defaultMessages.put("command_group_cannot_ban_admin", "&cYou can't ban a group admin!"); + defaultMessages.put("command_group_color_invalid", "&cInvalid color codes specified: Must be letters a-f or numbers 0-9"); + defaultMessages.put("command_group_color_usage", "&cUsage: /group color/colour "); + defaultMessages.put("command_group_only_players", "&cOnly players can use group chats"); + + defaultMessages.put("command_grouplist_list", "&a&lGroup List:"); + defaultMessages.put("command_grouplist_list_item", "&b- %SPECIAL%"); + + defaultMessages.put("command_helpme_desc", "&4Request help from a staff member!"); + defaultMessages.put("command_helpme_usage", "&cUsage: /HelpMe "); + defaultMessages.put("command_helpme_sent", "&cYour request for help has been sent to all online staff :)"); + defaultMessages.put("command_helpme_only_players", "&4Only players can request help!"); + defaultMessages.put("command_helpme_format", "&c&l<< &4HELPME &c&l>> &f&o%SPECIAL%"); + + defaultMessages.put("command_local_enabled_1", "&3LOCAL CHAT ENABLED"); + defaultMessages.put("command_local_enabled_2", "&bYour messages will only go to this server!"); + defaultMessages.put("command_local_only_players", "&cOnly players can change their chat state"); + + defaultMessages.put("command_mcc_usage", "&aUsage: /mcc "); + defaultMessages.put("command_mcc_only_players", "&cOnly players can change chat colours!"); + defaultMessages.put("command_mcc_updated", "&aMod-Chat colours updated!"); + defaultMessages.put("command_mcc_invalid", "&cInvalid color codes specified: Must be letters a-f or numbers 0-9"); + defaultMessages.put("command_mcc_invalid_usage", "&cUsage: /mcc "); + + defaultMessages.put("command_mc_toggle_on", "&bMod chat toggled on!"); + defaultMessages.put("command_mc_toggle_off", "&cMod chat toggled off!"); + defaultMessages.put("command_mc_only_players", "&cOnly players can toggle the chat!"); + + defaultMessages.put("command_msg_usage", "&bUsage: /msg [message]"); + defaultMessages.put("command_msg_usage_toggle", "&bUsing /msg with no message will toggle chat to go to that player"); + defaultMessages.put("command_msg_toggle_on", "&ePrivate chat toggled on! [You -> %SPECIAL%] (Type the same command to disable the toggle)"); + defaultMessages.put("command_msg_toggle_off", "&cPrivate chat toggled off!"); + defaultMessages.put("command_msg_only_players", "&cOnly players can toggle the chat!"); + defaultMessages.put("command_msg_not_online", "&cSorry this person is not online!"); + defaultMessages.put("command_msg_disabled_target", "&cSorry private messages are disabled on the target player's server!"); + defaultMessages.put("command_msg_disabled_sender", "&cSorry private messages are disabled on this server!"); + defaultMessages.put("command_msg_no_toggle", "&cSorry, message toggles are not allowed on this server!"); + + // TODO Somehow combine all these into one message but provide a special method like "displayMessagePage()" in this + // message manager which automatically decides how many lines to show for the page specified to the message manager. + defaultMessages.put("command_multichat_help_1", + "&2&lMulti&a&lChat &b&lHelp\n" + + "&3Display plugin version info\n" + + "&b/multichat\n" + + "&3Reload the plugin config\n" + + "&b/multichat reload\n" + + "&3Save ALL plugin data\n" + + "&b/multichat save\n" + + "&3Display a message to all players\n" + + "&b/display \n" + + "&3View group chat help\n" + + "&b/group\n" + + "&3Send mod chat message &o(Send admin chat message)\n" + + "&b/mc &o(/ac )\n" + + "&3Change mod/&oadmin &3chat colours\n" + + "&b/mcc \n" + + "&b&o/acc \n" + + "&3Toggle mod chat &o(Toggle admin chat)\n" + + "&b/mc &o(/ac)\n" + + "&3&lType &b&l/multichat help &3<o view more commands"); + + defaultMessages.put("command_multichat_help_2", + "&2&lMulti&a&lChat &b&lHelp [Page 2]\n" + + "&3View all global chat (Enabled by default)\n" + + "&b/global\n" + + "&3Only view chat from your current server\n" + + "&b/local\n" + + "&3See a list of online staff members\n" + + "&b/staff\n" + + "&3See a list of all group chats\n" + + "&b/groups\n" + + "&3Send a player a private message\n" + + "&b/msg [message]\n" + + "&3Reply to your last message\n" + + "&b/r \n" + + "&3Toggle socialspy to view private messages\n" + + "&b/socialspy\n" + + "&3Freeze the chat to stop messages being sent\n" + + "&b/freezechat\n" + + "&3Clear the chat stream for yourself or a group of people\n" + + "&b/clearchat [self,server,global,all]"); + + defaultMessages.put("command_multichat_help_3", + "&2&lMulti&a&lChat &b&lHelp [Page 3]\n" + + "&3View announcement commands\n" + + "&b/announcement\n" + + "&3View bulletin commands\n" + + "&b/bulletin\n" + + "&3View cast commands\n" + + "&b/cast\n" + + "&3Use a specified cast from the console\n" + + "&b/usecast \n" + + "&3Alert staff members of a problem\n" + + "&b/helpme \n" + + "&3Nickname a player (Only works if MultiChat installed on Spigot / Sponge)\n" + + "&b/nick [player] \n" + + "&3Get players real name from their nickname (Only works on Spigot)\n" + + "&b/realname \n" + + "&3Mute players to prevent them sending messages\n" + + "&b/mute \n" + + "&3Ignore players to stop seeing their messages\n" + + "&b/ignore "); + + defaultMessages.put("command_multichat_save_prepare", "&3Preparing to save multichat files!"); + defaultMessages.put("command_multichat_save_completed", "&bSave completed!"); + defaultMessages.put("command_multichat_reload_prepare", "&3Preparing to reload multichat files!"); + defaultMessages.put("command_multichat_reload_completed", "&bReload completed!"); + + defaultMessages.put("command_multichatbypass_usage", "&4Usage: /mcb\n" + + "&c&oThis command causes your chat messages to bypass MultiChat and be handled directly by spigot."); + defaultMessages.put("command_multichatbypass_enabled", "&aMultiChat BYPASS Enabled"); + defaultMessages.put("command_multichatbypass_disabled", "&bMultiChat BYPASS Disabled"); + + defaultMessages.put("command_execute_usage", "&2Usage: /mce [-s ] [-p ] \n" + + "&a&oThis command allows you to execute a command over all your spigot servers (&lwhich have at least 1 player online!&a&o)\n" + + "By default the command will be executed by console, you can instead make players execute the command using the -p flag\n" + + "By default the command will be executed on all servers, you can limit which servers using the -s flag."); + defaultMessages.put("command_execute_sent", "&2The command has been sent"); + defaultMessages.put("command_execute_regex", "&cThe regex specified was invalid"); + + defaultMessages.put("command_reply_usage", "&bUsage: /r "); + defaultMessages.put("command_reply_desc", "&bReply to the person who you private messaged most recently"); + defaultMessages.put("command_reply_no_one_to_reply_to", "&cYou have no one to reply to!"); + defaultMessages.put("command_reply_only_players", "&cOnly players can reply to private messages"); + + defaultMessages.put("command_socialspy_disabled", "&cSocial Spy Disabled"); + defaultMessages.put("command_socialspy_enabled", "&bSocial Spy Enabled"); + defaultMessages.put("command_socialspy_usage", "&bUsage: /socialspy"); + defaultMessages.put("command_socialspy_desc", "&bToggles if the user has social spy enabled or disabled"); + defaultMessages.put("command_socialspy_only_players", "&cOnly players can toggle socialspy"); + + defaultMessages.put("command_stafflist_list", "&a&lOnline Staff"); + defaultMessages.put("command_stafflist_list_item", "&b- %SPECIAL%"); + defaultMessages.put("command_stafflist_list_server", "&a%SPECIAL%"); + defaultMessages.put("command_stafflist_no_staff", "&b&oThere are currently no staff online"); + + defaultMessages.put("command_usecast_usage", "&aUsage:"); + defaultMessages.put("command_usecast_does_not_exist", "&cSorry, no such cast found: %SPECIAL%"); + + // *** GROUPS *** // + + defaultMessages.put("groups_toggled_but_no_longer_exists_1", "&cYou have toggled group chat but selected group doesn't exist!"); + defaultMessages.put("groups_toggled_but_no_longer_exists_2", "&cPlease select the chat you wish to message using /group or disable the toggle with /gc"); + defaultMessages.put("groups_password_protected", "&cSorry this group chat is password protected: %SPECIAL%"); + defaultMessages.put("groups_password_incorrect", "&cSorry incorrect password for: %SPECIAL%"); + defaultMessages.put("groups_already_joined", "&cSorry you are already a member of the group: %SPECIAL%"); + defaultMessages.put("groups_banned", "&cSorry you are banned from the group: %SPECIAL%"); + defaultMessages.put("groups_quit", "&aYou successfully left the group: %SPECIAL%"); + defaultMessages.put("groups_cannot_quit_owner_1", "&cSorry you cannot leave as you created the group!: %SPECIAL%"); + defaultMessages.put("groups_cannot_quit_owner_2", "&cPlease transfer group ownership first! Use /group transfer %SPECIAL% "); + defaultMessages.put("groups_cannot_quit_admin_1", "&cSorry you cannot leave as you are the only group admin!: %SPECIAL%"); + defaultMessages.put("groups_cannot_quit_admin_2", "&cPlease appoint a new admin using /group admin %SPECIAL% "); + + defaultMessages.put("groups_info_joined", " has joined the group chat!"); + defaultMessages.put("groups_info_quit", " has left the group chat!"); + defaultMessages.put("groups_info_formal", " has converted this group to a FORMAL group chat!"); + defaultMessages.put("groups_info_deleted", " has deleted this group chat!"); + defaultMessages.put("groups_info_goodbye", "Goodbye! If you want to see group chat commands do /group"); + defaultMessages.put("groups_info_transfer", " has transferred ownership to "); + defaultMessages.put("groups_info_promoted", " has promoted the following member to group admin: "); + defaultMessages.put("groups_info_step_down", " has stepped down as a group admin"); + defaultMessages.put("groups_info_kick", " kicked the following player from the group chat: "); + defaultMessages.put("groups_info_ban", " has banned the following player from the group chat: "); + defaultMessages.put("groups_info_unban", " has unbanned the following player from the group chat: "); + defaultMessages.put("groups_info_colors", "Group chat colours changed by "); + + defaultMessages.put("groups_help_1", + "&cGroup Chat Command Usage [Page 1] - INFORMAL GROUPS\n" + + "&2MAKE A NEW GROUP CHAT\n" + + "&a/group create/make [password]\n" + + "&2JOIN AN EXISTING GROUP CHAT\n" + + "&a/group join [password]\n" + + "&2LEAVE A GROUP CHAT\n" + + "&a/group leave/quit \n" + + "&2SELECT THE GROUP CHAT YOU WISH FOR YOUR MESSAGES TO GO TO\n" + + "&a/group \n" + + "&2SET THE COLOURS OF YOUR GROUP CHAT\n" + + "&a/group color/colour \n" + + "&2TRANSFER OWNERSHIP OF YOUR INFORMAL GROUP CHAT\n" + + "&a/group transfer \n" + + "&2DELETE A GROUP CHAT\n" + + "&a/group delete \n" + + "&2LIST GROUP CHAT MEMBERS\n" + + "&a/group list/members \n" + + "&2SEND A MESSAGE TO THE SELECTED GROUP CHAT\n" + + "&a/gc \n" + + "&cTo see FORMAL group chat commands do /group help 2"); + + defaultMessages.put("groups_help_2", + "&cGroup Chat Command Usage [Page 2] - FORMAL GROUPS\n" + + "&3All group chats default to informal group chats\n" + + "&3If you are a group owner you can convert your group to a formal group chat\n" + + "&3Formal group chats restrict changing colours to appointed group admins only\n" + + "&3Appointed group admins will also be able to ban people from the chat\n" + + "&3CONVERSION TO A FORMAL GROUP CHAT IS IRREVERSIBLE\n" + + "&2CONVERT YOUR GROUP CHAT TO A FORMAL GROUP CHAT (IRREVERSIBLE)\n" + + "&a/group formal \n" + + "&2ADD OR REMOVE AN ADMIN FROM A FORMAL GROUP CHAT\n" + + "&a/group admin \n" + + "&2BAN/UNBAN A PLAYER FROM YOUR FORMAL GROUP CHAT\n" + + "&a/group ban \n" + + "&cTo see INFORMAL group chat commands do /group help 1"); + + // *** FREEZECHAT *** // + + defaultMessages.put("freezechat_frozen", "&bSorry chat has been &3&lFROZEN"); + + // *** MUTE ***// + + defaultMessages.put("mute_muted", "&cYou have been muted by staff! You can no longer send chat messages."); + defaultMessages.put("mute_unmuted", "&aYou have been unmuted by staff, you can now send messages."); + defaultMessages.put("mute_muted_staff", "&cPlayer has been muted!"); + defaultMessages.put("mute_unmuted_staff", "&aPlayer has been unmuted!"); + defaultMessages.put("mute_cannot_send_message", "&cYou are currently muted so cannot send messages!"); + defaultMessages.put("mute_usage", "&cUsage: /mute (Also used to unmute players)"); + defaultMessages.put("mute_player_not_found", "&cPlayer cannot be muted as they are not online"); + defaultMessages.put("mute_bypass", "&cYou cannot mute this player"); + + // *** IGNORE *** // + + defaultMessages.put("ignore_sender", "&cYou cannot message this person"); + defaultMessages.put("ignore_target", "&c[%SPECIAL% sent a message, but you ignore them]"); + defaultMessages.put("ignore_ignored", "&bYou will no longer see chat messages from %SPECIAL%"); + defaultMessages.put("ignore_unignored", "&bYou have un-ignored %SPECIAL%"); + defaultMessages.put("ignore_player_not_found", "&cPlayer cannot be ignored as they are not online"); + defaultMessages.put("ignore_usage", "&cUsage: /ignore (Also used to un-ignore players)"); + defaultMessages.put("ignore_bypass", "&cYou cannot ignore this player"); + defaultMessages.put("ignore_only_players", "&cOnly players can use this command"); + defaultMessages.put("ignore_cannot_ignore_yourself", "&cYou cannot ignore yourself!"); + + // *** ANTI-SPAM *** // + + defaultMessages.put("anti_spam_cooldown", "&cANTI-SPAM: Your messages have been blocked. You cannot chat for another %SPECIAL% seconds."); + + } + + public static String getPrefix() { + return prefix; + } + + public static String getMessage(String id) { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("messages.yml").getConfig(); + + if (config.getChildrenMap().containsKey(id)) return config.getNode(id).getString(); + if (!defaultMessages.containsKey(id)) + return "&cERROR - Please report to plugin developer - No message defined for: " + id; + return defaultMessages.get(id.toLowerCase()); + + } + + public static void sendMessage(CommandSource sender, String id) { + updatePrefix(); + + Player player; + String server = ""; + if (sender instanceof Player) { + player = (Player) sender; + server = player.getCurrentServer().get().getServer().getServerInfo().getName(); + } + + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(prefix + MultiChatUtil.reformatRGB(getMessage(id).replaceAll("%SERVER%", server)))); + } + + public static void sendSpecialMessage(CommandSource sender, String id, String special) { + updatePrefix(); + + Player player; + String server = ""; + if (sender instanceof Player) { + player = (Player) sender; + server = player.getCurrentServer().get().getServer().getServerInfo().getName(); + } + + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(prefix + MultiChatUtil.reformatRGB(getMessage(id)).replaceAll("%SPECIAL%", special).replaceAll("%SERVER%", server))); + } + + public static void sendSpecialMessageWithoutPrefix(CommandSource sender, String id, String special) { + updatePrefix(); + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.reformatRGB(getMessage(id)).replaceAll("%SPECIAL%", special))); + } + + private static void updatePrefix() { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("messages.yml").getConfig(); + + if (config.getChildrenMap().containsKey("prefix")) { + prefix = config.getNode("prefix").getString(); + } else { + prefix = defaultMessages.get("prefix"); + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MultiChat.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MultiChat.java new file mode 100644 index 00000000..7eae8e87 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MultiChat.java @@ -0,0 +1,1074 @@ +package xyz.olivermartin.multichat.velocity; + +import com.google.inject.Inject; +import com.olivermartin410.plugins.TChatInfo; +import com.olivermartin410.plugins.TGroupChatInfo; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PostLoginEvent; +import com.velocitypowered.api.event.player.ServerPreConnectEvent; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import lombok.Getter; +import ninja.leaping.configurate.ConfigurationNode; +import org.slf4j.Logger; +import xyz.olivermartin.multichat.proxy.common.ServerGroups; +import xyz.olivermartin.multichat.velocity.commands.Command; + +import java.io.*; +import java.nio.file.Path; +import java.util.*; +import java.util.concurrent.TimeUnit; + + +/** + * The MAIN MultiChat Class + *

This class is the main plugin. All plugin enable and disable control happens here.

+ * + * @author Oliver Martin (Revilo410) + */ +@Plugin(id = "multichat", name = "MultiChat", version = "1.9.9", authors = {"Revilo410", "Haha007", "Gadse", "Seraek"}) +public class MultiChat { + + public static final String LATEST_VERSION = "1.9.9"; + + public static final String[] ALLOWED_VERSIONS = new String[]{ + LATEST_VERSION, + "1.9.8", + "1.9.7", + "1.9.6", + "1.9.5", + "1.9.4", + "1.9.3", + "1.9.2", + "1.9.1", + "1.9", + "1.8.2", + "1.8.1", + "1.8", + "1.7.5", + "1.7.4", + "1.7.3", + "1.7.2", + "1.7.1", + "1.7", + "1.6.2", + "1.6.1", + "1.6", + "1.5.2", + "1.5.1", + "1.5", + "1.4.2", + "1.4.1", + "1.4", + "1.3.4", + "1.3.3", + "1.3.2", + "1.3.1", + "1.3" + + }; + + public static Map modchatpreferences = new HashMap<>(); + public static Map adminchatpreferences = new HashMap<>(); + public static Map groupchats = new HashMap<>(); + + public static Map viewedchats = new HashMap<>(); + public static Map lastmsg = new HashMap<>(); + public static List allspy = new ArrayList<>(); + public static List socialspy = new ArrayList<>(); + + public static File configDir; + public static String configversion; + + public static boolean frozen; + + public static String defaultChannel = ""; + public static boolean forceChannelOnJoin = false; + + public static boolean logPMs = true; + public static boolean logStaffChat = true; + public static boolean logGroupChat = true; + + private static MultiChat instance; + + public static List legacyServers = new ArrayList<>(); + + private static ServerGroups serverGroups; + private static Boolean serverGroupsEnabled = false; + private static HashMap> serverGroupsMap = new HashMap<>(); + + @Getter + private final Logger logger; + @Getter + private final ProxyServer server; + private final Path dataFolderPath; + + public static MultiChat getInstance() { + return instance; + } + + @Inject + public MultiChat(ProxyServer server, Logger logger, @DataDirectory Path dataFolderPath) { + this.logger = logger; + this.server = server; + this.dataFolderPath = dataFolderPath; + } + + @Subscribe + void onProxyInit(ProxyInitializeEvent event) { + onEnable(); + } + + @Subscribe + void onProxyDisable(ProxyShutdownEvent event) { + onDisable(); + } + + public void backup() { + getServer().getScheduler().buildTask(this, () -> { + getLogger().info("Commencing backup!"); + + saveChatInfo(); + saveGroupChatInfo(); + saveGroupSpyInfo(); + saveGlobalChatInfo(); + saveSocialSpyInfo(); + saveAnnouncements(); + saveBulletins(); + saveCasts(); + saveMute(); + saveIgnore(); + UUIDNameManager.saveUUIDS(); + + getLogger().info("Backup complete. Any errors reported above."); + }).delay(1, TimeUnit.MINUTES).repeat(60, TimeUnit.MINUTES).schedule(); + } + + public void fetchDisplayNames() { + getServer().getScheduler().buildTask(this, () -> { + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + for (Player player : getServer().getAllPlayers()) { + if (player.getCurrentServer().isPresent()) { + BungeeComm.sendMessage(player.getGameProfile().getName(), player.getCurrentServer().get().getServerInfo()); + } + } + } + }).delay(1, TimeUnit.MINUTES).repeat(5, TimeUnit.MINUTES).schedule(); + } + + @Subscribe + public void onLogin(PostLoginEvent event) { + fetchDisplayNameOnce(event.getPlayer().getGameProfile().getName()); + } + + @Subscribe + public void onServerSwitch(ServerPreConnectEvent event) { + fetchDisplayNameOnce(event.getPlayer().getGameProfile().getName()); + } + + public void fetchDisplayNameOnce(final String playername) { + getServer().getScheduler().buildTask(this, () -> { + try { + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + getServer().getPlayer(playername).ifPresent(player -> { + if (player.getCurrentServer().isPresent()) { + BungeeComm.sendMessage(player.getGameProfile().getName(), player.getCurrentServer().get().getServerInfo()); + } + }); + } + } catch (NullPointerException ex) { /* EMPTY */ } + }).schedule(); + + getServer().getScheduler().buildTask(this, () -> { + try { + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + getServer().getPlayer(playername).ifPresent(player -> { + if (player.getCurrentServer().isPresent()) { + BungeeComm.sendMessage(player.getGameProfile().getName(), player.getCurrentServer().get().getServerInfo()); + } + }); + } + } catch (NullPointerException ex) { /* EMPTY */ } + }).delay(1L, TimeUnit.SECONDS).schedule(); + + getServer().getScheduler().buildTask(this, () -> { + try { + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + getServer().getPlayer(playername).ifPresent(player -> { + if (player.getCurrentServer().isPresent()) { + BungeeComm.sendMessage(player.getGameProfile().getName(), player.getCurrentServer().get().getServerInfo()); + } + }); + } + } catch (NullPointerException ex) { /* EMPTY */ } + }).delay(2, TimeUnit.SECONDS).schedule(); + + getServer().getScheduler().buildTask(this, () -> { + try { + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + getServer().getPlayer(playername).ifPresent(player -> { + if (player.getCurrentServer().isPresent()) { + BungeeComm.sendMessage(player.getGameProfile().getName(), player.getCurrentServer().get().getServerInfo()); + } + }); + } + } catch (NullPointerException ex) { /* EMPTY */ } + }).delay(4L, TimeUnit.SECONDS).schedule(); + } + + public void onEnable() { + instance = this; + + configDir = getDataFolder(); + if (!getDataFolder().exists()) { + System.out.println("[MultiChat] Creating plugin directory!"); + getDataFolder().mkdirs(); + } + + String translationsDir = configDir.toString() + File.separator + "translations"; + if (!new File(translationsDir).exists()) { + System.out.println("[MultiChat] Creating translations directory!"); + new File(translationsDir).mkdirs(); + } + + ConfigManager.getInstance().registerHandler("config.yml", configDir); + ConfigManager.getInstance().registerHandler("joinmessages.yml", configDir); + ConfigManager.getInstance().registerHandler("messages.yml", configDir); + ConfigManager.getInstance().registerHandler("chatcontrol.yml", configDir); + + ConfigManager.getInstance().registerHandler("messages_fr.yml", new File(translationsDir)); + ConfigManager.getInstance().registerHandler("joinmessages_fr.yml", new File(translationsDir)); + ConfigManager.getInstance().registerHandler("config_fr.yml", new File(translationsDir)); + ConfigManager.getInstance().registerHandler("chatcontrol_fr.yml", new File(translationsDir)); + + ConfigurationNode configYML = ConfigManager.getInstance().getHandler("config.yml").getConfig(); + ConfigurationNode chatcontrolYML = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + configversion = configYML.getNode("version").getString(); + + if (Arrays.asList(ALLOWED_VERSIONS).contains(configversion)) { + + // TODO - Remove for future versions! + if (!Objects.equals(configversion, LATEST_VERSION)) { + + getLogger().info("[!!!] [WARNING] YOUR CONFIG FILES ARE NOT THE LATEST VERSION"); + getLogger().info("[!!!] [WARNING] MULTICHAT HAS INTRODUCES SEVERAL NEW FEATURES WHICH ARE NOT IN YOUR OLD FILE"); + getLogger().info("[!!!] [WARNING] THE PLUGIN SHOULD WORK WITH THE OLDER FILE, BUT IS NOT SUPPORTED!"); + getLogger().info("[!!!] [WARNING] PLEASE BACKUP YOUR OLD CONFIG FILES AND DELETE THEM FROM THE MULTICHAT FOLDER SO NEW ONES CAN BE GENERATED!"); + getLogger().info("[!!!] [WARNING] THANK YOU"); + + } + + // Register listeners + getServer().getEventManager().register(this, new Events()); + + // Register communication channels and appropriate listeners + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:comm")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:prefix")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:suffix")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:dn")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:nick")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:world")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:act")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:pact")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:chat")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:ch")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:ignore")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:pxe")); + getServer().getChannelRegistrar().register(MinecraftChannelIdentifier.from("multichat:ppxe")); + getServer().getEventManager().register(this, new BungeeComm()); + + // Register commands + registerCommands(configYML, chatcontrolYML); + + System.out.println("[MultiChat] Config Version: " + configversion); + + // Run start-up routines + Startup(); + UUIDNameManager.Startup(); + + // Set up chat control stuff + if (chatcontrolYML.getChildrenMap().containsKey("link_control")) { + ChatControl.controlLinks = chatcontrolYML.getNode("link_control").getBoolean(); + ChatControl.linkMessage = chatcontrolYML.getNode("link_removal_message").getString(); + if (chatcontrolYML.getChildrenMap().containsKey("link_regex")) { + ChatControl.linkRegex = chatcontrolYML.getNode("link_regex").getString(); + } + } + + if (configYML.getChildrenMap().containsKey("privacy_settings")) { + logPMs = configYML.getNode("privacy_settings").getNode("log_pms").getBoolean(); + logStaffChat = configYML.getNode("privacy_settings").getNode("log_staffchat").getBoolean(); + logGroupChat = configYML.getNode("privacy_settings").getNode("log_groupchat").getBoolean(); + } + + // Legacy servers for RGB approximation + if (configYML.getChildrenMap().containsKey("legacy_servers")) { + legacyServers = configYML.getNode("legacy_servers").getList(o -> (String) o); + } + + // Set default channel + defaultChannel = configYML.getNode("default_channel").getString(); + forceChannelOnJoin = configYML.getNode("force_channel_on_join").getBoolean(); + + // Set up global chat + GlobalChannel channel = Channel.getGlobalChannel(); + channel.setFormat(configYML.getNode("globalformat").getString()); + + // Add all appropriate servers to this hardcoded global chat stream + for (String server : configYML.getNode("no_global").getList(o -> (String) o)) { + channel.addServer(server); + } + + // Setup Server Groups for Global Chatting + serverGroups = new ServerGroups(); + + if (configYML.getNode("serverGroups") != null) { + serverGroupsEnabled = configYML.getNode("serverGroups").getNode("enabled").getBoolean(false); + + if (configYML.getNode("serverGroups").getNode("groups") != null && configYML.getNode("serverGroups").getNode("groups").getChildrenMap() != null) { + for (Map.Entry groupKey : configYML.getNode("serverGroups").getNode("groups").getChildrenMap().entrySet()) { + ArrayList serverGroupList = new ArrayList<>(); + + for (String server : configYML.getNode("serverGroups").getNode("groups").getNode(groupKey.getKey()).getList(o -> (String) o)) { + serverGroupList.add(server); + } + + serverGroupsMap.put(groupKey.getKey().toString(), serverGroupList); + } + } + } else { + serverGroupsEnabled = false; + } + + serverGroups.setServerGroupsEnabled(serverGroupsEnabled); + serverGroups.setServerGroups(serverGroupsMap); + + // Initiate backup routine + backup(); + + // Fetch display names of all players + fetchDisplayNames(); + } else { + getLogger().info("Config incorrect version! Please repair or delete it!"); + } + } + + private File getDataFolder() { + return dataFolderPath.toFile(); + } + + public void onDisable() { + getLogger().info("Thankyou for using MultiChat. Disabling..."); + + saveChatInfo(); + saveGroupChatInfo(); + saveGroupSpyInfo(); + saveGlobalChatInfo(); + saveSocialSpyInfo(); + saveAnnouncements(); + saveBulletins(); + saveCasts(); + saveMute(); + saveIgnore(); + UUIDNameManager.saveUUIDS(); + + } + + private void registerCommand(Command command) { + getServer().getCommandManager().register(command.getMeta(), command); + } + + public void registerCommands(ConfigurationNode configYML, ConfigurationNode chatcontrolYML) { + + // Register main commands + registerCommand(CommandManager.getAcc()); + registerCommand(CommandManager.getAc()); + registerCommand(CommandManager.getMcc()); + registerCommand(CommandManager.getMc()); + registerCommand(CommandManager.getGc()); + registerCommand(CommandManager.getGroup()); + registerCommand(CommandManager.getGrouplist()); + registerCommand(CommandManager.getMultichat()); + registerCommand(CommandManager.getMultichatBypass()); + registerCommand(CommandManager.getDisplay()); + registerCommand(CommandManager.getFreezechat()); + registerCommand(CommandManager.getHelpme()); + registerCommand(CommandManager.getClearchat()); + registerCommand(CommandManager.getAnnouncement()); + registerCommand(CommandManager.getBulletin()); + registerCommand(CommandManager.getCast()); + registerCommand(CommandManager.getUsecast()); + registerCommand(CommandManager.getIgnore()); + + // Check for Multichat Execute Command Being Enabled + // By default this is enabled + if (configYML.getNode("mcexecute_enabled").getBoolean(true)) { + registerCommand(CommandManager.getMultiChatExecute()); + } + + // Register PM commands + if (configYML.getNode("pm").getBoolean()) { + registerCommand(CommandManager.getMsg()); + registerCommand(CommandManager.getReply()); + registerCommand(CommandManager.getSocialspy()); + } + + // Register global chat commands + if (configYML.getNode("global").getBoolean()) { + registerCommand(CommandManager.getLocal()); + registerCommand(CommandManager.getGlobal()); + registerCommand(CommandManager.getChannel()); + } + + // Register staff list command /staff + if (configYML.getChildrenMap().containsKey("staff_list")) { + if (configYML.getNode("staff_list").getBoolean()) { + registerCommand(CommandManager.getStafflist()); + } + } else { + registerCommand(CommandManager.getStafflist()); + } + + // Register mute command + if (chatcontrolYML.getNode("mute").getBoolean()) { + registerCommand(CommandManager.getMute()); + } + + } + + public void unregisterCommands(ConfigurationNode configYML, ConfigurationNode chatcontrolYML) { + + // Unregister main commands + unregisterCommand(CommandManager.getAcc()); + unregisterCommand(CommandManager.getAc()); + unregisterCommand(CommandManager.getMcc()); + unregisterCommand(CommandManager.getMc()); + unregisterCommand(CommandManager.getGc()); + unregisterCommand(CommandManager.getGroup()); + unregisterCommand(CommandManager.getGrouplist()); + unregisterCommand(CommandManager.getMultichat()); + unregisterCommand(CommandManager.getMultichatBypass()); + unregisterCommand(CommandManager.getDisplay()); + unregisterCommand(CommandManager.getFreezechat()); + unregisterCommand(CommandManager.getHelpme()); + unregisterCommand(CommandManager.getClearchat()); + unregisterCommand(CommandManager.getAnnouncement()); + unregisterCommand(CommandManager.getBulletin()); + unregisterCommand(CommandManager.getCast()); + unregisterCommand(CommandManager.getUsecast()); + unregisterCommand(CommandManager.getIgnore()); + + // Check for Multichat Execute Command Being Enabled + // By default this is enabled + if (configYML.getNode("mcexecute_enabled").getBoolean(true)) { + unregisterCommand(CommandManager.getMultiChatExecute()); + } + + // Unregister PM commands + if (configYML.getNode("pm").getBoolean()) { + unregisterCommand(CommandManager.getMsg()); + unregisterCommand(CommandManager.getReply()); + unregisterCommand(CommandManager.getSocialspy()); + } + + // Unregister global chat commands + if (configYML.getNode("global").getBoolean()) { + unregisterCommand(CommandManager.getLocal()); + unregisterCommand(CommandManager.getGlobal()); + unregisterCommand(CommandManager.getChannel()); + } + + // Unregister staff list command /staff + if (configYML.getChildrenMap().containsKey("staff_list")) { + if (configYML.getNode("staff_list").getBoolean()) { + unregisterCommand(CommandManager.getStafflist()); + } + } else { + unregisterCommand(CommandManager.getStafflist()); + } + + // UnRegister mute command + if (chatcontrolYML.getNode("mute").getBoolean()) { + unregisterCommand(CommandManager.getMute()); + } + + } + + private void unregisterCommand(Command acc) { + var cm = getServer().getCommandManager(); + acc.getMeta().getAliases().forEach(cm::unregister); + } + + public static void saveAnnouncements() { + + try { + File file = new File(configDir, "Announcements.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(Announcements.getAnnouncementList()); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the announcements file!"); + e.printStackTrace(); + } + + } + + public static void saveBulletins() { + + try { + File file = new File(configDir, "Bulletins.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeBoolean(Bulletins.isEnabled()); + out.writeInt(Bulletins.getTimeBetween()); + out.writeObject(Bulletins.getArrayList()); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the bulletins file!"); + e.printStackTrace(); + } + + } + + public static void saveChatInfo() { + + try { + File file = new File(configDir, "StaffChatInfo.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(modchatpreferences); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the mod chat info file!"); + e.printStackTrace(); + } + + try { + File file = new File(configDir, "AdminChatInfo.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(adminchatpreferences); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the admin chat info file!"); + e.printStackTrace(); + } + + } + + public static void saveGroupChatInfo() { + + try { + File file = new File(configDir, "GroupChatInfo.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(groupchats); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the group chat info file!"); + e.printStackTrace(); + } + + } + + public static void saveCasts() { + + try { + File file = new File(configDir, "Casts.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(CastControl.castList); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the casts file!"); + e.printStackTrace(); + } + + } + + public static void saveGroupSpyInfo() { + + try { + File file = new File(configDir, "GroupSpyInfo.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(allspy); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the group spy info file!"); + e.printStackTrace(); + } + + } + + public static void saveSocialSpyInfo() { + + try { + File file = new File(configDir, "SocialSpyInfo.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(socialspy); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the social spy info file!"); + e.printStackTrace(); + } + + } + + public static void saveGlobalChatInfo() { + + try { + File file = new File(configDir, "GlobalChatInfo.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(ChatModeManager.getInstance().getData()); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the global chat info file!"); + e.printStackTrace(); + } + + } + + public static void saveMute() { + + try { + File file = new File(configDir, "Mute.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(ChatControl.getMutedPlayers()); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the mute file!"); + e.printStackTrace(); + } + + } + + public static void saveIgnore() { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (config.getNode("session_ignore").getBoolean()) return; + + try { + File file = new File(configDir, "Ignore.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(ChatControl.getIgnoreMap()); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the ignore file!"); + e.printStackTrace(); + } + + } + + @SuppressWarnings("unchecked") + public static HashMap loadModChatInfo() { + + HashMap result = null; + + try { + File file = new File(configDir, "StaffChatInfo.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (HashMap) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the mod chat info file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static void loadBulletins() { + + ArrayList result; + boolean enabled; + int timeBetween; + + try { + File file = new File(configDir, "Bulletins.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + enabled = in.readBoolean(); + timeBetween = in.readInt(); + result = (ArrayList) in.readObject(); + in.close(); + Bulletins.setArrayList(result); + if (enabled) { + Bulletins.startBulletins(timeBetween); + } + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the bulletins file!"); + e.printStackTrace(); + } + + } + + @SuppressWarnings("unchecked") + public static HashMap loadAnnouncements() { + + HashMap result = null; + + try { + File file = new File(configDir, "Announcements.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (HashMap) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the announcements file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static HashMap loadAdminChatInfo() { + + HashMap result = null; + + try { + File file = new File(configDir, "AdminChatInfo.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (HashMap) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the admin chat info file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static HashMap loadCasts() { + + HashMap result = null; + + try { + File file = new File(configDir, "Casts.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (HashMap) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the casts file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static HashMap loadGroupChatInfo() { + + HashMap result = null; + + try { + File file = new File(configDir, "GroupChatInfo.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (HashMap) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the group chat info file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static List loadGroupSpyInfo() { + + List result = null; + + try { + File file = new File(configDir, "GroupSpyInfo.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (List) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the group spy info file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static List loadSocialSpyInfo() { + + List result = null; + + try { + File file = new File(configDir, "SocialSpyInfo.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (List) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the social spy info file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static Map loadGlobalChatInfo() { + + Map result = null; + + try { + File file = new File(configDir, "GlobalChatInfo.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (Map) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the global chat info file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static Set loadMute() { + + Set result = null; + + try { + File file = new File(configDir, "Mute.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (Set) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the mute file!"); + e.printStackTrace(); + } + + return result; + + } + + @SuppressWarnings("unchecked") + public static Map> loadIgnore() { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig(); + + if (config.getNode("session_ignore").getBoolean()) return new HashMap<>(); + + Map> result = null; + + try { + File file = new File(configDir, "Ignore.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (Map>) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[MultiChat] [Load Error] An error has occured reading the ignore file!"); + e.printStackTrace(); + } + + return result; + + } + + public static void Startup() { + + System.out.println("[MultiChat] Starting load routine for data files"); + + File f = new File(configDir, "StaffChatInfo.dat"); + File f2 = new File(configDir, "AdminChatInfo.dat"); + + if ((f.exists()) && (!f.isDirectory()) && (f2.exists()) && (!f2.isDirectory())) { + + modchatpreferences.putAll(loadModChatInfo()); + adminchatpreferences.putAll(loadAdminChatInfo()); + + } else { + + System.out.println("[MultiChat] Some staff chat files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Welcome to MultiChat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveChatInfo(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f3 = new File(configDir, "GroupChatInfo.dat"); + + if ((f3.exists()) && (!f3.isDirectory())) { + + groupchats.putAll(loadGroupChatInfo()); + + } else { + + System.out.println("[MultiChat] Some group chat files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Enabling Group Chats! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveGroupChatInfo(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f4 = new File(configDir, "GroupSpyInfo.dat"); + + if ((f4.exists()) && (!f4.isDirectory())) { + + allspy = loadGroupSpyInfo(); + + } else { + + System.out.println("[MultiChat] Some group spy files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Enabling Group-Spy! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveGroupSpyInfo(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f5 = new File(configDir, "GlobalChatInfo.dat"); + + if ((f5.exists()) && (!f5.isDirectory())) { + + ChatModeManager.getInstance().loadData(loadGlobalChatInfo()); + + } else { + + System.out.println("[MultiChat] Some global chat files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Enabling Global Chat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveGlobalChatInfo(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f6 = new File(configDir, "SocialSpyInfo.dat"); + + if ((f6.exists()) && (!f6.isDirectory())) { + + socialspy = loadSocialSpyInfo(); + + } else { + + System.out.println("[MultiChat] Some social spy files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Enabling Social Spy! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveGroupSpyInfo(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f7 = new File(configDir, "Announcements.dat"); + + if ((f7.exists()) && (!f7.isDirectory())) { + + Announcements.loadAnnouncementList((loadAnnouncements())); + + } else { + + System.out.println("[MultiChat] Some announcements files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Welcome to MultiChat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveAnnouncements(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f8 = new File(configDir, "Bulletins.dat"); + + if ((f8.exists()) && (!f8.isDirectory())) { + + loadBulletins(); + + } else { + + System.out.println("[MultiChat] Some bulletins files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Welcome to MultiChat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveBulletins(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f9 = new File(configDir, "Casts.dat"); + + if ((f9.exists()) && (!f9.isDirectory())) { + + CastControl.castList = loadCasts(); + + } else { + + System.out.println("[MultiChat] Some casts files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Welcome to MultiChat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveCasts(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f10 = new File(configDir, "Mute.dat"); + + if ((f10.exists()) && (!f10.isDirectory())) { + + ChatControl.setMutedPlayers(loadMute()); + + } else { + + System.out.println("[MultiChat] Some mute files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Welcome to MultiChat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveMute(); + System.out.println("[MultiChat] The files were created!"); + + } + + File f11 = new File(configDir, "Ignore.dat"); + + if ((f11.exists()) && (!f11.isDirectory())) { + + ChatControl.setIgnoreMap(loadIgnore()); + + } else { + + System.out.println("[MultiChat] Some ignore files do not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Welcome to MultiChat! :D"); + System.out.println("[MultiChat] Attempting to create hash files!"); + saveMute(); + System.out.println("[MultiChat] The files were created!"); + + } + + System.out.println("[MultiChat] [COMPLETE] Load sequence finished! (Any errors reported above)"); + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MultiChatUtil.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MultiChatUtil.java new file mode 100644 index 00000000..90b83d16 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/MultiChatUtil.java @@ -0,0 +1,151 @@ +package xyz.olivermartin.multichat.velocity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MultiChatUtil { + + /** + * Reformat the RGB codes into Spigot Native version + * + * @param message + * @return message reformatted + */ + public static String reformatRGB(String message) { + // Translate RGB codes + return message.replaceAll("(?i)\\&(x|#)([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])", "&x&$2&$3&$4&$5&$6&$7"); + } + + public static String approximateHexCodes(String message) { + + message = message.replaceAll("(?i)(\\&|§)x(\\&|§)([0-9A-F])(\\&|§)([0-9A-F])(\\&|§)([0-9A-F])(\\&|§)([0-9A-F])(\\&|§)([0-9A-F])(\\&|§)([0-9A-F])", "&#$3$5$7$9$11$13"); + + List allMatches = new ArrayList(); + Matcher m = Pattern.compile("(?i)\\&(x|#)([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])") + .matcher(message); + while (m.find()) { + allMatches.add(m.group()); + } + + for (String match : allMatches) { + String hexonly = match.split("#")[1]; + String minecraftCode = hexToMinecraft(hexonly); + message = message.replace(match,"§"+minecraftCode); + } + + return message; + + } + + public static String hexToMinecraft(String hex) { + + String rcode = hex.substring(0,2); + String gcode = hex.substring(2,4); + String bcode = hex.substring(4,6); + + int rint = Integer.parseInt(rcode,16); + int gint = Integer.parseInt(gcode,16); + int bint = Integer.parseInt(bcode,16); + + String[] cga = {"000000","0000aa","00aa00","00aaaa","aa0000","aa00aa","ffaa00","aaaaaa","555555","5555ff","55ff55","55ffff","ff5555","ff55ff","ffff55","ffffff"}; + + int diff = 999999999; + int best = -1; + + for (int i = 0; i < 16; i++) { + + String current = cga[i]; + + String rcode2 = current.substring(0,2); + String gcode2 = current.substring(2,4); + String bcode2 = current.substring(4,6); + + int rint2 = Integer.parseInt(rcode2,16); + int gint2 = Integer.parseInt(gcode2,16); + int bint2 = Integer.parseInt(bcode2,16); + + int val = Math.abs(rint-rint2) + Math.abs(gint-gint2) + Math.abs(bint-bint2); + + if (val < diff) { + best = i; + diff = val; + } + + } + + return Integer.toHexString(best); + + } + + /** + * Concatenate the arguments together to get the message as a string + * + * @param args The arguments of the command + * @param start The (zero-indexed) starting index of the message (inclusive) + * @param end The (zero-indexed) finishing index of the message (inclusive) + * @return The concatenated message + */ + public static String getMessageFromArgs(String[] args, int start, int end) { + + int counter = 0; + String message = ""; + for (String arg : args) { + if (counter >= start && counter <= end) { + if (counter != end) { + message = message + arg + " "; + } else { + message = message + arg; + } + } + counter++; + } + + return message; + + } + + /** + * Concatenate the arguments together to get the message as a string + * + * @param args The arguments of the command + * @param start The (zero-indexed) starting index of the message (inclusive) + * @return The concatenated message + */ + public static String getMessageFromArgs(String[] args, int start) { + + return getMessageFromArgs(args, start, args.length - 1); + + } + + /** + * Concatenate the arguments together to get the message as a string + * + * @param args The arguments of the command + * @return The concatenated message + */ + public static String getMessageFromArgs(String[] args) { + + return getMessageFromArgs(args, 0, args.length - 1); + + } + + public static String getStringFromCollection(Collection collection) { + + String result = ""; + + for (String item : collection) { + if (result.equals("")) { + result = result + item; + } else { + result = result + " " + item; + } + } + + return result; + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PlayerMeta.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PlayerMeta.java new file mode 100644 index 00000000..0c7c08ec --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PlayerMeta.java @@ -0,0 +1,28 @@ +package xyz.olivermartin.multichat.velocity; + +import java.util.UUID; + +public class PlayerMeta { + + public UUID uuid; + public String name; + public String nick; + public String spigotDisplayName; + public String prefix; + public String suffix; + public String world; + + public PlayerMeta(UUID uuid, String name) { + this.uuid = uuid; + this.name = name; + nick = name; + spigotDisplayName = nick; + prefix = ""; + suffix = ""; + world = ""; + } + + public String getSpigotDisplayname() { + return this.spigotDisplayName; + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PlayerMetaManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PlayerMetaManager.java new file mode 100644 index 00000000..71b62d03 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PlayerMetaManager.java @@ -0,0 +1,65 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.proxy.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; + +public class PlayerMetaManager { + + static { + instance = new PlayerMetaManager(); + } + + private static final PlayerMetaManager instance; + + public static PlayerMetaManager getInstance() { + return instance; + } + + // END OF STATIC + + private final Map metaMap; + + public PlayerMetaManager() { + this.metaMap = new HashMap<>(); + } + + public void registerPlayer(UUID uuid, String name) { + this.metaMap.put(uuid, new PlayerMeta(uuid, name)); + } + + public void unregisterPlayer(UUID uuid) { + metaMap.remove(uuid); + } + + public Optional getPlayer(UUID uuid) { + if (!metaMap.containsKey(uuid)) return Optional.empty(); + return Optional.of(metaMap.get(uuid)); + } + + public void updateDisplayName(UUID uuid) { + + DebugManager.log("[PlayerMetaManager] Updating display name..."); + + Optional opm = getPlayer(uuid); + + if (opm.isEmpty()) return; + + DebugManager.log("[PlayerMetaManager] Player is present!"); + + Player player = MultiChat.getInstance().getServer().getPlayer(uuid).orElse(null); + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean() && player != null) { + + DebugManager.log("[PlayerMetaManager] Fetch Spigot Display Names is true"); + + DebugManager.log("[PlayerMetaManager] display names [UNSUPPORTED IN VELOCITY]"); + + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PrivateMessageManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PrivateMessageManager.java new file mode 100644 index 00000000..0a6b1980 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/PrivateMessageManager.java @@ -0,0 +1,178 @@ +package xyz.olivermartin.multichat.velocity; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.bungee.MultiChatUtil; + +import java.util.UUID; + +public class PrivateMessageManager { + + private static PrivateMessageManager instance; + + public static PrivateMessageManager getInstance() { + return instance; + } + + static { + instance = new PrivateMessageManager(); + } + + /* END STATIC */ + + private ChatManipulation chatfix; + + private PrivateMessageManager() { + chatfix = new ChatManipulation(); + } + + public void sendMessage(String message, Player sender, Player target) { + + message = MultiChatUtil.reformatRGB(message); + + String messageoutformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmout").getString(); + String messageinformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmin").getString(); + String messagespyformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmspy").getString(); + + String finalmessage = chatfix.replaceMsgVars(messageoutformat, message, sender, target); + if (MultiChat.legacyServers.contains(sender.getCurrentServer().get().getServerInfo().getName())) { + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + + finalmessage = chatfix.replaceMsgVars(messageinformat, message, sender, target); + if (MultiChat.legacyServers.contains(target.getCurrentServer().get().getServerInfo().getName())) { + target.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + target.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + + finalmessage = chatfix.replaceMsgVars(messagespyformat, message, sender, target); + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (onlineplayer.hasPermission("multichat.staff.spy") + && MultiChat.socialspy.contains(onlineplayer.getUniqueId()) + && onlineplayer.getUniqueId() != sender.getUniqueId() + && onlineplayer.getUniqueId() != target.getUniqueId() + && !(sender.hasPermission("multichat.staff.spy.bypass") + || target.hasPermission("multichat.staff.spy.bypass"))) { + + if (onlineplayer.getCurrentServer() != null + && onlineplayer.getCurrentServer().get().getServerInfo() != null + && MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + + } + + } + + MultiChat.lastmsg.remove(sender.getUniqueId()); + + MultiChat.lastmsg.put(sender.getUniqueId(), target.getUniqueId()); + + MultiChat.lastmsg.remove(target.getUniqueId()); + + MultiChat.lastmsg.put(target.getUniqueId(), sender.getUniqueId()); + + ConsoleManager.logSocialSpy(sender.getUsername(), target.getUsername(), message); + + } + + public void sendMessageConsoleTarget(String message, Player sender) { + + message = MultiChatUtil.reformatRGB(message); + + String messageoutformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmout").getString(); + String messageinformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmin").getString(); + String messagespyformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmspy").getString(); + + String finalmessage = chatfix.replaceMsgConsoleTargetVars(messageoutformat, message, sender); + if (MultiChat.legacyServers.contains(sender.getCurrentServer().get().getServerInfo().getName())) { + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + + finalmessage = chatfix.replaceMsgConsoleTargetVars(messageinformat, message, sender); + MultiChat.getInstance().getServer().getConsoleCommandSource().sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + + finalmessage = chatfix.replaceMsgConsoleTargetVars(messagespyformat, message, sender); + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (onlineplayer.hasPermission("multichat.staff.spy") + && MultiChat.socialspy.contains(onlineplayer.getUniqueId()) + && onlineplayer.getUniqueId() != sender.getUniqueId() + && !sender.hasPermission("multichat.staff.spy.bypass")) { + + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + } + + } + + MultiChat.lastmsg.remove(sender.getUniqueId()); + + MultiChat.lastmsg.put(sender.getUniqueId(), new UUID(0L, 0L)); + + MultiChat.lastmsg.remove(new UUID(0L, 0L)); + + MultiChat.lastmsg.put(new UUID(0L, 0L), sender.getUniqueId()); + + } + + public void sendMessageConsoleSender(String message, Player target) { + + message = MultiChatUtil.reformatRGB(message); + + CommandSource sender = MultiChat.getInstance().getServer().getConsoleCommandSource(); + + String messageoutformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmout").getString(); + String messageinformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmin").getString(); + String messagespyformat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("pmspy").getString(); + + String finalmessage = chatfix.replaceMsgConsoleSenderVars(messageoutformat, message, target); + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + + finalmessage = chatfix.replaceMsgConsoleSenderVars(messageinformat, message, target); + if (MultiChat.legacyServers.contains(target.getCurrentServer().get().getServerInfo().getName())) { + target.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + target.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + + finalmessage = chatfix.replaceMsgConsoleSenderVars(messagespyformat, message, target); + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (onlineplayer.hasPermission("multichat.staff.spy") + && MultiChat.socialspy.contains(onlineplayer.getUniqueId()) + && onlineplayer.getUniqueId() != target.getUniqueId() + && !target.hasPermission("multichat.staff.spy.bypass")) { + + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(finalmessage))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(finalmessage)); + } + } + + } + + MultiChat.lastmsg.remove(new UUID(0L, 0L)); + + MultiChat.lastmsg.put(new UUID(0L, 0L), target.getUniqueId()); + + MultiChat.lastmsg.remove(target.getUniqueId()); + + MultiChat.lastmsg.put(target.getUniqueId(), new UUID(0L, 0L)); + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/StaffChatManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/StaffChatManager.java new file mode 100644 index 00000000..dd966bb9 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/StaffChatManager.java @@ -0,0 +1,119 @@ +package xyz.olivermartin.multichat.velocity; + +import com.olivermartin410.plugins.TChatInfo; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.bungee.MultiChatUtil; +import xyz.olivermartin.multichat.velocity.events.PostStaffChatEvent; + +import java.util.Optional; + +/** + * Staff Chat Manager + *

Manages chat input to the staff chats, both mod and admin

+ * + * @author Oliver Martin (Revilo410) + */ +public class StaffChatManager { + + public void sendModMessage(String username, String displayname, String server, String message) { + + message = MultiChatUtil.reformatRGB(message); + + ChatManipulation chatfix = new ChatManipulation(); + String messageFormat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("modchat").getNode("format").getString(); + String original = message; + + Optional crm; + + crm = ChatControl.applyChatRules(original, "staff_chats", username); + + if (crm.isPresent()) { + original = crm.get(); + } else { + return; + } + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (onlineplayer.hasPermission("multichat.staff.mod")) { + if (!MultiChat.modchatpreferences.containsKey(onlineplayer.getUniqueId())) { + TChatInfo chatinfo = new TChatInfo(); + chatinfo.setChatColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("modchat").getNode("ccdefault").getString().toCharArray()[0]); + chatinfo.setNameColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("modchat").getNode("ncdefault").getString().toCharArray()[0]); + MultiChat.modchatpreferences.put(onlineplayer.getUniqueId(), chatinfo); + } + + message = chatfix.replaceModChatVars(messageFormat, username, displayname, server, original, onlineplayer); + LegacyComponentSerializer serializer = LegacyComponentSerializer.legacyAmpersand(); + onlineplayer.sendMessage(serializer.deserialize(message)); + } + } + + // Trigger PostStaffChatEvent + if (username.equalsIgnoreCase("console")) { + MultiChat.getInstance().getServer().getEventManager().fire(new PostStaffChatEvent("mod", MultiChat.getInstance().getServer().getConsoleCommandSource(), original)); + } else { + if (MultiChat.getInstance().getServer().getPlayer(username).isPresent()) { + MultiChat.getInstance().getServer().getEventManager().fire(new PostStaffChatEvent("mod", MultiChat.getInstance().getServer().getPlayer(username).get(), original)); + } + } + + ConsoleManager.logModChat("(" + username + ") " + original); + + } + + public void sendAdminMessage(String username, String displayname, String server, String message) { + + message = MultiChatUtil.reformatRGB(message); + + String original = message; + ChatManipulation chatfix = new ChatManipulation(); + String messageFormat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("adminchat").getNode("format").getString(); + + Optional crm; + + crm = ChatControl.applyChatRules(original, "staff_chats", username); + + if (crm.isPresent()) { + original = crm.get(); + } else { + return; + } + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (onlineplayer.hasPermission("multichat.staff.admin")) { + + if (!MultiChat.adminchatpreferences.containsKey(onlineplayer.getUniqueId())) { + + TChatInfo chatinfo = new TChatInfo(); + chatinfo.setChatColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("adminchat").getNode("ccdefault").getString().toCharArray()[0]); + chatinfo.setNameColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("adminchat").getNode("ncdefault").getString().toCharArray()[0]); + + MultiChat.adminchatpreferences.put(onlineplayer.getUniqueId(), chatinfo); + + } + + message = chatfix.replaceAdminChatVars(messageFormat, username, displayname, server, original, onlineplayer); + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + + } + } + + // Trigger PostStaffChatEvent + if (username.equalsIgnoreCase("console")) { + MultiChat.getInstance().getServer().getEventManager().fire(new PostStaffChatEvent("admin", MultiChat.getInstance().getServer().getConsoleCommandSource(), original)); + } else { + if (MultiChat.getInstance().getServer().getPlayer(username).isPresent()) { + MultiChat.getInstance().getServer().getEventManager().fire(new PostStaffChatEvent("admin", MultiChat.getInstance().getServer().getPlayer(username).orElse(null), original)); + } + } + + ConsoleManager.logAdminChat("(" + username + ") " + original); + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/TViewChat.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/TViewChat.java new file mode 100644 index 00000000..de905ed2 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/TViewChat.java @@ -0,0 +1,43 @@ +package xyz.olivermartin.multichat.velocity; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * Viewed Chat Class + *

Class to represent the group chats a player is viewing, and what chat they have selected

+ * + * @author Oliver Martin (Revilo410) + */ +public class TViewChat implements Serializable { + + private static final long serialVersionUID = 1L; + private final List viewedchats = new ArrayList(); + private String selectedchat = ""; + + public List getViewed() { + return this.viewedchats; + } + + public void addViewed(String chat) { + this.viewedchats.add(chat); + } + + public boolean isViewing(String chat) { + return this.viewedchats.contains(chat); + } + + public void delViewed(String chat) { + this.viewedchats.remove(chat); + } + + public String getSelected() { + return this.selectedchat; + } + + public void setSelected(String chat) { + this.selectedchat = chat; + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/UUIDNameManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/UUIDNameManager.java new file mode 100644 index 00000000..2408443c --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/UUIDNameManager.java @@ -0,0 +1,83 @@ +package xyz.olivermartin.multichat.velocity; + +import java.io.*; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * UUID - NAME Manager + *

Manages storage of UUIDS with their currently associated username

+ * + * @author Oliver Martin (Revilo410) + */ +public class UUIDNameManager { + + private static final Map uuidname = new HashMap<>(); + + public static void addNew(UUID uuid, String name) { + uuidname.put(uuid, name); + } + + public static void removeUUID(UUID uuid) { + uuidname.remove(uuid); + } + + public static String getName(UUID uuid) { + return uuidname.get(uuid); + } + + public static void saveUUIDS() { + + try { + File file = new File(MultiChat.configDir, "MultiChatUUIDName.dat"); + FileOutputStream saveFile = new FileOutputStream(file); + ObjectOutputStream out = new ObjectOutputStream(saveFile); + out.writeObject(uuidname); + out.close(); + } catch (IOException e) { + System.out.println("[MultiChat] [Save Error] An error has occured writing the uuid-name file!"); + e.printStackTrace(); + } + + } + + @SuppressWarnings("unchecked") + public static HashMap loadUUIDS() { + + HashMap result = null; + + try { + File file = new File(MultiChat.configDir, "MultiChatUUIDName.dat"); + FileInputStream saveFile = new FileInputStream(file); + ObjectInputStream in = new ObjectInputStream(saveFile); + result = (HashMap) in.readObject(); + in.close(); + } catch (IOException | ClassNotFoundException e) { + System.out.println("[ActivityMonitor] [Load Error] An error has occured reading the uuid-name file!"); + e.printStackTrace(); + } + + return result; + + } + + public static void Startup() { + + File f = new File(MultiChat.configDir, "MultiChatUUIDName.dat"); + + if ((f.exists()) && (!f.isDirectory())) { + uuidname.putAll(loadUUIDS()); + } else { + System.out.println("[MultiChat] File for uuid-name conversion does not exist to load. Must be first startup!"); + System.out.println("[MultiChat] Attempting to create hash file!"); + saveUUIDS(); + System.out.println("[MultiChat] The uuid-name file was created!"); + } + + } + + public static boolean existsUUID(UUID uuid) { + return uuidname.containsKey(uuid); + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ACCCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ACCCommand.java new file mode 100644 index 00000000..2508b486 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ACCCommand.java @@ -0,0 +1,95 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.olivermartin410.plugins.TChatInfo; +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.DebugManager; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +/** + * Admin-Chat colour command + *

This command allows individual staff members to set their colour of the admin-chat messages they receive

+ * + * @author Oliver Martin (Revilo410) + * + */ +public class ACCCommand extends Command { + + // Command aliases + private static final String[] aliases = new String[] {}; + + public ACCCommand() { + super("acc", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.mod"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + // Check correct arguments + if (args.length != 2) { + + if ((sender instanceof Player)) { + MessageManager.sendMessage(sender, "command_acc_usage"); + } else { + MessageManager.sendMessage(sender, "command_acc_only_players"); + } + + } else if ((sender instanceof Player)) { + Player player = (Player) sender; + + DebugManager.log("[ACCCommand] Command sender is a player"); + + TChatInfo chatinfo = new TChatInfo(); + + // Convert args to lowercase + args[0] = args[0].toLowerCase(); + args[1] = args[1].toLowerCase(); + + if ((args[0].equals("a")) || (args[0].equals("b")) || (args[0].equals("c")) || (args[0].equals("d")) + || (args[0].equals("e")) || (args[0].equals("f")) || (args[0].equals("0")) || (args[0].equals("1")) + || (args[0].equals("2")) || (args[0].equals("3")) || (args[0].equals("4")) || (args[0].equals("5")) + || (args[0].equals("6")) || (args[0].equals("7")) || (args[0].equals("8")) || (args[0].equals("9"))) { + + if ((args[1].equals("a")) || (args[1].equals("b")) || (args[1].equals("c")) || (args[1].equals("d")) + || (args[1].equals("e")) || (args[1].equals("f")) || (args[1].equals("0")) || (args[1].equals("1")) + || (args[1].equals("2")) || (args[1].equals("3")) || (args[1].equals("4")) || (args[1].equals("5")) + || (args[1].equals("6")) || (args[1].equals("7")) || (args[1].equals("8")) || (args[1].equals("9"))) { + + DebugManager.log("[ACCCommand] Colour codes are valid"); + + chatinfo.setChatColor(args[0].charAt(0)); + chatinfo.setNameColor(args[1].charAt(0)); + + MultiChat.adminchatpreferences.remove(player.getUniqueId()); + MultiChat.adminchatpreferences.put(player.getUniqueId(), chatinfo); + + DebugManager.log("[ACCCommand] Preferences updated"); + + MessageManager.sendMessage(sender, "command_acc_updated"); + + } else { + + MessageManager.sendMessage(sender, "command_acc_invalid"); + MessageManager.sendMessage(sender, "command_acc_invalid_usage"); + + } + + } else { + + MessageManager.sendMessage(sender, "command_acc_invalid"); + MessageManager.sendMessage(sender, "command_acc_invalid_usage"); + + } + + } else { + + MessageManager.sendMessage(sender, "command_acc_only_players"); + + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ACCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ACCommand.java new file mode 100644 index 00000000..302af51d --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ACCommand.java @@ -0,0 +1,80 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.DebugManager; +import xyz.olivermartin.multichat.velocity.Events; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.StaffChatManager; +import xyz.olivermartin.multichat.velocity.MultiChatUtil; + +/** + * Admin-Chat command + *

Allows the user to toggle / send a message to admin-chat

+ * + * @author Oliver Martin (Revilo410) + */ +public class ACCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public ACCommand() { + super("ac", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.admin"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + boolean toggleresult; + + if (args.length < 1) { + + if ((sender instanceof Player)) { + Player player = (Player) sender; + + DebugManager.log("[ACCommand] Command sender is a player"); + + toggleresult = Events.toggleAC(player.getUniqueId()); + + DebugManager.log("[ACCommand] AC new toggle state: " + toggleresult); + + if (toggleresult) { + MessageManager.sendMessage(sender, "command_ac_toggle_on"); + } else { + MessageManager.sendMessage(sender, "command_ac_toggle_off"); + } + + } else { + + MessageManager.sendMessage(sender, "command_ac_only_players"); + + } + + } else if ((sender instanceof Player)) { + Player player = (Player) sender; + + DebugManager.log("[ACCommand] Command sender is a player"); + + String message = MultiChatUtil.getMessageFromArgs(args); + + StaffChatManager chatman = new StaffChatManager(); + + DebugManager.log("[ACCommand] Next line of code will send the message, if no errors, then it worked!"); + player.getCurrentServer().ifPresent(server -> chatman.sendAdminMessage(player.getGameProfile().getName(), player.getUsername(), server.getServerInfo().getName(), message)); + } else { + DebugManager.log("[ACCommand] Command sender is the console"); + + String message = MultiChatUtil.getMessageFromArgs(args); + + StaffChatManager chatman = new StaffChatManager(); + + DebugManager.log("[ACCommand] Next line of code will send the message, if no errors, then it worked!"); + + chatman.sendAdminMessage("CONSOLE", "CONSOLE", "#", message); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/AnnouncementCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/AnnouncementCommand.java new file mode 100644 index 00000000..3d660b28 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/AnnouncementCommand.java @@ -0,0 +1,157 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import xyz.olivermartin.multichat.velocity.Announcements; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChatUtil; + +import java.util.Iterator; +import java.util.Map; + +/** + * Announcement Command + *

Allows the user to create, remove or use announcements

+ * + * @author Oliver Martin (Revilo410) + */ +public class AnnouncementCommand extends Command { + + private static final String[] aliases = new String[]{"announce"}; + + public AnnouncementCommand() { + super("announcement", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.announce"); + } + + public void execute(Invocation invocation) { + + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + showCommandUsage(sender); + + } else if (args.length == 1) { + + if (args[0].equalsIgnoreCase("list")) { + + Map announcementList = Announcements.getAnnouncementList(); + Iterator it = announcementList.keySet().iterator(); + + MessageManager.sendMessage(sender, "command_announcement_list"); + + String currentItem; + while (it.hasNext()) { + currentItem = it.next(); + MessageManager.sendSpecialMessage(sender, "command_announcement_list_item", currentItem + ": " + announcementList.get(currentItem)); + } + + } else if (Announcements.existsAnnouncemnt(args[0].toLowerCase())) { + + Announcements.playAnnouncement(args[0].toLowerCase()); + + } else { + + MessageManager.sendSpecialMessage(sender, "command_announcement_does_not_exist", args[0].toUpperCase()); + + } + + } else if (args.length == 2) { + + if (args[0].equalsIgnoreCase("remove")) { + + if (Announcements.removeAnnouncement(args[1].toLowerCase())) { + MessageManager.sendSpecialMessage(sender, "command_announcement_removed", args[1].toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_announcement_does_not_exist", args[1].toUpperCase()); + } + + } else if (args[0].equalsIgnoreCase("stop")) { + + if (Announcements.stopAnnouncement(args[1].toLowerCase())) { + MessageManager.sendSpecialMessage(sender, "command_announcement_stopped", args[1].toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_announcement_stopped_error", args[1].toUpperCase()); + } + + } else { + + showCommandUsage(sender); + } + + } else if (args.length == 3) { + + if (isInteger(args[2])) { + + if (args[0].equalsIgnoreCase("start")) { + + if (Announcements.startAnnouncement(args[1].toLowerCase(), Integer.parseInt(args[2]))) { + MessageManager.sendSpecialMessage(sender, "command_announcement_started", args[1].toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_announcement_started_error", args[1].toUpperCase()); + } + + } else { + + showCommandUsage(sender); + + } + + } else if (args[0].equalsIgnoreCase("add")) { + + if (Announcements.addAnnouncement(args[1].toLowerCase(), args[2])) { + MessageManager.sendSpecialMessage(sender, "command_announcement_added", args[1].toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_announcement_added_error", args[1].toUpperCase()); + } + + } else { + + showCommandUsage(sender); + + } + + } else { + if (args[0].equalsIgnoreCase("add")) { + String message = MultiChatUtil.getMessageFromArgs(args, 2); + if (Announcements.addAnnouncement(args[1].toLowerCase(), message)) { + MessageManager.sendSpecialMessage(sender, "command_announcement_added", args[1].toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_announcement_added_error", args[1].toUpperCase()); + } + } else { + showCommandUsage(sender); + } + } + + } + + public static boolean isInteger(String str) { + try { + Integer.parseInt(str); + } catch (NumberFormatException nfe) { + return false; + } + + return true; + } + + private void showCommandUsage(CommandSource sender) { + + MessageManager.sendMessage(sender, "command_announcement_usage"); + sender.sendMessage(Component.text("/announcement add ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/announcement remove ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/announcement start ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/announcement stop ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/announcement list").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/announce ").color(NamedTextColor.AQUA)); + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/BulletinCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/BulletinCommand.java new file mode 100644 index 00000000..5f5ef335 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/BulletinCommand.java @@ -0,0 +1,120 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import xyz.olivermartin.multichat.velocity.Bulletins; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChatUtil; + +import java.util.Iterator; + +/** + * Bulletin Command + *

Allows the user to create, start and stop bulletins

+ * + * @author Oliver Martin (Revilo410) + */ +public class BulletinCommand extends Command { + + private static final String[] aliases = new String[]{"bulletins"}; + + public BulletinCommand() { + super("bulletin", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.bulletin"); + } + + public void execute(Invocation invocation) { + + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + showCommandUsage(sender); + + } else if (args.length == 1) { + + if (args[0].equalsIgnoreCase("stop")) { + + Bulletins.stopBulletins(); + MessageManager.sendMessage(sender, "command_bulletin_stopped"); + + } else if (args[0].equalsIgnoreCase("list")) { + + int counter = 0; + Iterator it = Bulletins.getIterator(); + + MessageManager.sendMessage(sender, "command_bulletin_list"); + while (it.hasNext()) { + counter++; + MessageManager.sendSpecialMessage(sender, "command_bulletin_list_item", counter + ": " + it.next()); + } + + } else { + + showCommandUsage(sender); + + } + + } else if (args.length == 2) { + + if (args[0].equalsIgnoreCase("remove")) { + + try { + + Bulletins.removeBulletin(Integer.parseInt(args[1]) - 1); + MessageManager.sendMessage(sender, "command_bulletin_removed"); + + } catch (Exception e) { + MessageManager.sendMessage(sender, "command_bulletin_invalid_usage"); + } + + } else if (args[0].equalsIgnoreCase("start")) { + + try { + Bulletins.startBulletins(Integer.parseInt(args[1])); + MessageManager.sendMessage(sender, "command_bulletin_started"); + } catch (Exception e) { + MessageManager.sendMessage(sender, "command_bulletin_invalid_usage"); + } + + } else if (args[0].equalsIgnoreCase("add")) { + + Bulletins.addBulletin(args[1]); + MessageManager.sendMessage(sender, "command_bulletin_added"); + + } else { + + showCommandUsage(sender); + + } + + } else { + + if (args[0].equalsIgnoreCase("add")) { + + String message = MultiChatUtil.getMessageFromArgs(args, 1); + + Bulletins.addBulletin(message); + MessageManager.sendMessage(sender, "command_bulletin_added"); + } + + } + + } + + private void showCommandUsage(CommandSource sender) { + + MessageManager.sendMessage(sender, "command_bulletin_usage"); + sender.sendMessage(Component.text("/bulletin add ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/bulletin remove ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/bulletin start ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/bulletin stop").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/bulletin list").color(NamedTextColor.AQUA)); + + } +} \ No newline at end of file diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/CastCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/CastCommand.java new file mode 100644 index 00000000..c9f97851 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/CastCommand.java @@ -0,0 +1,127 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import xyz.olivermartin.multichat.velocity.CastControl; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChatUtil; + +import java.util.Iterator; + +/** + * Cast Command + *

The Custom broadcAST (CAST) command allows you to create your own customised broadcast formats

+ * + * @author Oliver Martin (Revilo410) + * + */ +public class CastCommand extends Command { + + private static final String[] aliases = new String[] {}; + + public CastCommand() { + super("cast", aliases); + } + + public void showCommandUsage(CommandSource sender) { + MessageManager.sendMessage(sender, "command_cast_usage"); + sender.sendMessage(Component.text("/cast add ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/cast remove ").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/cast list").color(NamedTextColor.AQUA)); + sender.sendMessage(Component.text("/ ").color(NamedTextColor.AQUA)); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.cast.admin"); + } + + public void execute(Invocation invocation) { + + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + showCommandUsage(sender); + + } else if (args.length == 1) { + + if (args[0].equalsIgnoreCase("list")) { + + Iterator it = CastControl.castList.keySet().iterator(); + String currentItem; + + MessageManager.sendMessage(sender, "command_cast_list"); + while (it.hasNext()) { + currentItem = it.next(); + MessageManager.sendSpecialMessage(sender, "command_cast_list_item", currentItem + ": " + CastControl.castList.get(currentItem)); + } + + } else { + showCommandUsage(sender); + } + + } else if (args.length == 2) { + + if (args[0].equalsIgnoreCase("remove")) { + + if (CastControl.existsCast(args[1])) { + + CastControl.removeCast(args[1]); + MessageManager.sendSpecialMessage(sender, "command_cast_removed", args[1].toUpperCase()); + + } else { + + MessageManager.sendSpecialMessage(sender, "command_cast_does_not_exist", args[1].toUpperCase()); + } + + } else { + + showCommandUsage(sender); + + } + + } else if (args.length == 3) { + + if (args[0].equalsIgnoreCase("add")) { + + if (!(CastControl.existsCast(args[1])) && !args[1].equalsIgnoreCase("cast")) { + + CastControl.addCast(args[1], args[2]); + MessageManager.sendSpecialMessage(sender, "command_cast_added", args[1].toUpperCase()); + + } else { + + MessageManager.sendSpecialMessage(sender, "command_cast_added_error", args[1].toUpperCase()); + } + + } else { + + showCommandUsage(sender); + + } + + } else { + if (args[0].equalsIgnoreCase("add")) { + + String message = MultiChatUtil.getMessageFromArgs(args, 2); + + if (!CastControl.existsCast(args[1])) { + + CastControl.addCast(args[1], message); + MessageManager.sendSpecialMessage(sender, "command_cast_added", args[1].toUpperCase()); + + } else { + + MessageManager.sendSpecialMessage(sender, "command_cast_added_error", args[1].toUpperCase()); + } + + } else { + + showCommandUsage(sender); + + } + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ChannelCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ChannelCommand.java new file mode 100644 index 00000000..d98de2d6 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ChannelCommand.java @@ -0,0 +1,149 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.*; + +/** + * Chat Channel Command + *

Players can use this command to switch channels, as well as show and hide specific channels

+ * + * @author Oliver Martin (Revilo410) + */ +public class ChannelCommand extends Command { + + public ChannelCommand() { + super("channel", ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("channelcommand").getList(String::valueOf).toArray(new String[0])); + } + + private void showHelp(CommandSource sender) { + MessageManager.sendMessage(sender, "command_channel_help"); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.channel"); + } + + public void execute(Invocation invocation) { + + var args = invocation.arguments(); + var sender = invocation.source(); + + if ((sender instanceof Player)) { + if ((args.length < 1) || ((args.length == 1) && (args[0].toLowerCase().equals("help")))) { + showHelp(sender); + } else if (args.length == 1) { + showHelp(sender); + } else if (args.length == 2) { + String subCommand = args[0].toLowerCase(); + String operand = args[1].toLowerCase(); + + switch (subCommand) { + case "switch": + if (!sender.hasPermission("multichat.chat.channel.switch")) { + MessageManager.sendMessage(sender, "command_channel_switch_no_permission"); + return; + } + if (operand.equals("local")) { + ChatModeManager.getInstance().setLocal(((Player) sender).getUniqueId()); + MessageManager.sendSpecialMessage(sender, "command_channel_switch", operand.toUpperCase()); + } else if (operand.equals("global")) { + ChatModeManager.getInstance().setGlobal(((Player) sender).getUniqueId()); + MessageManager.sendSpecialMessage(sender, "command_channel_switch", operand.toUpperCase()); + } else { + MessageManager.sendMessage(sender, "command_channel_does_not_exist"); + } + + case "hide": + if (!sender.hasPermission("multichat.chat.channel.hide")) { + MessageManager.sendMessage(sender, "command_channel_hide_no_permission"); + return; + } + if (operand.equals("local")) { + + if (!ChatModeManager.getInstance().isGlobal(((Player) sender).getUniqueId())) { + MessageManager.sendMessage(sender, "command_channel_cannot_hide"); + return; + } + + Channel local = Channel.getLocalChannel(); + if (local.isMember(((Player) sender).getUniqueId())) { + local.addMember(((Player) sender).getUniqueId()); + MessageManager.sendSpecialMessage(sender, "command_channel_hide", operand.toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_channel_already_hide", operand.toUpperCase()); + } + + } else if (operand.equals("global")) { + + if (ChatModeManager.getInstance().isGlobal(((Player) sender).getUniqueId())) { + MessageManager.sendMessage(sender, "command_channel_cannot_hide"); + return; + } + + Channel global = Channel.getGlobalChannel(); + if (global.isMember(((Player) sender).getUniqueId())) { + global.addMember(((Player) sender).getUniqueId()); + MessageManager.sendSpecialMessage(sender, "command_channel_hide", operand.toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_channel_already_hide", operand.toUpperCase()); + } + + } else { + MessageManager.sendMessage(sender, "command_channel_does_not_exist"); + } + + case "show": + if (!sender.hasPermission("multichat.chat.channel.show")) { + MessageManager.sendMessage(sender, "command_channel_show_no_permission"); + return; + } + if (operand.equals("local")) { + + Channel local = Channel.getLocalChannel(); + if (!local.isMember(((Player) sender).getUniqueId())) { + local.removeMember(((Player) sender).getUniqueId()); + MessageManager.sendSpecialMessage(sender, "command_channel_show", operand.toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_channel_already_show", operand.toUpperCase()); + } + + } else if (operand.equals("global")) { + + Channel global = Channel.getGlobalChannel(); + if (!global.isMember(((Player) sender).getUniqueId())) { + global.removeMember(((Player) sender).getUniqueId()); + MessageManager.sendSpecialMessage(sender, "command_channel_show", operand.toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_channel_already_show", operand.toUpperCase()); + } + + } else { + MessageManager.sendMessage(sender, "command_channel_does_not_exist"); + } + + default: + showHelp(sender); + break; + } + + // Update local channel info + for (Player p : MultiChat.getInstance().getServer().getAllPlayers()) { + BungeeComm.sendPlayerChannelMessage( + p.getUsername(), + Channel.getChannel(p.getUniqueId()).getName(), + Channel.getChannel(p.getUniqueId()), + p.getCurrentServer().get().getServerInfo(), + (p.hasPermission("multichat.chat.color") || p.hasPermission("multichat.chat.color.simple")), + (p.hasPermission("multichat.chat.color") || p.hasPermission("multichat.chat.color.rgb"))); + } + + } + + } else { + MessageManager.sendMessage(sender, "command_channel_only_players"); + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ClearChatCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ClearChatCommand.java new file mode 100644 index 00000000..1eb1a661 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ClearChatCommand.java @@ -0,0 +1,121 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.Component; +import xyz.olivermartin.multichat.velocity.ConfigManager; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +/** + * Clear Chat Command + *

Allows the user to clear their personal chat, the server chat, the global chat, or all servers' chat

+ * + * @author Oliver Martin (Revilo410) + * + */ +public class ClearChatCommand extends Command { + + private static final String[] aliases = new String[] {"chatclear","wipechat","killchat"}; + + public ClearChatCommand() { + super("clearchat", aliases); + } + + private void clearChatSelf(CommandSource sender) { + for (int i = 1 ; i<151 ; i++ ) { + sender.sendMessage(Component.empty()); + } + MessageManager.sendMessage(sender, "command_clearchat_self"); + } + + private void clearChatServer(CommandSource sender) { + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (onlineplayer.getCurrentServer().get().getServerInfo().getName().equals(((Player) sender).getCurrentServer().get().getServerInfo().getName() )) { + for (int i = 1 ; i<151 ; i++ ) { + onlineplayer.sendMessage(Component.empty()); + } + MessageManager.sendMessage(onlineplayer, "command_clearchat_server"); + } + } + } + + private void clearChatGlobal() { + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_global").getList(String::valueOf).contains(onlineplayer.getCurrentServer().get().getServerInfo().getName()) ) { + for (int i = 1 ; i<151 ; i++ ) { + onlineplayer.sendMessage(Component.empty()); + } + MessageManager.sendMessage(onlineplayer, "command_clearchat_global"); + } + } + + } + + private void clearChatAll() { + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + for (int i = 1 ; i<151 ; i++ ) { + onlineplayer.sendMessage(Component.empty()); + } + MessageManager.sendMessage(onlineplayer, "command_clearchat_all"); + } + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.clear"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + clearChatSelf(sender); + + } else { + if (args.length == 1) { + + if (args[0].equalsIgnoreCase("self")) { + + clearChatSelf(sender); + + } else if (args[0].equalsIgnoreCase("all") ) { + + if (sender.hasPermission("multichat.chat.clear.all")) { + + clearChatAll(); + + } else { + MessageManager.sendSpecialMessage(sender, "command_clearchat_no_permission", "ALL"); + } + + } else if (args[0].equalsIgnoreCase("server") ) { + + if (sender.hasPermission("multichat.chat.clear.server")) { + + clearChatServer(sender); + + } else { + MessageManager.sendSpecialMessage(sender, "command_clearchat_no_permission", "SERVER"); + } + + } else if (args[0].equalsIgnoreCase("global") ) { + + if (sender.hasPermission("multichat.chat.clear.global")) { + + clearChatGlobal(); + + } else { + MessageManager.sendSpecialMessage(sender, "command_clearchat_no_permission", "GLOBAL"); + } + + } + + } else { + MessageManager.sendMessage(sender, "command_clearchat_usage"); + } + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/Command.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/Command.java new file mode 100644 index 00000000..34b01d37 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/Command.java @@ -0,0 +1,15 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandMeta; +import com.velocitypowered.api.command.SimpleCommand; +import lombok.Getter; +import xyz.olivermartin.multichat.velocity.MultiChat; + +public abstract class Command implements SimpleCommand { + @Getter + private final CommandMeta meta; + + public Command(String name, String... names) { + meta = MultiChat.getInstance().getServer().getCommandManager().metaBuilder(name).aliases(names).build(); + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/DisplayCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/DisplayCommand.java new file mode 100644 index 00000000..405a6156 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/DisplayCommand.java @@ -0,0 +1,67 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import ninja.leaping.configurate.ConfigurationNode; +import xyz.olivermartin.multichat.bungee.MultiChatUtil; +import xyz.olivermartin.multichat.velocity.*; +import xyz.olivermartin.multichat.velocity.events.PostBroadcastEvent; + +/** + * Display Command + *

Displays a message to every player connected to the BungeeCord network

+ * + * @author Oliver Martin (Revilo410) + */ +public class DisplayCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public DisplayCommand() { + super("display", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.display"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + MessageManager.sendMessage(sender, "command_display_desc"); + MessageManager.sendMessage(sender, "command_display_usage"); + + } else { + + String message = MultiChatUtil.getMessageFromArgs(args); + + displayMessage(message); + } + } + + public static void displayMessage(String message) { + message = ChatControl.applyChatRules(message, "display_command", "").get(); + message = MultiChatUtil.reformatRGB(message); + ConfigurationNode config = ConfigManager.getInstance().getHandler("config.yml").getConfig(); + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (onlineplayer.getCurrentServer().isPresent()) { + if (!config.getNode("no_global").getList(String::valueOf).contains( + onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + else + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } + } + + // Trigger PostBroadcastEvent + MultiChat.getInstance().getServer().getEventManager().fire(new PostBroadcastEvent("display", message)); + + ConsoleManager.logDisplayMessage(message); + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/FreezeChatCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/FreezeChatCommand.java new file mode 100644 index 00000000..b9131e32 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/FreezeChatCommand.java @@ -0,0 +1,52 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +/** + * Freeze Chat Command + *

Allows staff members to block all chat messages being sent

+ * + * @author Oliver Martin (Revilo410) + */ +public class FreezeChatCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public FreezeChatCommand() { + super("freezechat", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.freeze"); + } + + public void execute(Invocation invocation) { + var sender = invocation.source(); + String senderName = ""; + + if (sender instanceof Player) { + senderName = ((Player) sender).getUsername(); + } else { + senderName = "CONSOLE"; + } + + if (MultiChat.frozen) { + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + MessageManager.sendSpecialMessage(onlineplayer, "command_freezechat_thawed", senderName); + } + + MultiChat.frozen = false; + + } else { + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + MessageManager.sendSpecialMessage(onlineplayer, "command_freezechat_frozen", senderName); + } + + MultiChat.frozen = true; + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GCCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GCCommand.java new file mode 100644 index 00000000..5c8c3dcd --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GCCommand.java @@ -0,0 +1,145 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.olivermartin410.plugins.TGroupChatInfo; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.velocity.*; + +import java.util.Optional; + +/** + * Group Chat Messaging Command + *

Allows players to send a message direct to a group chat or toggle group chats

+ * + * @author Oliver Martin (Revilo410) + */ +public class GCCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public GCCommand() { + super("gc", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.group"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + if ((sender instanceof Player)) { + Player player = (Player) sender; + + boolean toggleresult = Events.toggleGC(player.getUniqueId()); + + if (toggleresult) { + MessageManager.sendMessage(sender, "command_gc_toggle_on"); + } else { + MessageManager.sendMessage(sender, "command_gc_toggle_off"); + } + + } else { + + MessageManager.sendMessage(sender, "command_gc_only_players_toggle"); + } + + } else if ((sender instanceof Player)) { + Player player = (Player) sender; + + if (MultiChat.viewedchats.get(player.getUniqueId()) != null) { + + String groupName = MultiChat.viewedchats.get(player.getUniqueId()); + + if (MultiChat.groupchats.containsKey(groupName)) { + + TGroupChatInfo groupInfo = MultiChat.groupchats.get(groupName); + + String message = MultiChatUtil.getMessageFromArgs(args); + + String playerName = ((Player) sender).getUsername(); + + if ((groupInfo.getFormal()) + && (groupInfo.getAdmins().contains(player.getUniqueId()))) { + playerName = "&o" + playerName; + } + + sendMessage(message, playerName, groupInfo); + + } else { + + MessageManager.sendMessage(sender, "command_gc_no_longer_exists"); + } + + } else { + MessageManager.sendMessage(sender, "command_gc_no_chat_selected"); + } + + } else { + MessageManager.sendMessage(sender, "command_gc_only_players_speak"); + } + } + + public static void sendMessage(String message, String playerName, TGroupChatInfo groupInfo) { + + ChatManipulation chatfix = new ChatManipulation(); + + message = MultiChatUtil.reformatRGB(message); + + Player potentialPlayer = MultiChat.getInstance().getServer().getPlayer(playerName).orElse(null); + if (potentialPlayer != null) { + if (ChatControl.isMuted(potentialPlayer.getUniqueId(), "group_chats")) { + MessageManager.sendMessage(potentialPlayer, "mute_cannot_send_message"); + return; + } + + if (ChatControl.handleSpam(potentialPlayer, message, "group_chats")) { + return; + } + } + + Optional crm; + + crm = ChatControl.applyChatRules(message, "group_chats", playerName); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return; + } + + String messageFormat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("groupchat").getNode("format").getString(); + message = chatfix.replaceGroupChatVars(messageFormat, playerName, message, groupInfo.getName()); + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (((groupInfo.existsViewer(onlineplayer.getUniqueId())) && (onlineplayer.hasPermission("multichat.group"))) || ((MultiChat.allspy.contains(onlineplayer.getUniqueId())) && (onlineplayer.hasPermission("multichat.staff.spy")))) { + + if (potentialPlayer != null) { + if (!ChatControl.ignores(potentialPlayer.getUniqueId(), onlineplayer.getUniqueId(), "group_chats")) { + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } else { + ChatControl.sendIgnoreNotifications(onlineplayer, potentialPlayer, "group_chats"); + } + } else { + if (MultiChat.legacyServers.contains(onlineplayer.getCurrentServer().get().getServerInfo().getName())) { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(MultiChatUtil.approximateHexCodes(message))); + } else { + onlineplayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message)); + } + } + + } + + } + + ConsoleManager.logGroupChat(message); + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GlobalCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GlobalCommand.java new file mode 100644 index 00000000..31fce229 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GlobalCommand.java @@ -0,0 +1,114 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.*; + +import java.util.Optional; + +/** + * Global Command + *

Causes players to see messages sent from all servers in the global chat

+ * + * @author Oliver Martin (Revilo410) + */ +public class GlobalCommand extends Command { + + public GlobalCommand() { + super("global", ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("globalcommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.mode"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if ((sender instanceof Player)) { + + if (args.length < 1) { + + ChatModeManager.getInstance().setGlobal(((Player) sender).getUniqueId()); + + MessageManager.sendMessage(sender, "command_global_enabled_1"); + MessageManager.sendMessage(sender, "command_global_enabled_2"); + + } else { + + Player player = (Player) sender; + String message = MultiChatUtil.getMessageFromArgs(args); + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("global").getBoolean()) { + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_global").getList(String::valueOf).contains(player.getCurrentServer().get().getServerInfo().getName())) { + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + BungeeComm.sendMessage(player.getUsername(), player.getCurrentServer().get().getServerInfo()); + } + + if ((!MultiChat.frozen) || (player.hasPermission("multichat.chat.always"))) { + + if (ChatControl.isMuted(player.getUniqueId(), "global_chat")) { + MessageManager.sendMessage(player, "mute_cannot_send_message"); + return; + } + + DebugManager.log(player.getUsername() + "- about to check for spam"); + + if (ChatControl.handleSpam(player, message, "global_chat")) { + DebugManager.log(player.getUsername() + " - chat message being cancelled due to spam"); + return; + } + + Optional crm; + + crm = ChatControl.applyChatRules(message, "global_chat", player.getUsername()); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return; + } + + if (!player.hasPermission("multichat.chat.link")) { + message = ChatControl.replaceLinks(message); + } + + // If they had this channel hidden, then unhide it... + Channel global = Channel.getGlobalChannel(); + if (!global.isMember(player.getUniqueId())) { + global.removeMember(player.getUniqueId()); + MessageManager.sendSpecialMessage(player, "command_channel_show", "GLOBAL"); + } + + // Let server know players channel preference + BungeeComm.sendPlayerChannelMessage(player.getUsername(), + Channel.getChannel(player.getUniqueId()).getName(), + Channel.getChannel(player.getUniqueId()), + player.getCurrentServer().get().getServerInfo(), + (player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.color.simple")), + (player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.color.rgb"))); + + // Message passes through to spigot here + + // Send message directly to global chat... + + BungeeComm.sendPlayerCommandMessage("!SINGLE G MESSAGE!" + message, ((Player) sender).getUsername(), ((Player) sender).getCurrentServer().get().getServerInfo()); + + Events.hiddenStaff.remove(player.getUniqueId()); + + } else { + MessageManager.sendMessage(player, "freezechat_frozen"); + } + + } + } + + } + + } else { + MessageManager.sendMessage(sender, "command_global_only_players"); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GroupCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GroupCommand.java new file mode 100644 index 00000000..489cccc0 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GroupCommand.java @@ -0,0 +1,587 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.olivermartin410.plugins.TGroupChatInfo; +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.GroupManager; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; +import xyz.olivermartin.multichat.velocity.UUIDNameManager; + +import java.util.List; +import java.util.UUID; + +/** + * The Group Command + *

From here the player can manipulate group chats in every possible way

+ * + * @author Oliver Martin (Revilo410) + */ +public class GroupCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public GroupCommand() { + super("group", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.group"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if ((args.length < 1) || ((args.length == 1) && (args[0].equalsIgnoreCase("help")))) { + + GroupManager groupman = new GroupManager(); + groupman.displayHelp(1, sender); + + } else if (sender instanceof Player) { + Player player = (Player) sender; + + switch (args.length) { + case 1: + if (MultiChat.groupchats.containsKey(args[0].toLowerCase())) { + + TGroupChatInfo groupInfo = MultiChat.groupchats.get(args[0].toLowerCase()); + + if (groupInfo.existsMember(player.getUniqueId())) { + + String viewedchat = args[0].toLowerCase(); + MultiChat.viewedchats.remove(player.getUniqueId()); + MultiChat.viewedchats.put(player.getUniqueId(), viewedchat); + + MessageManager.sendSpecialMessage(sender, "command_group_selected", args[0].toUpperCase()); + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_not_a_member", args[0].toUpperCase()); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[0].toUpperCase()); + } + + break; + + case 2: + + if ((!args[0].equalsIgnoreCase("members")) && (!args[0].equalsIgnoreCase("list")) + && (!args[0].equalsIgnoreCase("spyall")) && (!args[0].equalsIgnoreCase("spy")) + && (!args[0].equalsIgnoreCase("help")) && (!args[0].equalsIgnoreCase("create")) + && (!args[0].equalsIgnoreCase("make")) && (!args[0].equalsIgnoreCase("join")) + && (!args[0].equalsIgnoreCase("quit")) && (!args[0].equalsIgnoreCase("leave")) + && (!args[0].equalsIgnoreCase("formal")) && (!args[0].equalsIgnoreCase("delete"))) { + + MessageManager.sendMessage(sender, "command_group_incorrect_usage"); + } + + if ((args[0].equalsIgnoreCase("list")) || (args[0].equalsIgnoreCase("members"))) { + + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + + if ((groupChatInfo.existsMember(player.getUniqueId())) || (sender.hasPermission("multichat.staff.spy"))) { + + List memberlist = groupChatInfo.getMembers(); + + MessageManager.sendSpecialMessage(sender, "command_group_member_list", groupChatInfo.getName().toUpperCase()); + + for (UUID member : memberlist) { + + if (!groupChatInfo.existsAdmin(member)) { + MessageManager.sendSpecialMessage(sender, "command_group_member_list_item", UUIDNameManager.getName(member)); + } else { + MessageManager.sendSpecialMessage(sender, "command_group_member_list_item_admin", UUIDNameManager.getName(member)); + } + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_not_a_member", args[1].toUpperCase()); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + + } + + if (args[0].equalsIgnoreCase("spy")) { + if (args[1].equalsIgnoreCase("all")) { + if (player.hasPermission("multichat.staff.spy")) { + + if (MultiChat.allspy.contains(player.getUniqueId())) { + + MultiChat.allspy.remove(player.getUniqueId()); + MessageManager.sendMessage(sender, "command_group_spy_all_disabled_1"); + MessageManager.sendMessage(sender, "command_group_spy_all_disabled_2"); + MessageManager.sendMessage(sender, "command_group_spy_all_disabled_3"); + + } else { + + MultiChat.allspy.add(player.getUniqueId()); + MessageManager.sendMessage(sender, "command_group_spy_all_enabled"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_spy_no_permission"); + } + + } else if (player.hasPermission("multichat.staff.spy")) { + + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + + if (!groupChatInfo.existsMember(player.getUniqueId())) { + + if (groupChatInfo.existsViewer(player.getUniqueId())) { + + groupChatInfo.delViewer(player.getUniqueId()); + MultiChat.groupchats.remove(groupChatInfo.getName().toLowerCase()); + MultiChat.groupchats.put(groupChatInfo.getName().toLowerCase(), groupChatInfo); + MessageManager.sendSpecialMessage(sender, "command_group_spy_off", groupChatInfo.getName().toUpperCase()); + + } else { + + groupChatInfo.addViewer(player.getUniqueId()); + MultiChat.groupchats.remove(groupChatInfo.getName().toLowerCase()); + MultiChat.groupchats.put(groupChatInfo.getName().toLowerCase(), groupChatInfo); + MessageManager.sendSpecialMessage(sender, "command_group_spy_on", groupChatInfo.getName().toUpperCase()); + + } + + } else { + MessageManager.sendMessage(sender, "command_group_spy_already_a_member"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_spy_does_not_exist"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_spy_no_permission"); + } + + } + + if (args[0].equalsIgnoreCase("help")) { + + GroupManager groupman = new GroupManager(); + if (args[1].equals("1")) { + groupman.displayHelp(1, sender); + } else { + groupman.displayHelp(2, sender); + } + + } + + if ((args[0].equalsIgnoreCase("create")) || (args[0].equalsIgnoreCase("make"))) { + if (player.hasPermission("multichat.group.create")) { + if (args[1].length() <= 20) { + if (!MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + GroupManager groupman = new GroupManager(); + + // Make the new group + groupman.createGroup(args[1], player.getUniqueId(), false, ""); + // Select the new group for the player + groupman.setViewedChat(player.getUniqueId(), args[1]); + // Announce join to group members + MessageManager.sendSpecialMessage(sender, "command_group_created", args[1].toUpperCase()); + + groupman.announceJoinGroup(player.getUsername(), args[1]); + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_already_exists", args[1].toUpperCase()); + } + + } else { + MessageManager.sendMessage(sender, "command_group_max_length"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_create_no_permission"); + } + } + + if (args[0].equalsIgnoreCase("join")) { + + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + GroupManager groupman = new GroupManager(); + + //Run the join group routine + if (groupman.joinGroup(args[1], player, "")) { + + //If the join is successful, set their viewed chat + groupman.setViewedChat(player.getUniqueId(), args[1]); + MessageManager.sendSpecialMessage(sender, "command_group_joined", args[1].toUpperCase()); + //Announce their join + groupman.announceJoinGroup(player.getUsername(), args[1]); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + if ((args[0].equalsIgnoreCase("quit")) || (args[0].equalsIgnoreCase("leave"))) { + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + GroupManager groupman = new GroupManager(); + groupman.quitGroup(args[1].toLowerCase(), player.getUniqueId(), player); + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + if (args[0].equalsIgnoreCase("formal")) { + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + if (!groupChatInfo.getFormal()) { + if (groupChatInfo.getAdmins().contains(player.getUniqueId())) { + groupChatInfo.setFormal(true); + MultiChat.groupchats.remove(groupChatInfo.getName()); + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_formal"), "&lINFO", groupChatInfo); + } else { + MessageManager.sendMessage(sender, "command_group_formal_not_owner"); + } + } else { + MessageManager.sendSpecialMessage(sender, "command_group_formal_already_formal", args[1].toUpperCase()); + } + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + if (args[0].equalsIgnoreCase("delete")) { + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + if (groupChatInfo.getAdmins().contains(player.getUniqueId())) { + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + + if ((MultiChat.viewedchats.get(onlineplayer.getUniqueId()) != null) && + (MultiChat.viewedchats.get(onlineplayer.getUniqueId()).equalsIgnoreCase(groupChatInfo.getName()))) { + + MultiChat.viewedchats.remove(onlineplayer.getUniqueId()); + MultiChat.viewedchats.put(onlineplayer.getUniqueId(), null); + + } + } + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_deleted"), "&lINFO", groupChatInfo); + GCCommand.sendMessage(MessageManager.getMessage("groups_info_goodbye"), "&lINFO", groupChatInfo); + + MultiChat.groupchats.remove(groupChatInfo.getName().toLowerCase()); + } else { + MessageManager.sendMessage(sender, "command_group_formal_not_admin"); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + break; + + case 3: + + if ((!args[0].equalsIgnoreCase("create")) && (!args[0].equalsIgnoreCase("make")) + && (!args[0].equalsIgnoreCase("join")) && (!args[0].equalsIgnoreCase("transfer")) + && (!args[0].equalsIgnoreCase("admin")) && (!args[0].equalsIgnoreCase("addadmin")) + && (!args[0].equalsIgnoreCase("removeadmin")) && (!args[0].equalsIgnoreCase("ban"))) { + + MessageManager.sendMessage(sender, "command_group_incorrect_usage"); + + } + + if ((args[0].equalsIgnoreCase("create")) || (args[0].equalsIgnoreCase("make"))) { + if (player.hasPermission("multichat.group.create")) { + if ((args[1].length() <= 20) && (args[2].length() <= 20)) { + if (!MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + GroupManager groupman = new GroupManager(); + + //Make the new group + groupman.createGroup(args[1], player.getUniqueId(), true, args[2]); + //Select the new group for the player + groupman.setViewedChat(player.getUniqueId(), args[1]); + //Announce join to group members + groupman.announceJoinGroup(player.getUsername(), args[1]); + + MessageManager.sendSpecialMessage(sender, "command_group_created", args[1].toUpperCase()); + } else { + MessageManager.sendSpecialMessage(sender, "command_group_already_exists", args[1].toUpperCase()); + } + + } else { + MessageManager.sendMessage(sender, "command_group_max_length_password"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_create_no_permission"); + } + } + + if (args[0].equalsIgnoreCase("join")) { + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + GroupManager groupman = new GroupManager(); + //Run the join group routine + if (groupman.joinGroup(args[1], player, args[2])) { + //If the join is successful, set their viewed chat + groupman.setViewedChat(player.getUniqueId(), args[1]); + MessageManager.sendSpecialMessage(sender, "command_group_joined", args[1].toUpperCase()); + //Announce their join + groupman.announceJoinGroup(player.getUsername(), args[1]); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + if (args[0].equalsIgnoreCase("transfer")) { + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + if (MultiChat.getInstance().getServer().getPlayer(args[2].toLowerCase()).isPresent()) { + + Player newplayer = MultiChat.getInstance().getServer().getPlayer(args[2].toLowerCase()).get(); + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + + if (!groupChatInfo.getFormal()) { + + if (groupChatInfo.existsAdmin(player.getUniqueId())) { + + if (groupChatInfo.existsMember(newplayer.getUniqueId())) { + + groupChatInfo.addAdmin(newplayer.getUniqueId()); + groupChatInfo.delAdmin(player.getUniqueId()); + + MultiChat.groupchats.remove(groupChatInfo.getName()); + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_transfer") + newplayer.getUsername(), "&lINFO", groupChatInfo); + + } else { + MessageManager.sendMessage(sender, "command_group_transfer_not_member"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_transfer_not_owner"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_transfer_not_informal"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_player_not_online"); + } + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + if ((args[0].equalsIgnoreCase("admin")) || (args[0].equalsIgnoreCase("addadmin")) || (args[0].equalsIgnoreCase("removeadmin"))) { + + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + if (MultiChat.getInstance().getServer().getPlayer(args[2].toLowerCase()).isPresent()) { + + Player newplayer = MultiChat.getInstance().getServer().getPlayer(args[2].toLowerCase()).orElse(null); + + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + + if (groupChatInfo.getFormal()) { + + if (groupChatInfo.existsAdmin(player.getUniqueId())) { + + if (groupChatInfo.existsMember(newplayer.getUniqueId())) { + + if (!groupChatInfo.existsAdmin(newplayer.getUniqueId())) { + + groupChatInfo.addAdmin(newplayer.getUniqueId()); + + MultiChat.groupchats.remove(groupChatInfo.getName()); + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_promoted") + newplayer.getUsername(), "&lINFO", groupChatInfo); + + } else if (newplayer.getUniqueId().equals(player.getUniqueId())) { + + if (groupChatInfo.getAdmins().size() > 1) { + + groupChatInfo.delAdmin(player.getUniqueId()); + + MultiChat.groupchats.remove(groupChatInfo.getName()); + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_step_down"), "&lINFO", groupChatInfo); + + } else { + MessageManager.sendMessage(sender, "command_group_formal_only_admin"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_formal_cannot_demote"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_transfer_not_member"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_formal_not_admin"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_not_formal"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_player_not_online"); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + + } + + if (args[0].equalsIgnoreCase("ban")) { + + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + if (MultiChat.getInstance().getServer().getPlayer(args[2].toLowerCase()).isPresent()) { + + Player newPlayer = MultiChat.getInstance().getServer().getPlayer(args[2].toLowerCase()).orElse(null); + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + + if (groupChatInfo.getFormal()) { + + if (groupChatInfo.existsAdmin(player.getUniqueId())) { + + if (!groupChatInfo.existsAdmin(newPlayer.getUniqueId())) { + + if (!groupChatInfo.existsBanned(newPlayer.getUniqueId())) { + + groupChatInfo.addBanned(newPlayer.getUniqueId()); + + if (groupChatInfo.existsMember(newPlayer.getUniqueId())) { + + groupChatInfo.delMember(newPlayer.getUniqueId()); + groupChatInfo.delViewer(newPlayer.getUniqueId()); + + MultiChat.viewedchats.remove(newPlayer.getUniqueId()); + MultiChat.viewedchats.put(newPlayer.getUniqueId(), null); + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_kick") + newPlayer.getUsername(), "&lINFO", groupChatInfo); + } + + MultiChat.groupchats.remove(groupChatInfo.getName()); + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_ban") + newPlayer.getUsername(), "&lINFO", groupChatInfo); + + MessageManager.sendSpecialMessage(newPlayer, "command_group_banned", groupChatInfo.getName()); + + + } else { + + groupChatInfo.delBanned(newPlayer.getUniqueId()); + + MultiChat.groupchats.remove(groupChatInfo.getName()); + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + + GCCommand.sendMessage(player.getUsername() + MessageManager.getMessage("groups_info_unban") + newPlayer.getUsername(), "&lINFO", groupChatInfo); + + MessageManager.sendSpecialMessage(newPlayer, "command_group_unbanned", groupChatInfo.getName()); + } + + } else { + MessageManager.sendMessage(sender, "command_group_cannot_ban_admin"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_ban_not_admin"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_not_formal"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_player_not_online"); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + } + + break; + + case 4: + + if ((args[0].equalsIgnoreCase("color")) || (args[0].equalsIgnoreCase("colour"))) { + + if (MultiChat.groupchats.containsKey(args[1].toLowerCase())) { + + TGroupChatInfo groupChatInfo = MultiChat.groupchats.get(args[1].toLowerCase()); + + if (((groupChatInfo.existsMember(player.getUniqueId())) + && (!groupChatInfo.getFormal())) || (groupChatInfo.existsAdmin(player.getUniqueId()))) { + + args[2] = args[2].toLowerCase(); + args[3] = args[3].toLowerCase(); + + if ((args[2].equals("a")) || (args[2].equals("b")) || (args[2].equals("c")) || (args[2].equals("d")) + || (args[2].equals("e")) || (args[2].equals("f")) || (args[2].equals("0")) || (args[2].equals("1")) + || (args[2].equals("2")) || (args[2].equals("3")) || (args[2].equals("4")) || (args[2].equals("5")) + || (args[2].equals("6")) || (args[2].equals("7")) || (args[2].equals("8")) || (args[2].equals("9"))) { + + if ((args[3].equals("a")) || (args[3].equals("b")) || (args[3].equals("c")) || (args[3].equals("d")) + || (args[3].equals("e")) || (args[3].equals("f")) || (args[3].equals("0")) || (args[3].equals("1")) + || (args[3].equals("2")) || (args[3].equals("3")) || (args[3].equals("4")) || (args[3].equals("5")) + || (args[3].equals("6")) || (args[3].equals("7")) || (args[3].equals("8")) || (args[3].equals("9"))) { + + MultiChat.groupchats.remove(groupChatInfo.getName()); + + groupChatInfo.setChatColor(args[2].charAt(0)); + groupChatInfo.setNameColor(args[3].charAt(0)); + + MultiChat.groupchats.put(groupChatInfo.getName(), groupChatInfo); + + GCCommand.sendMessage(MessageManager.getMessage("groups_info_colors") + player.getUsername(), "&lINFO", groupChatInfo); + + } else { + MessageManager.sendMessage(sender, "command_group_color_invalid"); + MessageManager.sendMessage(sender, "command_group_color_usage"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_color_invalid"); + MessageManager.sendMessage(sender, "command_group_color_usage"); + } + + } else { + MessageManager.sendMessage(sender, "command_group_formal_not_admin"); + } + + } else { + MessageManager.sendSpecialMessage(sender, "command_group_does_not_exist", args[1].toUpperCase()); + } + + } else { + MessageManager.sendMessage(sender, "command_group_incorrect_usage"); + } + + break; + + } + + } else { + MessageManager.sendMessage(sender, "command_group_only_players"); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GroupListCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GroupListCommand.java new file mode 100644 index 00000000..819dbaa8 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/GroupListCommand.java @@ -0,0 +1,34 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +/** + * Group List Command + *

Displays a list of all current group chats on the server

+ * + * @author Oliver Martin (Revilo410) + */ +public class GroupListCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public GroupListCommand() { + super("groups", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.listgroups"); + } + + public void execute(Invocation invocation) { + var sender = invocation.source(); + + MessageManager.sendMessage(sender, "command_grouplist_list"); + + for (String groupname : MultiChat.groupchats.keySet()) { + MessageManager.sendSpecialMessage(sender, "command_grouplist_list_item", groupname); + } + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/HelpMeCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/HelpMeCommand.java new file mode 100644 index 00000000..90d93c90 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/HelpMeCommand.java @@ -0,0 +1,88 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.*; + +import java.util.Optional; + +/** + * 'Help Me' Command + *

Allows players to request help from all online staff members

+ * + * @author Oliver Martin (Revilo410) + */ +public class HelpMeCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public HelpMeCommand() { + super("helpme", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.helpme"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (sender instanceof Player) { + Player player = (Player) sender; + + if (args.length < 1) { + + MessageManager.sendMessage(sender, "command_helpme_desc"); + MessageManager.sendMessage(sender, "command_helpme_usage"); + + } else { + + String message = MultiChatUtil.getMessageFromArgs(args); + + if (sendMessage(player.getUsername() + ": " + message, player.getUsername())) { + MessageManager.sendMessage(sender, "command_helpme_sent"); + } + + } + + } else { + MessageManager.sendMessage(sender, "command_helpme_only_players"); + } + } + + public static boolean sendMessage(String message, String username) { + + Optional crm; + + Player potentialPlayer = MultiChat.getInstance().getServer().getPlayer(username).orElse(null); + if (potentialPlayer != null) { + if (ChatControl.isMuted(potentialPlayer.getUniqueId(), "helpme")) { + MessageManager.sendMessage(potentialPlayer, "mute_cannot_send_message"); + return false; + } + + if (ChatControl.handleSpam(potentialPlayer, message, "helpme")) { + return false; + } + } + + crm = ChatControl.applyChatRules(message, "helpme", username); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return false; + } + + for (Player onlineplayer : MultiChat.getInstance().getServer().getAllPlayers()) { + if (onlineplayer.hasPermission("multichat.staff")) { + MessageManager.sendSpecialMessage(onlineplayer, "command_helpme_format", message); + } + } + + ConsoleManager.logHelpMe(message); + + return true; + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/IgnoreCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/IgnoreCommand.java new file mode 100644 index 00000000..6fb7c982 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/IgnoreCommand.java @@ -0,0 +1,69 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.*; + +public class IgnoreCommand extends Command { + + public IgnoreCommand() { + super("ignore", ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getNode("ignorecommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.ignore"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length != 1) { + MessageManager.sendMessage(sender, "ignore_usage"); + } else { + + if (sender instanceof Player) { + Player player = (Player) sender; + + String username = args[0]; + + Player target = MultiChat.getInstance().getServer().getPlayer(username).orElse(null); + + if (target != null) { + + if (target.getUsername().equals(player.getUsername())) { + MessageManager.sendMessage(player, "ignore_cannot_ignore_yourself"); + return; + } + + if (target.hasPermission("multichat.ignore.bypass")) { + MessageManager.sendMessage(player, "ignore_bypass"); + return; + } + + if (!ChatControl.ignoresAnywhere(target.getUniqueId(), (player).getUniqueId())) { + ChatControl.ignore(player.getUniqueId(), target.getUniqueId()); + MessageManager.sendSpecialMessage(player, "ignore_ignored", target.getUsername()); + } else { + ChatControl.unignore(player.getUniqueId(), target.getUniqueId()); + MessageManager.sendSpecialMessage(player, "ignore_unignored", target.getUsername()); + } + + BungeeComm.sendIgnoreMap(player.getCurrentServer().get().getServerInfo()); + + } else { + + MessageManager.sendMessage(sender, "ignore_player_not_found"); + + } + + } else { + + MessageManager.sendMessage(sender, "ignore_only_players"); + + } + + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/LocalCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/LocalCommand.java new file mode 100644 index 00000000..4930a2c6 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/LocalCommand.java @@ -0,0 +1,106 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.*; + +import java.util.Optional; + +/** + * Local Chat Command + *

Players can use this command to only see the chat sent from players on their current server

+ * + * @author Oliver Martin (Revilo410) + */ +public class LocalCommand extends Command { + + public LocalCommand() { + super("local", ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("localcommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.mode"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (sender instanceof Player) { + Player player = (Player) sender; + + if (args.length < 1) { + + ChatModeManager.getInstance().setLocal(player.getUniqueId()); + + MessageManager.sendMessage(sender, "command_local_enabled_1"); + MessageManager.sendMessage(sender, "command_local_enabled_2"); + + } else { + + String message = MultiChatUtil.getMessageFromArgs(args); + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + BungeeComm.sendMessage(player.getUsername(), player.getCurrentServer().get().getServerInfo()); + } + + if ((!MultiChat.frozen) || (player.hasPermission("multichat.chat.always"))) { + + if (ChatControl.isMuted(player.getUniqueId(), "global_chat")) { + MessageManager.sendMessage(player, "mute_cannot_send_message"); + return; + } + + DebugManager.log(player.getUsername() + "- about to check for spam"); + + if (ChatControl.handleSpam(player, message, "global_chat")) { + DebugManager.log(player.getUsername() + " - chat message being cancelled due to spam"); + return; + } + + Optional crm; + + crm = ChatControl.applyChatRules(message, "global_chat", player.getUsername()); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return; + } + + if (!player.hasPermission("multichat.chat.link")) { + message = ChatControl.replaceLinks(message); + } + + // If they had this channel hidden, then unhide it... + Channel local = Channel.getLocalChannel(); + if (!local.isMember(player.getUniqueId())) { + local.removeMember(player.getUniqueId()); + MessageManager.sendSpecialMessage(player, "command_channel_show", "LOCAL"); + } + + // Let server know players channel preference + BungeeComm.sendPlayerChannelMessage(player.getUsername(), + Channel.getChannel(player.getUniqueId()).getName(), + Channel.getChannel(player.getUniqueId()), + player.getCurrentServer().get().getServerInfo(), + (player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.color.simple")), + (player.hasPermission("multichat.chat.color") || player.hasPermission("multichat.chat.color.rgb"))); + + // Message passes through to spigot here + // Send message directly to local chat... + + BungeeComm.sendPlayerCommandMessage("!SINGLE L MESSAGE!" + message, player.getUsername(), player.getCurrentServer().get().getServerInfo()); + + Events.hiddenStaff.remove(player.getUniqueId()); + + } else { + MessageManager.sendMessage(player, "freezechat_frozen"); + } + + } + + } else { + MessageManager.sendMessage(sender, "command_local_only_players"); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MCCCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MCCCommand.java new file mode 100644 index 00000000..44bb2d3d --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MCCCommand.java @@ -0,0 +1,79 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.olivermartin410.plugins.TChatInfo; +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +/** + * Mod-Chat Colour Command + *

Allows staff members to individually set the colours that they see the mod-chat displayed in

+ * + * @author Oliver Martin (Revilo410) + */ +public class MCCCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public MCCCommand() { + super("mcc", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.mod"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length != 2) { + + if ((sender instanceof Player)) { + MessageManager.sendMessage(sender, "command_mcc_usage"); + } else { + MessageManager.sendMessage(sender, "command_mcc_only_players"); + } + + } else if ((sender instanceof Player)) { + Player player = (Player) sender; + + TChatInfo chatinfo = new TChatInfo(); + + args[0] = args[0].toLowerCase(); + args[1] = args[1].toLowerCase(); + + if ((args[0].equals("a")) || (args[0].equals("b")) || (args[0].equals("c")) || (args[0].equals("d")) + || (args[0].equals("e")) || (args[0].equals("f")) || (args[0].equals("0")) || (args[0].equals("1")) + || (args[0].equals("2")) || (args[0].equals("3")) || (args[0].equals("4")) || (args[0].equals("5")) + || (args[0].equals("6")) || (args[0].equals("7")) || (args[0].equals("8")) || (args[0].equals("9"))) { + + if ((args[1].equals("a")) || (args[1].equals("b")) || (args[1].equals("c")) || (args[1].equals("d")) + || (args[1].equals("e")) || (args[1].equals("f")) || (args[1].equals("0")) || (args[1].equals("1")) + || (args[1].equals("2")) || (args[1].equals("3")) || (args[1].equals("4")) || (args[1].equals("5")) + || (args[1].equals("6")) || (args[1].equals("7")) || (args[1].equals("8")) || (args[1].equals("9"))) { + + MultiChat.modchatpreferences.remove(player.getUniqueId()); + + chatinfo.setChatColor(args[0].charAt(0)); + chatinfo.setNameColor(args[1].charAt(0)); + + MultiChat.modchatpreferences.put(player.getUniqueId(), chatinfo); + + MessageManager.sendMessage(sender, "command_mcc_updated"); + + } else { + MessageManager.sendMessage(sender, "command_mcc_invalid"); + MessageManager.sendMessage(sender, "command_mcc_invalid_usage"); + } + + } else { + MessageManager.sendMessage(sender, "command_mcc_invalid"); + MessageManager.sendMessage(sender, "command_mcc_invalid_usage"); + } + + } else { + MessageManager.sendMessage(sender, "command_mcc_only_players"); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MCCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MCCommand.java new file mode 100644 index 00000000..161218fe --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MCCommand.java @@ -0,0 +1,66 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.Events; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.StaffChatManager; +import xyz.olivermartin.multichat.velocity.MultiChatUtil; + +/** + * Mod-Chat Commands + *

Allows staff members to send mod-chat messages or toggle the chat

+ * + * @author Oliver Martin (Revilo410) + */ +public class MCCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public MCCommand() { + super("mc", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.mod"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + boolean toggleresult; + + if (args.length < 1) { + + if ((sender instanceof Player)) { + Player player = (Player) sender; + + toggleresult = Events.toggleMC(player.getUniqueId()); + + if (toggleresult) { + MessageManager.sendMessage(sender, "command_mc_toggle_on"); + } else { + MessageManager.sendMessage(sender, "command_mc_toggle_off"); + } + + } else { + MessageManager.sendMessage(sender, "command_mc_only_players"); + } + + } else if ((sender instanceof Player)) { + Player player = (Player) sender; + + String message = MultiChatUtil.getMessageFromArgs(args); + + StaffChatManager chatman = new StaffChatManager(); + chatman.sendModMessage(player.getUsername(), player.getUsername(), player.getCurrentServer().get().getServerInfo().getName(), message); + + } else { + + String message = MultiChatUtil.getMessageFromArgs(args); + + StaffChatManager chatman = new StaffChatManager(); + chatman.sendModMessage("CONSOLE", "CONSOLE", "#", message); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MsgCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MsgCommand.java new file mode 100644 index 00000000..f4bfbb75 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MsgCommand.java @@ -0,0 +1,237 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.google.common.collect.ImmutableList; +import com.velocitypowered.api.proxy.Player; +import ninja.leaping.configurate.ConfigurationNode; +import xyz.olivermartin.multichat.velocity.*; + +import java.util.*; + +/** + * Message Command + *

Allows players to send private messages to each other

+ * + * @author Oliver Martin (Revilo410) + */ +public class MsgCommand extends Command { + + public MsgCommand() { + super("msg", ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("msgcommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.msg"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + // Show usage (not enough args) + + MessageManager.sendMessage(sender, "command_msg_usage"); + MessageManager.sendMessage(sender, "command_msg_usage_toggle"); + + } else { + + boolean toggleresult; + + if (args.length == 1) { + + // 1 arg --> toggle + Player target = MultiChat.getInstance().getServer().getPlayer(args[0]).orElse(null); + + if (target != null) { + + + if ((sender instanceof Player)) { + Player player = (Player) sender; + + toggleresult = Events.togglePM(player.getUniqueId(), target.getUniqueId()); + + if (toggleresult) { + + ConfigurationNode config = ConfigManager.getInstance().getHandler("config.yml").getConfig(); + + if (config.getChildrenMap().containsKey("toggle_pm") && !config.getNode("toggle_pm").getBoolean()) { + + MessageManager.sendMessage(sender, "command_msg_no_toggle"); + + } else { + MessageManager.sendSpecialMessage(sender, "command_msg_toggle_on", target.getUsername()); + } + + } else { + MessageManager.sendMessage(sender, "command_msg_toggle_off"); + } + + } else { + MessageManager.sendMessage(sender, "command_msg_only_players"); + } + + } else { + + Player player = (Player) sender; + + if (Events.PMToggle.containsKey(player.getUniqueId())) { + Events.PMToggle.remove(player.getUniqueId()); + MessageManager.sendMessage(sender, "command_msg_toggle_off"); + } else { + MessageManager.sendMessage(sender, "command_msg_not_online"); + } + + } + + } else if ((sender instanceof Player)) { + + // >1 arg and the sender is a PLAYER + + String message = MultiChatUtil.getMessageFromArgs(args, 1); + + Optional crm; + + if (ChatControl.isMuted(((Player) sender).getUniqueId(), "private_messages")) { + MessageManager.sendMessage(sender, "mute_cannot_send_message"); + return; + } + + if (ChatControl.handleSpam(((Player) sender), message, "private_messages")) { + return; + } + + crm = ChatControl.applyChatRules(message, "private_messages", ((Player) sender).getUsername()); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return; + } + + if (MultiChat.getInstance().getServer().getPlayer(args[0]).orElse(null) != null) { + + Player target = MultiChat.getInstance().getServer().getPlayer(args[0]).orElse(null); + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + + BungeeComm.sendMessage(((Player) sender).getUsername(), ((Player) sender).getCurrentServer().get().getServerInfo()); + BungeeComm.sendMessage(target.getUsername(), target.getCurrentServer().get().getServerInfo()); + + } + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(((Player) sender).getCurrentServer().get().getServerInfo().getName())) { + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(target.getCurrentServer().get().getServerInfo().getName())) { + + if (ChatControl.ignores(((Player) sender).getUniqueId(), target.getUniqueId(), "private_messages")) { + ChatControl.sendIgnoreNotifications(target, sender, "private_messages"); + return; + } + + PrivateMessageManager.getInstance().sendMessage(message, (Player) sender, target); + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_target"); + } + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_sender"); + } + + } else if (args[0].equalsIgnoreCase("console")) { + + // New console target stuff here! + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + + BungeeComm.sendMessage(((Player) sender).getUsername(), ((Player) sender).getCurrentServer().get().getServerInfo()); + + } + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(((Player) sender).getCurrentServer().get().getServerInfo().getName())) { + + PrivateMessageManager.getInstance().sendMessageConsoleTarget(message, (Player) sender); + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_sender"); + } + + // End of console target stuff + + } else { + MessageManager.sendMessage(sender, "command_msg_not_online"); + } + + } else { + + // >1 arg and the sender is the CONSOLE + + String message = MultiChatUtil.getMessageFromArgs(args, 1); + + if (MultiChat.getInstance().getServer().getPlayer(args[0]).isPresent()) { + + Player target = MultiChat.getInstance().getServer().getPlayer(args[0]).get(); + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + + BungeeComm.sendMessage(target.getUsername(), target.getCurrentServer().get().getServerInfo()); + + } + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(target.getCurrentServer().get().getServerInfo().getName())) { + + PrivateMessageManager.getInstance().sendMessageConsoleSender(message, target); + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_target"); + } + + } else { + MessageManager.sendMessage(sender, "command_msg_not_online"); + } + + } + } + } + + @Override + public List suggest(Invocation invoker) { + + List matches = new ArrayList<>(); + + String[] args = invoker.arguments(); + + if (invoker.source() instanceof Player) { + Player sourcePlayer = (Player) invoker.source(); + + if (args.length == 1) { + String search = args[0].toLowerCase(); + + for (Player player : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (!player.getUsername().equalsIgnoreCase(sourcePlayer.getUsername()) && player.getUsername().toLowerCase().startsWith(search) ){ + + if (!xyz.olivermartin.multichat.velocity.Events.hiddenStaff.contains(player.getUniqueId())) { + matches.add(player.getUsername()); + } + } + } + } else if (args.length == 0) { + + for (Player player : MultiChat.getInstance().getServer().getAllPlayers()) { + + if (!player.getUsername().equalsIgnoreCase(sourcePlayer.getUsername())) { + matches.add(player.getUsername()); + } + } + } + } + + if (matches != null && matches.size() > 0) { + return matches; + } else { + return ImmutableList.of(); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatBypassCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatBypassCommand.java new file mode 100644 index 00000000..d17c26db --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatBypassCommand.java @@ -0,0 +1,50 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.ConfigManager; +import xyz.olivermartin.multichat.velocity.Events; +import xyz.olivermartin.multichat.velocity.MessageManager; + +public class MultiChatBypassCommand extends Command { + + public MultiChatBypassCommand() { + super("multichatbypass", ConfigManager.getInstance().getHandler("config.yml").getConfig().getChildrenMap().containsKey("multichatbypasscommand") ? ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("multichatbypasscommand").getList(String::valueOf).toArray(new String[0]) : new String[0]); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.bypass"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (!(sender instanceof Player)) { + return; + } + + Player player = (Player) sender; + + if (args.length >= 1) { + + MessageManager.sendMessage(sender, "command_multichatbypass_usage"); + + } else { + + if (Events.mcbPlayers.contains(player.getUniqueId())) { + + Events.mcbPlayers.remove(player.getUniqueId()); + MessageManager.sendMessage(sender, "command_multichatbypass_disabled"); + + } else { + + Events.mcbPlayers.add(player.getUniqueId()); + MessageManager.sendMessage(sender, "command_multichatbypass_enabled"); + + } + + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatCommand.java new file mode 100644 index 00000000..900ca107 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatCommand.java @@ -0,0 +1,155 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import xyz.olivermartin.multichat.velocity.*; + +/** + * MultiChat (Admin) Command + *

Used to view details about the plugin and display help information

+ * + * @author Oliver Martin (Revilo410) + */ +public class MultiChatCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public MultiChatCommand() { + super("multichat", aliases); + } + + private void displayHelp(CommandSource sender, int page) { + + switch (page) { + case 1: MessageManager.sendMessage(sender, "command_multichat_help_1"); + case 2: MessageManager.sendMessage(sender, "command_multichat_help_2"); + default: MessageManager.sendMessage(sender, "command_multichat_help_3"); + } + + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.admin"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize("&2Multi&aChat &bVersion " + MultiChat.LATEST_VERSION)); + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize("&bBy Revilo410")); + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize("&bOriginally created for &3Oasis-MC.US")); + sender.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize("&bUse &3/multichat help &bfor all commands")); + + } else { + + if (args.length == 1) { + + if (args[0].equalsIgnoreCase("help")) { + + displayHelp(sender, 1); + + } else if (args[0].equalsIgnoreCase("debug")) { + + DebugManager.toggle(); + DebugManager.log("Debug mode toggled"); + + } else if (args[0].equalsIgnoreCase("save")) { + + MessageManager.sendMessage(sender, "command_multichat_save_prepare"); + + MultiChat.saveChatInfo(); + MultiChat.saveGroupChatInfo(); + MultiChat.saveGroupSpyInfo(); + MultiChat.saveGlobalChatInfo(); + MultiChat.saveSocialSpyInfo(); + MultiChat.saveAnnouncements(); + MultiChat.saveBulletins(); + MultiChat.saveCasts(); + MultiChat.saveMute(); + MultiChat.saveIgnore(); + UUIDNameManager.saveUUIDS(); + + MessageManager.sendMessage(sender, "command_multichat_save_completed"); + + } else if (args[0].equalsIgnoreCase("reload")) { + + MessageManager.sendMessage(sender, "command_multichat_reload_prepare"); + + // Unregister commands + MultiChat.getInstance().unregisterCommands(ConfigManager.getInstance().getHandler("config.yml").getConfig(), ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig()); + + ConfigManager.getInstance().getHandler("config.yml").startupConfig(); + MultiChat.configversion = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("version").getString(); + + ConfigManager.getInstance().getHandler("joinmessages.yml").startupConfig(); + ConfigManager.getInstance().getHandler("messages.yml").startupConfig(); + ConfigManager.getInstance().getHandler("chatcontrol.yml").startupConfig(); + + ConfigManager.getInstance().getHandler("messages_fr.yml").startupConfig(); + ConfigManager.getInstance().getHandler("joinmessages_fr.yml").startupConfig(); + ConfigManager.getInstance().getHandler("config_fr.yml").startupConfig(); + ConfigManager.getInstance().getHandler("chatcontrol_fr.yml").startupConfig(); + + // Reload, and re-register commands + CommandManager.reload(); + MultiChat.getInstance().registerCommands(ConfigManager.getInstance().getHandler("config.yml").getConfig(), ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig()); + + ChatControl.reload(); + + System.out.println("VERSION LOADED: " + MultiChat.configversion); + + // Set up chat control stuff + if (ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getChildrenMap().containsKey("link_control")) { + ChatControl.controlLinks = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getNode("link_control").getBoolean(); + ChatControl.linkMessage = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getNode("link_removal_message").getString(); + if (ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getChildrenMap().containsKey("link_regex")) { + ChatControl.linkRegex = ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getNode("link_regex").getString(); + } + } + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getChildrenMap().containsKey("privacy_settings")) { + MultiChat.logPMs = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("privacy_settings").getNode("log_pms").getBoolean(); + MultiChat.logStaffChat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("privacy_settings").getNode("log_staffchat").getBoolean(); + MultiChat.logGroupChat = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("privacy_settings").getNode("log_groupchat").getBoolean(); + } + + // Legacy servers for RGB approximation + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getChildrenMap().containsKey("legacy_servers")) { + MultiChat.legacyServers = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("legacy_servers").getList(String::valueOf); + } + + // Set default channel + MultiChat.defaultChannel = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("default_channel").getString(); + MultiChat.forceChannelOnJoin = ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("force_channel_on_join").getBoolean(); + + Channel.getGlobalChannel().setFormat(ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("globalformat").getString()); + Channel.getGlobalChannel().clearServers(); + + for (String server : ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_global").getList(String::valueOf)) { + Channel.getGlobalChannel().addServer(server); + } + + MessageManager.sendMessage(sender, "command_multichat_reload_completed"); + } + } + + if (args.length == 2) { + + if (args[0].equalsIgnoreCase("help")) { + + if (args[1].equalsIgnoreCase("1")) { + displayHelp(sender, 1); + } else if (args[1].equalsIgnoreCase("2")) { + displayHelp(sender, 2); + } else { + displayHelp(sender, 3); + } + + } + } + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatExecuteCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatExecuteCommand.java new file mode 100644 index 00000000..d9c903a6 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MultiChatExecuteCommand.java @@ -0,0 +1,106 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import xyz.olivermartin.multichat.velocity.BungeeComm; +import xyz.olivermartin.multichat.velocity.ConfigManager; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +import java.util.regex.PatternSyntaxException; + +/** + * Execute Command + *

Used to execute commands remotely on Spigot servers

+ * + * @author Oliver Martin (Revilo410) + */ +public class MultiChatExecuteCommand extends Command { + + public MultiChatExecuteCommand() { + super("multichatexecute", ConfigManager.getInstance().getHandler("config.yml").getConfig().getChildrenMap().containsKey("multichatexecutecommand") ? ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("multichatexecutecommand").getList(String::valueOf).toArray(new String[0]) : new String[]{"mcexecute", "mce", "gexecute", "gexe", "gcommand"}); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.execute"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + MessageManager.sendMessage(sender, "command_execute_usage"); + + } else { + + String server = ".*"; + boolean playerFlag = false; + String player = ".*"; + + // Handle flags + int index = 0; + + while (index < args.length) { + + if (args[index].equalsIgnoreCase("-s")) { + if (index + 1 < args.length) { + server = args[index + 1]; + } + } else if (args[index].equalsIgnoreCase("-p")) { + if (index + 1 < args.length) { + playerFlag = true; + player = args[index + 1]; + } + } else { + break; + } + + index = index + 2; + + } + + + StringBuilder message = new StringBuilder(); + for (String arg : args) { + if (index > 0) { + index--; + } else { + message.append(arg).append(" "); + } + } + + message = new StringBuilder(message.toString().trim()); + + try { + + for (RegisteredServer ser : MultiChat.getInstance().getServer().getAllServers()) { + var s = ser.getServerInfo(); + if (s.getName().matches(server)) { + + if (playerFlag) { + for (Player p : MultiChat.getInstance().getServer().getAllPlayers()) { + if (p.getUsername().matches(player)) { + BungeeComm.sendPlayerCommandMessage(message.toString(), p.getUsername(), s); + } + } + } else { + BungeeComm.sendCommandMessage(message.toString(), s); + } + } + + } + + MessageManager.sendMessage(sender, "command_execute_sent"); + + } catch (PatternSyntaxException e) { + + MessageManager.sendMessage(sender, "command_execute_regex"); + + } + + } + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MuteCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MuteCommand.java new file mode 100644 index 00000000..ec1d0a0a --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/MuteCommand.java @@ -0,0 +1,62 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.ChatControl; +import xyz.olivermartin.multichat.velocity.ConfigManager; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +public class MuteCommand extends Command { + + public MuteCommand() { + super("multichatmute", ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getNode("mutecommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.mute"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (!ConfigManager.getInstance().getHandler("chatcontrol.yml").getConfig().getNode("mute").getBoolean()) return; + + if (args.length != 1) { + + MessageManager.sendMessage(sender, "mute_usage"); + + } else { + + String username = args[0]; + + Player target = MultiChat.getInstance().getServer().getPlayer(username).orElse(null); + + if (target != null) { + + if (target.hasPermission("multichat.mute.bypass")) { + MessageManager.sendMessage(sender, "mute_bypass"); + return; + } + + if (!ChatControl.isMutedAnywhere(target.getUniqueId())) { + ChatControl.mute(target.getUniqueId()); + MessageManager.sendMessage(sender, "mute_muted_staff"); + MessageManager.sendMessage(target, "mute_muted"); + } else { + ChatControl.unmute(target.getUniqueId()); + MessageManager.sendMessage(sender, "mute_unmuted_staff"); + MessageManager.sendMessage(target, "mute_unmuted"); + } + + } else { + + MessageManager.sendMessage(sender, "mute_player_not_found"); + + } + + } + + } + +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ReplyCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ReplyCommand.java new file mode 100644 index 00000000..3ce1837e --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/ReplyCommand.java @@ -0,0 +1,136 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.*; + +import java.util.Optional; +import java.util.UUID; + +/** + * Reply Command + *

Used to quickly reply to your last private message

+ * + * @author Oliver Martin (Revilo410) + */ +public class ReplyCommand extends Command { + + public ReplyCommand() { + super("r", ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("rcommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.chat.msg"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 1) { + + MessageManager.sendMessage(sender, "command_reply_usage"); + MessageManager.sendMessage(sender, "command_reply_desc"); + + } else if ((sender instanceof Player)) { + + String message = MultiChatUtil.getMessageFromArgs(args); + + Optional crm; + + if (ChatControl.isMuted(((Player) sender).getUniqueId(), "private_messages")) { + MessageManager.sendMessage(sender, "mute_cannot_send_message"); + return; + } + + if (ChatControl.handleSpam(((Player) sender), message, "private_messages")) { + return; + } + + crm = ChatControl.applyChatRules(message, "private_messages", ((Player) sender).getUsername()); + + if (crm.isPresent()) { + message = crm.get(); + } else { + return; + } + + if (MultiChat.lastmsg.containsKey(((Player) sender).getUniqueId())) { + + if (MultiChat.getInstance().getServer().getPlayer(MultiChat.lastmsg.get(((Player) sender).getUniqueId())).isPresent()) { + + Player target = MultiChat.getInstance().getServer().getPlayer(MultiChat.lastmsg.get(((Player) sender).getUniqueId())).orElse(null); + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(((Player) sender).getCurrentServer().get().getServerInfo().getName())) { + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(target.getCurrentServer().get().getServerInfo().getName())) { + + if (ChatControl.ignores(((Player) sender).getUniqueId(), target.getUniqueId(), "private_messages")) { + ChatControl.sendIgnoreNotifications(target, sender, "private_messages"); + return; + } + + PrivateMessageManager.getInstance().sendMessage(message, (Player) sender, target); + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_target"); + } + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_sender"); + } + + } else if (MultiChat.lastmsg.get(((Player) sender).getUniqueId()).equals(new UUID(0L, 0L))) { + + // Console target stuff + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(((Player) sender).getCurrentServer().get().getServerInfo().getName())) { + + PrivateMessageManager.getInstance().sendMessageConsoleTarget(message, (Player) sender); + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_sender"); + } + + // End console target stuff + + } else { + MessageManager.sendMessage(sender, "command_reply_no_one_to_reply_to"); + } + + } else { + MessageManager.sendMessage(sender, "command_reply_no_one_to_reply_to"); + } + + } else { + + // New console reply + + String message = MultiChatUtil.getMessageFromArgs(args); + + if (MultiChat.lastmsg.containsKey(new UUID(0L, 0L))) { + + if (MultiChat.getInstance().getServer().getPlayer(MultiChat.lastmsg.get((new UUID(0L, 0L)))).isPresent()) { + + Player target = MultiChat.getInstance().getServer().getPlayer(MultiChat.lastmsg.get((new UUID(0L, 0L)))).orElse(null); + + if (!ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("no_pm").getList(String::valueOf).contains(target.getCurrentServer().get().getServerInfo().getName())) { + + PrivateMessageManager.getInstance().sendMessageConsoleSender(message, target); + + } else { + MessageManager.sendMessage(sender, "command_msg_disabled_target"); + } + + } else { + MessageManager.sendMessage(sender, "command_reply_no_one_to_reply_to"); + } + + } else { + MessageManager.sendMessage(sender, "command_reply_no_one_to_reply_to"); + } + + // End new console stuff + + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/SocialSpyCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/SocialSpyCommand.java new file mode 100644 index 00000000..6e08593f --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/SocialSpyCommand.java @@ -0,0 +1,49 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.ConfigManager; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChat; + +/** + * SocialSpy Command + *

Allows staff members to view private messages sent by players

+ * + * @author Oliver Martin (Revilo410) + */ +public class SocialSpyCommand extends Command { + + public SocialSpyCommand() { + super("socialspy", ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("socialspycommand").getList(String::valueOf).toArray(new String[0])); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.spy"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if ((sender instanceof Player)) { + + if (args.length < 1) { + + if (MultiChat.socialspy.contains(((Player) sender).getUniqueId())) { + MultiChat.socialspy.remove(((Player) sender).getUniqueId()); + MessageManager.sendMessage(sender, "command_socialspy_disabled"); + } else { + MultiChat.socialspy.add(((Player) sender).getUniqueId()); + MessageManager.sendMessage(sender, "command_socialspy_enabled"); + } + + } else { + MessageManager.sendMessage(sender, "command_socialspy_usage"); + MessageManager.sendMessage(sender, "command_socialspy_desc"); + } + + } else { + MessageManager.sendMessage(sender, "command_socialspy_only_players"); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/StaffListCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/StaffListCommand.java new file mode 100644 index 00000000..93341bbf --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/StaffListCommand.java @@ -0,0 +1,79 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import xyz.olivermartin.multichat.velocity.*; + +/** + * Staff List Command + *

Allows the user to view a list of all online staff, sorted by their server

+ * + * @author Oliver Martin (Revilo410) + */ +public class StaffListCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public StaffListCommand() { + super("staff", aliases); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.staff.list"); + } + + public void execute(Invocation invocation) { + var sender = invocation.source(); + + String server; + boolean staff = false; + boolean onServer; + + MessageManager.sendMessage(sender, "command_stafflist_list"); + + DebugManager.log("[StaffList] Player: " + ((sender instanceof Player) ? ((Player) sender).getUsername() : "CONSOLE") + " is the command sender!"); + + for (RegisteredServer registeredServer : MultiChat.getInstance().getServer().getAllServers()) { + + server = registeredServer.getServerInfo().getName(); + + DebugManager.log("[StaffList] First Server: " + server); + + if (!registeredServer.getPlayersConnected().isEmpty()) { + + onServer = false; + + for (Player onlineplayer2 : MultiChat.getInstance().getServer().getAllPlayers()) { + + if ((onlineplayer2.hasPermission("multichat.staff"))) { + + DebugManager.log("[StaffList] Found a staff member: " + onlineplayer2.getUsername()); + + + if (onlineplayer2.getCurrentServer().get().getServerInfo().getName().equals(server)) { + + if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getNode("fetch_spigot_display_names").getBoolean()) { + BungeeComm.sendMessage(onlineplayer2.getUsername(), onlineplayer2.getCurrentServer().get().getServerInfo()); + } + + staff = true; + + if (!onServer) { + MessageManager.sendSpecialMessage(sender, "command_stafflist_list_server", server); + onServer = true; + } + + MessageManager.sendSpecialMessage(sender, "command_stafflist_list_item", onlineplayer2.getUsername()); + + } + + } + } + + } + } + + if (!staff) MessageManager.sendMessage(sender, "command_stafflist_no_staff"); + + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/UseCastCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/UseCastCommand.java new file mode 100644 index 00000000..c3a19fca --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/commands/UseCastCommand.java @@ -0,0 +1,50 @@ +package xyz.olivermartin.multichat.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import xyz.olivermartin.multichat.velocity.CastControl; +import xyz.olivermartin.multichat.velocity.Channel; +import xyz.olivermartin.multichat.velocity.MessageManager; +import xyz.olivermartin.multichat.velocity.MultiChatUtil; + +/** + * Use Cast Command + *

A command designed to allow you to use a cast from the console

+ * + * @author Oliver Martin (Revilo410) + */ +public class UseCastCommand extends Command { + + private static final String[] aliases = new String[]{}; + + public UseCastCommand() { + super("usecast", aliases); + } + + public void displayUsage(CommandSource sender) { + MessageManager.sendMessage(sender, "command_usecast_usage"); + sender.sendMessage(Component.text("/usecast ").color(NamedTextColor.AQUA)); + } + + public boolean hasPermission(Invocation invocation) { + return invocation.source().hasPermission("multichat.cast.admin"); + } + + public void execute(Invocation invocation) { + var args = invocation.arguments(); + var sender = invocation.source(); + + if (args.length < 2) { + displayUsage(sender); + return; + } + + if (CastControl.existsCast(args[0])) { + String message = MultiChatUtil.getMessageFromArgs(args, 1); + CastControl.sendCast(args[0], message, Channel.getGlobalChannel(), sender); + } else { + MessageManager.sendSpecialMessage(sender, "command_usecast_does_not_exist", args[0].toUpperCase()); + } + } +} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostBroadcastEvent.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostBroadcastEvent.java new file mode 100644 index 00000000..9204f7c7 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostBroadcastEvent.java @@ -0,0 +1,92 @@ +package xyz.olivermartin.multichat.velocity.events; + +import java.util.regex.Pattern; + +/** + * An event that triggers AFTER a broadcast message has been sent via MultiChat + * + * @author Oliver Martin (Revilo410) + */ +public class PostBroadcastEvent { + + private boolean cancelled; + private String message; // The actual message that was broadcast + private String type; // The type of broadcast + + /** + * Trigger a new PostBroadcastEvent + * + * @param type "cast", "display", "bulletin" or "announcement" depending on the type of broadcast + * @param message The message that was broadcast + */ + public PostBroadcastEvent(String type, String message) { + + cancelled = false; + this.message = message; + this.type = type; + + } + + /** + * @return "cast", "display", "bulletin" or "announcement" depending on the type of broadcast + */ + public String getType() { + return type; + } + + /** + * @return The message that was broadcast including format codes in the '&' notation + */ + public String getMessage() { + return message; + } + + /** + *

Allows you to change the message in this PostBroadcastEvent ONLY

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT BROADCASTS!

+ *

This is a POST broadcast event, meaning the broadcast has already happened by the time this event triggers.

+ */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return The message that was broadcast EXCLUDING any format codes in the '&' notation + */ + public String getRawMessage() { + return stripAllFormattingCodes(message); + } + + /** + *

Returns true if this post broadcast event has been cancelled

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT BROADCASTS!

+ *

This is a POST broadcast event, meaning the broadcast has already happened by the time this event triggers.

+ */ + public boolean isCancelled() { + return cancelled; + } + + /** + *

Allows you to cancel this PostBroadcastEvent

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT BROADCASTS!

+ *

This is a POST broadcast event, meaning the broadcast has already happened by the time this event triggers.

+ */ + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + // Remove all formatting codes from the text (&a, &l etc.) + private static String stripAllFormattingCodes(String input) { + + char COLOR_CHAR = '&'; + Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]"); + + if (input == null) { + return null; + } + + return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); + + } + +} \ No newline at end of file diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostGlobalChatEvent.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostGlobalChatEvent.java new file mode 100644 index 00000000..fe5017f0 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostGlobalChatEvent.java @@ -0,0 +1,244 @@ +package xyz.olivermartin.multichat.velocity.events; + +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.ChatModeManager; +import xyz.olivermartin.multichat.velocity.PlayerMeta; +import xyz.olivermartin.multichat.velocity.PlayerMetaManager; + +import java.util.Optional; +import java.util.regex.Pattern; + +/** + * An event that triggers AFTER a global chat message has been sent via MultiChat + * + * @author Oliver Martin (Revilo410) + */ +public class PostGlobalChatEvent { + + private boolean cancelled; + private String message; // The message that was sent in global chat + private final String format; // The global chat format that was used + private final Player sender; // The sender of the message + + /** + * Trigger a new PostGlobalChatEvent + * + * @param sender The sender of the message + * @param format The format used to send the message + * @param message The message that was sent + */ + public PostGlobalChatEvent(Player sender, String format, String message) { + + cancelled = false; + this.message = message; + this.sender = sender; + this.format = format; + + } + + /** + * @return The player who sent the message + */ + public Player getSender() { + return sender; + } + + /** + * @return The message that was sent including any format codes in the '&' notation + */ + public String getMessage() { + return message; + } + + /** + * @return The message that was sent EXCLUDING any format codes in the '&' notation + */ + public String getRawMessage() { + return stripAllFormattingCodes(getMessage()); + } + + /** + *

Allows you to change the message in this PostGlobalChatEvent ONLY

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT SENDS!

+ *

This is a POST global chat event, meaning the chat message has already happened by the time this event triggers.

+ */ + public void setMessage(String message) { + this.message = message; + } + + /** + * Returns the format that was used to send this message on the network + * (i.e. The bit that appears before the actual message) + *

+ * %NICK% -> Nickname + * %NAME% -> Name + * %DISPLAYNAME% -> DisplayName + * %PREFIX% -> Prefix + * %SUFFIX% -> Suffix + * %SERVER% -> Server + * %MODE% -> Chat Mode + * %M% -> Short Chat Mode + * + * @return The format MultiChat used to send this message + */ + public String getFormat() { + return format; + } + + /** + * @return The display name of the sender including any format codes in the '&' notation + */ + public String getSenderDisplayName() { + return sender.getUsername(); + } + + /** + * @return The display name of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderDisplayName() { + return stripAllFormattingCodes(getSenderDisplayName()); + } + + /** + * @return The prefix of the sender including any format codes in the '&' notation + */ + public String getSenderPrefix() { + Optional opm = PlayerMetaManager.getInstance().getPlayer(sender.getUniqueId()); + if (opm.isPresent()) { + return opm.get().prefix; + } else { + return ""; + } + } + + /** + * @return The prefix of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderPrefix() { + return stripAllFormattingCodes(getSenderPrefix()); + } + + /** + * @return The suffix of the sender including any format codes in the '&' notation + */ + public String getSenderSuffix() { + Optional opm = PlayerMetaManager.getInstance().getPlayer(sender.getUniqueId()); + if (opm.isPresent()) { + return opm.get().suffix; + } else { + return ""; + } + } + + /** + * @return The suffix of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderSuffix() { + return stripAllFormattingCodes(getSenderSuffix()); + } + + /** + * @return The username of the sender + */ + public String getSenderName() { + return sender.getUsername(); + } + + /** + * @return The nickname of the sender including any format codes in the '&' notation + */ + public String getSenderNickname() { + Optional opm = PlayerMetaManager.getInstance().getPlayer(sender.getUniqueId()); + if (opm.isPresent()) { + return opm.get().nick; + } else { + return ""; + } + } + + /** + * @return The nickname of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderNickname() { + return stripAllFormattingCodes(getSenderNickname()); + } + + /** + * @return The server name of the sender + */ + public String getSenderServer() { + return sender.getCurrentServer().get().getServerInfo().getName(); + } + + /** + * Returns "Local" if the player is in local mode and only seeing chat from players on the same server + * Returns "Global" if the player is in global mode and seeing chat from everyone + */ + public String getSenderChatMode() { + + boolean global = ChatModeManager.getInstance().isGlobal(sender.getUniqueId()); + + if (!global) { + return "Local"; + } else { + return "Global"; + } + + } + + /** + * Returns "L" if the player is in local mode and only seeing chat from players on the same server + * Returns "G" if the player is in global mode and seeing chat from everyone + */ + public String getSenderShortChatMode() { + + boolean global = ChatModeManager.getInstance().isGlobal(sender.getUniqueId()); + + if (!global) { + return "L"; + } else { + return "G"; + } + + } + + /** + * Returns true if the player has the MultiChat permission to use format codes in global chat + */ + public boolean hasColorChatPermission() { + return (sender.hasPermission("multichat.chat.color") || sender.hasPermission("multichat.chat.colour")); + } + + /** + *

Returns true if this PostGlobalChatEvent has been cancelled

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT SENDS!

+ *

This is a POST global chat event, meaning the message has already happened by the time this event triggers.

+ */ + public boolean isCancelled() { + return cancelled; + } + + /** + *

Allows you to cancel this PostGlobalChatEvent

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT SENDS!

+ *

This is a POST global chat event, meaning the message has already happened by the time this event triggers.

+ */ + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + // Remove all formatting codes from the text (&a, &l etc.) + private static String stripAllFormattingCodes(String input) { + + char COLOR_CHAR = '&'; + Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]"); + + if (input == null) { + return null; + } + + return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); + + } + +} \ No newline at end of file diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostStaffChatEvent.java b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostStaffChatEvent.java new file mode 100644 index 00000000..55060798 --- /dev/null +++ b/multichat/src/main/java/xyz/olivermartin/multichat/velocity/events/PostStaffChatEvent.java @@ -0,0 +1,223 @@ +package xyz.olivermartin.multichat.velocity.events; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import xyz.olivermartin.multichat.velocity.PlayerMeta; +import xyz.olivermartin.multichat.velocity.PlayerMetaManager; + +import java.util.Optional; +import java.util.regex.Pattern; + +/** + * An event that triggers AFTER a staff chat message has been sent via MultiChat + * + * @author Oliver Martin (Revilo410) + * + */ +public class PostStaffChatEvent{ + + private boolean cancelled; + private String message; // The message that was sent + private CommandSource sender; // The sender of the message + private String type; // The type of staff chat, currently "mod" or "admin" + + /** + * Trigger a new PostStaffChatEvent + * + * @param type The type of staff chat, currently "mod" or "admin" + * @param sender The sender of the command, could be a player or the console + * @param message The message that was sent + */ + public PostStaffChatEvent(String type, CommandSource sender, String message) { + + cancelled = false; + this.message = message; + this.sender = sender; + this.type = type; + + } + + /** + * @return "mod" or "admin" depending on the type of staff chat + */ + public String getType() { + return type; + } + + /** + * @return The sender of the message, could be a player or the console + */ + public CommandSource getSender() { + return sender; + } + + /** + * @return The message that was sent including any format codes in the '&' notation + */ + public String getMessage() { + return message; + } + + /** + * @return The message that was sent EXCLUDING any format codes in the '&' notation + */ + public String getRawMessage() { + return stripAllFormattingCodes(getMessage()); + } + + /** + *

Allows you to change the message in this PostStaffChatEvent ONLY

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT SENDS!

+ *

This is a POST staff chat event, meaning the chat message has already happened by the time this event triggers.

+ */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @return The display name of the sender including any format codes in the '&' notation + */ + public String getSenderDisplayName() { + if (sender instanceof Player) { + return ((Player) sender).getUsername(); + } + return "CONSOLE"; + } + + /** + * @return The display name of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderDisplayName() { + return stripAllFormattingCodes(getSenderDisplayName()); + } + + /** + * @return The prefix of the sender including any format codes in the '&' notation + */ + public String getSenderPrefix() { + + if (sender instanceof Player) { + Optional opm = PlayerMetaManager.getInstance().getPlayer(((Player) sender).getUniqueId()); + if (opm.isPresent()) { + return opm.get().prefix; + } else { + return ""; + } + + } else { + return ""; + } + } + + /** + * @return The prefix of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderPrefix() { + return stripAllFormattingCodes(getSenderPrefix()); + } + + /** + * @return The suffix of the sender including any format codes in the '&' notation + */ + public String getSenderSuffix() { + if (sender instanceof Player) { + Optional opm = PlayerMetaManager.getInstance().getPlayer(((Player) sender).getUniqueId()); + if (opm.isPresent()) { + return opm.get().suffix; + } else { + return ""; + } + + } else { + return ""; + } + } + + /** + * @return The suffix of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderSuffix() { + return stripAllFormattingCodes(getSenderSuffix()); + } + + /** + * @return The username of the sender + */ + public String getSenderName() { + if (sender instanceof Player) { + + return ((Player) sender).getUsername(); + + } else { + return "CONSOLE"; + } + } + + /** + * @return The nickname of the sender including any format codes in the '&' notation + */ + public String getSenderNickname() { + if (sender instanceof Player) { + Optional opm = PlayerMetaManager.getInstance().getPlayer(((Player) sender).getUniqueId()); + if (opm.isPresent()) { + return opm.get().nick; + } else { + return ""; + } + + } else { + return "CONSOLE"; + } + } + + /** + * @return The nickname of the sender EXCLUDING any format codes in the '&' notation + */ + public String getRawSenderNickname() { + return stripAllFormattingCodes(getSenderNickname()); + } + + /** + * @return The server name of the sender + */ + public String getSenderServer() { + if (sender instanceof Player) { + return ((Player) sender).getCurrentServer().get().getServerInfo().getName(); + } else { + return "CONSOLE"; + } + } + + /** + *

Returns true if this PostStaffChatEvent has been cancelled

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT SENDS!

+ *

This is a POST staff chat event, meaning the message has already happened by the time this event triggers.

+ */ + public boolean isCancelled() { + return cancelled; + } + + /** + *

Allows you to cancel this PostStaffChatEvent

+ *

THIS WILL HAVE NO AFFECT ON WHAT MESSAGE MULTICHAT SENDS!

+ *

This is a POST staff chat event, meaning the message has already happened by the time this event triggers.

+ */ + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + // Remove all formatting codes from the text (&a, &l etc.) + private static String stripAllFormattingCodes(String input) { + + char COLOR_CHAR = '&'; + Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]"); + + if (input == null) { + return null; + } + + return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); + + } + +} \ No newline at end of file diff --git a/multichat/src/main/resources/chatcontrol.yml b/multichat/src/main/resources/chatcontrol.yml index 80307f8b..827a6f7c 100644 --- a/multichat/src/main/resources/chatcontrol.yml +++ b/multichat/src/main/resources/chatcontrol.yml @@ -8,7 +8,7 @@ ################## # DON'T EDIT # -version: "1.9.7" # +version: "1.9.8" # ################## # 1. Chat Control Rules diff --git a/multichat/src/main/resources/chatcontrol_fr.yml b/multichat/src/main/resources/chatcontrol_fr.yml index 75581e87..1d4621a0 100644 --- a/multichat/src/main/resources/chatcontrol_fr.yml +++ b/multichat/src/main/resources/chatcontrol_fr.yml @@ -8,7 +8,7 @@ ################## # NE PAS EDITER # -version: "1.9.7" # +version: "1.9.8" # ################## # French Translation by Nogapra - Thank you ! diff --git a/multichat/src/main/resources/config.yml b/multichat/src/main/resources/config.yml index 852de680..2844c78e 100644 --- a/multichat/src/main/resources/config.yml +++ b/multichat/src/main/resources/config.yml @@ -8,7 +8,7 @@ ################## # DON'T EDIT # -version: "1.9.7" # +version: "1.9.9" # ################## # 1. General @@ -169,6 +169,20 @@ global: true no_global: [] +# Grouping of Servers Global Chat +# Allows for sharing of global chat between specific servers +# Global Chat Above Still Needs to be turned on +# Does not look at the No Global List +serverGroups: + enabled: false + groups: + Group1: + - Server1 + - Server2 + Group2: + - Server3 + - Server4 + ####################### # Global Chat Formats # ####################### @@ -238,6 +252,22 @@ adminchat: ccdefault: "d" ncdefault: "b" +############################################################ +# +------------------------------------------------------+ # +# | Execute Command | # +# +------------------------------------------------------+ # +############################################################ +# Enable/Disable the proxy execute command +mcexecute_enabled: true + +# MultiChat execute command aliases (other than /multichatexecute) +multichatexecutecommand: + - mcexecute + - mce + - gexecute + - gexe + - gcommand + ############################################################ # +------------------------------------------------------+ # # | Other | # @@ -252,14 +282,6 @@ multichatbypasscommand: - mcb - bypass -# MultiChat execute command aliases (other than /multichatexecute) -multichatexecutecommand: -- mcexecute -- mce -- gexecute -- gexe -- gcommand - # Control what aspects of chat are logged by MultiChat (useful for GDPR etc.) privacy_settings: log_pms: true diff --git a/multichat/src/main/resources/config_fr.yml b/multichat/src/main/resources/config_fr.yml index e2abda99..7c9150d7 100644 --- a/multichat/src/main/resources/config_fr.yml +++ b/multichat/src/main/resources/config_fr.yml @@ -8,7 +8,7 @@ ################## # NE PAS EDITER # -version: "1.9.7" # +version: "1.9.9" # ################## # French Translation by Nogapra - Thank you ! @@ -176,6 +176,20 @@ global: true # etc. no_global: [] +# Grouping of Servers Global Chat +# Allows for sharing of global chat between specific servers +# Global Chat Above Still Needs to be turned on +# Does not look at the No Global List +serverGroups: + enabled: false + groups: + Group1: + - Server1 + - Server2 + Group2: + - Server3 + - Server4 + ########################## # Formata du chat global # ########################## @@ -242,6 +256,22 @@ adminchat: ccdefault: "d" ncdefault: "b" +############################################################ +# +------------------------------------------------------+ # +# | Execute Command | # +# +------------------------------------------------------+ # +############################################################ +# Enable/Disable the proxy execute command +mcexecute_enabled: true + +# Alias de commande MultiChat Execute (autre que /multichatexecute). +multichatexecutecommand: + - mcexecute + - mce + - gexecute + - gexe + - gcommand + ############################################################ # +------------------------------------------------------+ # # | Divers | # @@ -257,14 +287,6 @@ multichatbypasscommand: - mcb - bypass -# Alias de commande MultiChat Execute (autre que /multichatexecute). -multichatexecutecommand: -- mcexecute -- mce -- gexecute -- gexe -- gcommand - # Contrôlez quels aspects du chat sont enregistrés dans les logs MultiChat (utile pour la RGDP etc.) privacy_settings: log_pms: true diff --git a/multichat/src/main/resources/joinmessages.yml b/multichat/src/main/resources/joinmessages.yml index a9077183..6f47bbb6 100644 --- a/multichat/src/main/resources/joinmessages.yml +++ b/multichat/src/main/resources/joinmessages.yml @@ -8,7 +8,7 @@ ################## # DON'T EDIT # -version: "1.9.7" # +version: "1.9.8" # ################## ############################################################ diff --git a/multichat/src/main/resources/joinmessages_fr.yml b/multichat/src/main/resources/joinmessages_fr.yml index 44db04a2..733441b9 100644 --- a/multichat/src/main/resources/joinmessages_fr.yml +++ b/multichat/src/main/resources/joinmessages_fr.yml @@ -8,7 +8,7 @@ ################## # Ne pas éditer # -version: "1.9.7" # +version: "1.9.8" # ################## # French Translation by Nogapra - Thank you! diff --git a/multichat/src/main/resources/localconfig.yml b/multichat/src/main/resources/localconfig.yml index 9acecd83..0772d5d3 100644 --- a/multichat/src/main/resources/localconfig.yml +++ b/multichat/src/main/resources/localconfig.yml @@ -8,7 +8,7 @@ ################## # DON'T EDIT # -version: "1.9.7" # +version: "1.9.9" # ################## # 1. Global Chat Settings @@ -138,6 +138,14 @@ mysql_flags: [] #- useSSL=false #- autoReconnect=true +############################################################ +# +------------------------------------------------------+ # +# | Execute Command | # +# +------------------------------------------------------+ # +############################################################ +# Enable/Disable the proxy execute command +pexecute_enabled: true + ############################################################ # +------------------------------------------------------+ # # | Channel Control | # diff --git a/multichat/src/main/resources/localconfig_fr.yml b/multichat/src/main/resources/localconfig_fr.yml index 301da3af..ce051653 100644 --- a/multichat/src/main/resources/localconfig_fr.yml +++ b/multichat/src/main/resources/localconfig_fr.yml @@ -8,7 +8,7 @@ ################## # NE PAS EDITER # -version: "1.9.7" # +version: "1.9.9" # ################## # French Translation by Nogapra - Thank you ! @@ -148,6 +148,14 @@ mysql_flags: [] #- useSSL=false #- autoReconnect=true +############################################################ +## +------------------------------------------------------+ # +## | Execute Command | # +## +------------------------------------------------------+ # +############################################################# +## Enable/Disable the proxy execute command +pexecute_enabled: true + ############################################################ # +------------------------------------------------------+ # # | Contrôle de canal | # diff --git a/multichat/src/main/resources/messages.yml b/multichat/src/main/resources/messages.yml index 15ad1cd6..72da06e8 100644 --- a/multichat/src/main/resources/messages.yml +++ b/multichat/src/main/resources/messages.yml @@ -8,13 +8,14 @@ ################## # DON'T EDIT # -version: "1.9.7" # +version: "1.9.8" # ################## ############################################################ # +------------------------------------------------------+ # # | Customise Messages | # # +------------------------------------------------------+ # +# Use %SERVER% to add the player's server # ############################################################ # Console log formats diff --git a/multichat/src/main/resources/messages_fr.yml b/multichat/src/main/resources/messages_fr.yml index ed421ce1..be01048a 100644 --- a/multichat/src/main/resources/messages_fr.yml +++ b/multichat/src/main/resources/messages_fr.yml @@ -8,7 +8,7 @@ ################## # DON'T EDIT # -version: "1.9.7" # +version: "1.9.8" # ################## # French Translation by Nogapra - Thank you! @@ -18,6 +18,7 @@ version: "1.9.7" # # +------------------------------------------------------+ # # | Customise Messages | # # +------------------------------------------------------+ # +# Use %SERVER% to add the player's server # ############################################################ # Format des logs console diff --git a/multichat/src/main/resources/plugin.yml b/multichat/src/main/resources/plugin.yml index 8314be1e..6eeef3c7 100644 --- a/multichat/src/main/resources/plugin.yml +++ b/multichat/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: MultiChat -version: 1.9.7 +version: 1.9.8 author: Revilo410 main: xyz.olivermartin.multichat.local.spigot.MultiChatLocalSpigotPlugin softdepend: [Vault,PlaceholderAPI] diff --git a/multichat/src/main/resources/velocity.yml b/multichat/src/main/resources/velocity.yml new file mode 100644 index 00000000..5c8600f1 --- /dev/null +++ b/multichat/src/main/resources/velocity.yml @@ -0,0 +1,6 @@ +name: MultiChat +main: xyz.olivermartin.multichat.velocity.MultiChat +version: 1.9.8 +author: Revilo410 +api-version: 1.16 +softdepends: [PremiumVanish]