Manages all plug-in messaging channels on the BungeeCord side
- * - * @author Oliver Martin (Revilo410) - * - */ -public class BungeeComm implements Listener { - - 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? - Configuration configYML = ConfigManager.getInstance().getHandler("config.yml").getConfig(); - if (configYML.contains("set_display_name")) { - if (configYML.getBoolean("set_display_name")) { - out.writeUTF("T"); - } else { - out.writeUTF("F"); - } - } else { - out.writeUTF("T"); - } - - // Display name format - if (configYML.contains("display_name_format")) { - out.writeUTF(configYML.getString("display_name_format")); - } else { - out.writeUTF("%PREFIX%%NICK%%SUFFIX%"); - } - - // Is this server a global chat server? - if (ConfigManager.getInstance().getHandler("config.yml").getConfig().getBoolean("global") == true - && !ConfigManager.getInstance().getHandler("config.yml").getConfig().getStringList("no_global").contains(server.getName())) { - out.writeUTF("T"); - } else { - out.writeUTF("F"); - } - - // Send the global format - out.writeUTF(Channel.getGlobalChannel().getFormat()); - - } catch (IOException e) { - e.printStackTrace(); - } - - server.sendData("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(); - } - - server.sendData("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(); - } - - server.sendData("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(); - } - - server.sendData("multichat:chat", stream.toByteArray()); - - } - - public static void sendIgnoreMap(ServerInfo server) { - - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - //DataOutputStream out = new DataOutputStream(stream); - try { - ObjectOutputStream oout = new ObjectOutputStream(stream); - - oout.writeObject(ChatControl.getIgnoreMap()); - - } catch (IOException e) { - e.printStackTrace(); - } - - server.sendData("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(); - } - - server.sendData("multichat:ch", stream.toByteArray()); - - DebugManager.log("Sent message on multichat:ch channel!"); - - } - - @EventHandler - public static void onPluginMessage(PluginMessageEvent ev) { - - if (! (ev.getTag().equals("multichat:comm") || ev.getTag().equals("multichat:chat") || ev.getTag().equals("multichat:prefix") || ev.getTag().equals("multichat:suffix") || ev.getTag().equals("multichat:dn") || ev.getTag().equals("multichat:world") || ev.getTag().equals("multichat:nick") || ev.getTag().equals("multichat:pxe") || ev.getTag().equals("multichat:ppxe")) ) { - return; - } - - if (!(ev.getSender() instanceof Server)) { - return; - } - - if (ev.getTag().equals("multichat:comm")) { - - // TODO Remove - legacy - return; - - } - - if (ev.getTag().equals("multichat:chat")) { - - ev.setCancelled(true); - - 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); - - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); - - 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.getName()); - - //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.getTag().equals("multichat:nick")) { - - ev.setCancelled(true); - - ByteArrayInputStream stream = new ByteArrayInputStream(ev.getData()); - DataInputStream in = new DataInputStream(stream); - - try { - - UUID uuid = UUID.fromString(in.readUTF()); - String nick = in.readUTF(); - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); - - 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. - */ - - OptionalA class to represent a chat channel and control the messages sent etc.
- * - * @author Oliver Martin (Revilo410) - * - */ -public class Channel { - - private static GlobalChannel global; - private static 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 MapManages loading / creation of an individual configuration file
- * - * @author Oliver Martin (Revilo410) - * - */ -public class ConfigHandler { - - // The config file - private Configuration config; - // Path of config file - private File configPath; - // Name of config file - private String fileName; - - public ConfigHandler(File configPath, String fileName) { - - this.configPath = configPath; - this.config = null; - this.fileName = fileName; - this.startupConfig(); - - } - - public Configuration getConfig() { - if (config == null) startupConfig(); - return config; - } - - public void startupConfig() { - - try { - - File file = new File(configPath, fileName); - - if (!file.exists()) { - - ProxyServer.getInstance().getLogger().info("Config file " + fileName + " not found... Creating new one."); - saveDefaultConfig(); - - loadConfig(); - - } else { - - ProxyServer.getInstance().getLogger().info("Loading " + fileName + "..."); - loadConfig(); - - } - - } catch (Exception e) { - ProxyServer.getInstance().getLogger().info("[ERROR] Could not load " + fileName); - e.printStackTrace(); - } - } - - private void saveDefaultConfig() { - - // Load default file into input stream - InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName); - - // Copy to desired location - try { - Files.copy(inputStream, new File(configPath, fileName).toPath(), new CopyOption[0]); - } catch (IOException e) { - ProxyServer.getInstance().getLogger().info("[ERROR] Could not create new " + fileName + " file..."); - e.printStackTrace(); - } finally { - try { - inputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - } - - private void loadConfig() { - - try { - - this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(configPath, fileName)); - - } catch (IOException e) { - - ProxyServer.getInstance().getLogger().info("[ERROR] Could not load " + fileName + " file..."); - e.printStackTrace(); - - } - } -} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/ConfigManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/ConfigManager.java deleted file mode 100644 index 7582a4e0..00000000 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/ConfigManager.java +++ /dev/null @@ -1,71 +0,0 @@ -package xyz.olivermartin.multichat.bungee; - - -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 ConfigManager instance; - - static { - - instance = new ConfigManager(); - - } - - public static ConfigManager getInstance() { - return instance; - } - - // END OF STATIC - - private MapHandles 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().getString("groupchat.ccdefault").toCharArray()[0]); - newgroup.setNameColor(ConfigManager.getInstance().getHandler("config.yml").getConfig().getString("groupchat.ncdefault").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, ProxiedPlayer player, String password) { - - boolean success = false; - - TGroupChatInfo groupchat = new TGroupChatInfo(); - groupchat = (TGroupChatInfo)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()); - } - - groupchat = null; - return success; - - } - - /** - * Sets the selected group of a player to the specified group - */ - public void setViewedChat(UUID playeruuid, String groupname) { - - String viewedchat = (String)MultiChat.viewedchats.get(playeruuid); - - 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, ProxiedPlayer pinstance) { - - TGroupChatInfo groupchatinfo = new TGroupChatInfo(); - String viewedchat = (String)MultiChat.viewedchats.get(player); - - groupchatinfo = (TGroupChatInfo)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); - } - - viewedchat = null; - - MultiChat.viewedchats.remove(player); - MultiChat.viewedchats.put(player, viewedchat); - MultiChat.groupchats.remove(groupname.toLowerCase()); - MultiChat.groupchats.put(groupname.toLowerCase(), groupchatinfo); - - MessageManager.sendSpecialMessage(pinstance, "groups_quit", groupname.toUpperCase()); - announceQuitGroup(pinstance.getName(), 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()); - - } - - groupchatinfo = null; - - } - - public void displayHelp(int page, CommandSender sender) { - - if (page == 1) { - - MessageManager.sendMessage(sender, "groups_help_1"); - - } else { - - MessageManager.sendMessage(sender, "groups_help_2"); - - } - } + /** + * 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(); + ProxyDataStore ds = MultiChatProxy.getInstance().getDataStore(); + + newgroup.addMember(owneruuid); + newgroup.addViewer(owneruuid); + newgroup.addAdmin(owneruuid); + newgroup.setName(groupname.toLowerCase()); + newgroup.setChatColor(ProxyConfigs.CONFIG.getGroupChatColor()); + newgroup.setNameColor(ProxyConfigs.CONFIG.getGroupNameColor()); + newgroup.setSecret(secret); + newgroup.setPassword(password); + newgroup.setFormal(false); + + ds.getGroupChats().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, ProxiedPlayer player, String password) { + ProxyDataStore dataStore = MultiChatProxy.getInstance().getDataStore(); + TGroupChatInfo groupChatInfo = dataStore.getGroupChats().get(groupname.toLowerCase()); + + UUID playerUID = player.getUniqueId(); + if (groupChatInfo.isBanned(playerUID)) { + ProxyConfigs.MESSAGES.sendMessage(player, "groups_banned", groupname.toUpperCase()); + return false; + } + + if (groupChatInfo.isMember(playerUID)) { + ProxyConfigs.MESSAGES.sendMessage(player, "groups_already_joined", groupname.toUpperCase()); + return false; + } + + if (groupChatInfo.getSecret()) { + if (password.isEmpty()) { + ProxyConfigs.MESSAGES.sendMessage(player, "groups_password_protected", groupname.toUpperCase()); + return false; + } + + if (!password.equals(groupChatInfo.getPassword())) { + ProxyConfigs.MESSAGES.sendMessage(player, "groups_password_incorrect", groupname.toUpperCase()); + return false; + } + } + + if (groupChatInfo.isViewer(player.getUniqueId())) { + if (player.hasPermission("multichat.staff.spy")) + ProxyConfigs.MESSAGES.sendMessage(player, "command_group_spy_off", groupname.toUpperCase()); + + groupChatInfo.delViewer(player.getUniqueId()); + } + + groupChatInfo.addMember(player.getUniqueId()); + groupChatInfo.addViewer(player.getUniqueId()); + + dataStore.getGroupChats().remove(groupname.toLowerCase()); + dataStore.getGroupChats().put(groupname.toLowerCase(), groupChatInfo); + + return true; + } + + /** + * Sets the selected group of a player to the specified group + */ + public void setViewedChat(UUID playeruuid, String groupname) { + ProxyDataStore ds = MultiChatProxy.getInstance().getDataStore(); + ds.getViewedChats().get(playeruuid); + String viewedchat = groupname.toLowerCase(); + ds.getViewedChats().remove(playeruuid); + ds.getViewedChats().put(playeruuid, viewedchat); + } + + /** + * The INFO announce in a group that a player has joined + */ + public void announceJoinGroup(String playername, String groupname) { + ProxyDataStore ds = MultiChatProxy.getInstance().getDataStore(); + + GCCommand.sendMessage(playername + ProxyConfigs.MESSAGES.getMessage("groups_info_joined"), "&lINFO", ds.getGroupChats().get(groupname.toLowerCase())); + } + + /** + * The INFO announce in a group that a player has left + */ + public void announceQuitGroup(String playername, String groupname) { + ProxyDataStore ds = MultiChatProxy.getInstance().getDataStore(); + + GCCommand.sendMessage(playername + ProxyConfigs.MESSAGES.getMessage("groups_info_quit"), "&lINFO", ds.getGroupChats().get(groupname.toLowerCase())); + } + + /** + * Quits a group, announces in the group chat and notifies the player quitting + */ + public void quitGroup(String groupname, UUID player, ProxiedPlayer pinstance) { + ProxyDataStore dataStore = MultiChatProxy.getInstance().getDataStore(); + TGroupChatInfo groupChatInfo = dataStore.getGroupChats().get(groupname.toLowerCase()); + + if (!groupChatInfo.isMember(player)) { + ProxyConfigs.MESSAGES.sendMessage(pinstance, "command_group_not_a_member", groupname.toUpperCase()); + return; + } + + if ((!groupChatInfo.isAdmin(player)) || (groupChatInfo.getAdmins().size() > 1)) { + groupChatInfo.delMember(player); + groupChatInfo.delViewer(player); + + if (groupChatInfo.isAdmin(player)) { + groupChatInfo.delAdmin(player); + } + + dataStore.getViewedChats().remove(player); + dataStore.getViewedChats().put(player, null); + dataStore.getGroupChats().remove(groupname.toLowerCase()); + dataStore.getGroupChats().put(groupname.toLowerCase(), groupChatInfo); + + ProxyConfigs.MESSAGES.sendMessage(pinstance, "groups_quit", groupname.toUpperCase()); + announceQuitGroup(pinstance.getName(), groupname); + } else if (!groupChatInfo.getFormal()) { + ProxyConfigs.MESSAGES.sendMessage(pinstance, "groups_cannot_quit_owner_1", groupname.toUpperCase()); + ProxyConfigs.MESSAGES.sendMessage(pinstance, "groups_cannot_quit_owner_2", groupname.toUpperCase()); + } else { + ProxyConfigs.MESSAGES.sendMessage(pinstance, "groups_cannot_quit_admin_1", groupname.toUpperCase()); + ProxyConfigs.MESSAGES.sendMessage(pinstance, "groups_cannot_quit_admin_2", groupname.toUpperCase()); + } + } + + public void displayHelp(int page, CommandSender sender) { + ProxyConfigs.MESSAGES.sendMessage(sender, "groups_help_" + (page == 1 ? "1" : "2")); + } } diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/LocalChannel.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/LocalChannel.java deleted file mode 100644 index 512b948e..00000000 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/LocalChannel.java +++ /dev/null @@ -1,32 +0,0 @@ -package xyz.olivermartin.multichat.bungee; - -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -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(ProxiedPlayer sender, String message, String format) { - /* EMPTY */ - } - - @Override - public void sendMessage(String message, CommandSender sender) { - - DebugManager.log("LocalChannel wants to send a cast message!"); - - // Use this to relay CASTS to local chat! - if (sender instanceof ProxiedPlayer) { - BungeeComm.sendChatMessage(message, ((ProxiedPlayer)sender).getServer().getInfo()); - } - - } - -} diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java deleted file mode 100644 index 9cfad8cd..00000000 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/MessageManager.java +++ /dev/null @@ -1,438 +0,0 @@ -package xyz.olivermartin.multichat.bungee; - -import java.util.HashMap; -import java.util.Map; - -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.config.Configuration; - -/** - * Message Manager - *Used to display all plugin messages to players
- * - * @author Oliver Martin (Revilo410) - */ -public class MessageManager { - - private static MapThis class is the main plugin. All plugin enable and disable control happens here.
- * - * @author Oliver Martin (Revilo410) * + * @author Oliver Martin (Revilo410) */ -public class MultiChat extends Plugin implements Listener { - - public static final String LATEST_VERSION = "1.9.5"; - - public static final String[] ALLOWED_VERSIONS = new String[] { - - LATEST_VERSION, - "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 MapAllows the user to toggle / send a message to admin-chat
- * - * @author Oliver Martin (Revilo410) * + * @author Oliver Martin (Revilo410) */ public class ACCommand extends Command { - private static String[] aliases = new String[] {}; - - public ACCommand() { - super("ac", "multichat.staff.admin", aliases); - } - - public void execute(CommandSender sender, String[] args) { - - boolean toggleresult; - - if (args.length < 1) { - - if ((sender instanceof ProxiedPlayer)) { - - DebugManager.log("[ACCommand] Command sender is a player"); - - ProxiedPlayer player = (ProxiedPlayer)sender; - toggleresult = Events.toggleAC(player.getUniqueId()); - - DebugManager.log("[ACCommand] AC new toggle state: " + toggleresult); - - if (toggleresult == true) { - 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 ProxiedPlayer)) { - - DebugManager.log("[ACCommand] Command sender is a player"); - - String message = MultiChatUtil.getMessageFromArgs(args); - - ProxiedPlayer player = (ProxiedPlayer)sender; - StaffChatManager chatman = new StaffChatManager(); - - DebugManager.log("[ACCommand] Next line of code will send the message, if no errors, then it worked!"); - - chatman.sendAdminMessage(player.getName(), player.getDisplayName(), player.getServer().getInfo().getName(), message); - chatman = null; - - } 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); - chatman = null; - - } - } + public ACCommand() { + super("mcac", "multichat.staff.admin", ProxyConfigs.ALIASES.getAliases("mcac")); + } + + public void execute(CommandSender sender, String[] args) { + if (args.length == 0) { + if (!(sender instanceof ProxiedPlayer)) { + ProxyConfigs.MESSAGES.sendMessage(sender, "command_ac_only_players"); + return; + } + + UUID playerUID = ((ProxiedPlayer) sender).getUniqueId(); + boolean toggleResult = Events.toggleAC(playerUID); + ProxyConfigs.MESSAGES.sendMessage(sender, "command_ac_toggle_" + (toggleResult ? "on" : "off")); + return; + } + + String name = "CONSOLE"; + String displayName = "CONSOLE"; + String serverName = "#"; + + if (sender instanceof ProxiedPlayer) { + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + name = proxiedPlayer.getName(); + displayName = proxiedPlayer.getDisplayName(); + serverName = proxiedPlayer.getServer().getInfo().getName(); + } + + new StaffChatManager().sendAdminMessage(name, displayName, serverName, String.join(" ", args)); + } } diff --git a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/commands/AnnouncementCommand.java b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/commands/AnnouncementCommand.java index 83b087e7..db017df0 100644 --- a/multichat/src/main/java/xyz/olivermartin/multichat/bungee/commands/AnnouncementCommand.java +++ b/multichat/src/main/java/xyz/olivermartin/multichat/bungee/commands/AnnouncementCommand.java @@ -1,167 +1,123 @@ package xyz.olivermartin.multichat.bungee.commands; -import java.util.Iterator; -import java.util.Map; +import java.util.Arrays; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.plugin.Command; import xyz.olivermartin.multichat.bungee.Announcements; -import xyz.olivermartin.multichat.bungee.MessageManager; -import xyz.olivermartin.multichat.bungee.MultiChatUtil; +import xyz.olivermartin.multichat.proxy.common.config.ProxyConfigs; /** * Announcement Command *Allows the user to create, remove or use announcements
- * - * @author Oliver Martin (Revilo410) * + * @author Oliver Martin (Revilo410) */ public class AnnouncementCommand extends Command { - private static String[] aliases = new String[] {"announce"}; - - public AnnouncementCommand() { - super("announcement", "multichat.announce", aliases); - } - - public void execute(CommandSender sender, String[] args) { - - if (args.length < 1) { - - showCommandUsage(sender); - - } else if (args.length == 1) { - - if (args[0].toLowerCase().equals("list")) { - - MapAllows the user to create, start and stop bulletins
- * - * @author Oliver Martin (Revilo410) * + * @author Oliver Martin (Revilo410) */ public class BulletinCommand extends Command { - private static String[] aliases = new String[] {"bulletins"}; - - public BulletinCommand() { - super("bulletin", "multichat.bulletin", aliases); - } - - @Override - public void execute(CommandSender sender, String[] args) { - - if (args.length < 1) { - - showCommandUsage(sender); - - } else if (args.length == 1) { - - if (args[0].toLowerCase().equals("stop")) { - - Bulletins.stopBulletins(); - MessageManager.sendMessage(sender, "command_bulletin_stopped"); - - } else if (args[0].toLowerCase().equals("list")) { - - int counter = 0; - IteratorThe Custom broadcAST (CAST) command allows you to create your own customised broadcast formats
- * - * @author Oliver Martin (Revilo410) * + * @author Oliver Martin (Revilo410) */ public class CastCommand extends Command { - private static String[] aliases = new String[] {}; - - public CastCommand() { - super("cast", "multichat.cast.admin", aliases); - } - - public void showCommandUsage(CommandSender sender) { - MessageManager.sendMessage(sender, "command_cast_usage"); - sender.sendMessage(new ComponentBuilder("/cast addPlayers can use this command to switch channels, as well as show and hide specific channels
- * - * @author Oliver Martin (Revilo410) * + * @author Oliver Martin (Revilo410) */ public class ChannelCommand extends Command { - public ChannelCommand() { - super("channel", "multichat.chat.channel", (String[]) ConfigManager.getInstance().getHandler("config.yml").getConfig().getStringList("channelcommand").toArray(new String[0])); - } - - private void showHelp(CommandSender sender) { - - MessageManager.sendMessage(sender, "command_channel_help"); - - } - - @Override - public void execute(CommandSender sender, String[] args) { - - if ((sender instanceof ProxiedPlayer)) { - - 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(((ProxiedPlayer)sender).getUniqueId()); - MessageManager.sendSpecialMessage(sender, "command_channel_switch", operand.toUpperCase()); - } else if (operand.equals("global")) { - ChatModeManager.getInstance().setGlobal(((ProxiedPlayer)sender).getUniqueId()); - MessageManager.sendSpecialMessage(sender, "command_channel_switch", operand.toUpperCase()); - } else { - MessageManager.sendMessage(sender, "command_channel_does_not_exist"); - } - break; - - 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(((ProxiedPlayer)sender).getUniqueId())) { - MessageManager.sendMessage(sender, "command_channel_cannot_hide"); - return; - } - - Channel local = Channel.getLocalChannel(); - if (local.isMember(((ProxiedPlayer)sender).getUniqueId())) { - local.addMember(((ProxiedPlayer)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(((ProxiedPlayer)sender).getUniqueId())) { - MessageManager.sendMessage(sender, "command_channel_cannot_hide"); - return; - } - - Channel global = Channel.getGlobalChannel(); - if (global.isMember(((ProxiedPlayer)sender).getUniqueId())) { - global.addMember(((ProxiedPlayer)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"); - } - break; - - 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(((ProxiedPlayer)sender).getUniqueId())) { - local.removeMember(((ProxiedPlayer)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(((ProxiedPlayer)sender).getUniqueId())) { - global.removeMember(((ProxiedPlayer)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"); - } - break; - - default: - showHelp(sender); - break; - } - - // Update local channel info - for (ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) { - BungeeComm.sendPlayerChannelMessage(p.getName(), Channel.getChannel(p.getUniqueId()).getName(), Channel.getChannel(p.getUniqueId()), p.getServer().getInfo(), (p.hasPermission("multichat.chat.colour")||p.hasPermission("multichat.chat.color")||p.hasPermission("multichat.chat.colour.simple")||p.hasPermission("multichat.chat.color.simple")), (p.hasPermission("multichat.chat.colour")||p.hasPermission("multichat.chat.color")||p.hasPermission("multichat.chat.colour.rgb")||p.hasPermission("multichat.chat.color.rgb"))); - } - - } - - } else { - MessageManager.sendMessage(sender, "command_channel_only_players"); - } - - } - + public ChannelCommand() { + super("mcchannel", "multichat.chat.channel", ProxyConfigs.ALIASES.getAliases("mcchannel")); + } + + @Override + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof ProxiedPlayer)) { + ProxyConfigs.MESSAGES.sendMessage(sender, "command_channel_only_players"); + return; + } + + if (args.length < 2) { + showCommandUsage(sender); + return; + } + + ChannelManager channelManager = MultiChatProxy.getInstance().getChannelManager(); + String operand = args[1].toLowerCase(); + + // TODO: This check is horrible... + // Future implementation of channelManager.exists? + // Or implement a Channel interface that both Proxy and Local extend + if (!channelManager.existsProxyChannel(operand) && !operand.equals("local")) { + ProxyConfigs.MESSAGES.sendMessage(sender, "command_channel_does_not_exist"); + return; + } + + ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender; + UUID proxiedPlayerUID = proxiedPlayer.getUniqueId(); + Optional