diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java index 755cc6199..658f481fd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementManager.java @@ -14,7 +14,6 @@ import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.achievement.command.StatsCommand; import mineplex.core.achievement.ui.AchievementShop; -import mineplex.core.common.util.C; import mineplex.core.common.util.NautHashMap; import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; @@ -266,7 +265,7 @@ public class AchievementManager extends MiniPlugin prefix = Achievement.getExperienceString(level); } - return prefix + C.Reset + " "; + return prefix; } public CoreClientManager getClientManager() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antispam/AntiSpamManager.java b/Plugins/Mineplex.Core/src/mineplex/core/antispam/AntiSpamManager.java index 14aa7b447..e91f43666 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antispam/AntiSpamManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antispam/AntiSpamManager.java @@ -1,27 +1,24 @@ package mineplex.core.antispam; -import mineplex.core.MiniPlugin; -import mineplex.core.antispam.repository.AntiSpamRepository; -import mineplex.core.chat.IChatMessageFormatter; -import mineplex.core.status.ServerStatusManager; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.AsyncPlayerChatEvent; -/** - * @author Shaun Bennett - */ +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.antispam.repository.AntiSpamRepository; +import mineplex.core.chat.event.FormatPlayerChatEvent; +import mineplex.core.status.ServerStatusManager; + +@ReflectivelyCreateMiniPlugin public class AntiSpamManager extends MiniPlugin { + private final String _pluginName; private final String _serverName; private final String _region; private final AntiSpamRepository _repository; - private IChatMessageFormatter _messageFormatter; - - public AntiSpamManager() + private AntiSpamManager() { super("AntiSpam"); @@ -41,34 +38,18 @@ public class AntiSpamManager extends MiniPlugin } } - public void setMessageFormatter(IChatMessageFormatter messageFormatter) + @EventHandler + public void onChat(FormatPlayerChatEvent event) { - _messageFormatter = messageFormatter; - } + Player player = event.getPlayer(); + String message = event.getMessage(); + ChatPayload payload = new ChatPayload(player.getName(), player.getUniqueId().toString(), _region, _serverName, message, System.currentTimeMillis()); + // Run our API call async to the chat message (prevents blocking chat message) + AntiSpamApiResponse response = _repository.sendMessage(_pluginName, payload); - @EventHandler(priority = EventPriority.LOWEST) - public void onChat(AsyncPlayerChatEvent event) - { - // Only listen to async events, as non async events are fake messages - if (event.isAsynchronous()) + if (response != null && response.isShadowMuted()) // can be null if the request times out { - Player player = event.getPlayer(); - String message = event.getMessage(); - ChatPayload payload = new ChatPayload(player.getName(), player.getUniqueId().toString(), _region, _serverName, message, System.currentTimeMillis()); - // Run our API call async to the chat message (prevents blocking chat message) - AntiSpamApiResponse response = _repository.sendMessage(_pluginName, payload); - if (response != null) // can be null if the request times out - { - if (response.isShadowMuted()) - { - event.setCancelled(true); - if (_messageFormatter != null) - { - String formattedMessage = String.format(_messageFormatter.getChatFormat(player, message).getFormat(), player.getName(), message); - event.getPlayer().sendMessage(formattedMessage); - } - } - } + event.getRecipients().removeIf(other -> !player.equals(other)); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java index 122a7d73f..0266d007d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java @@ -1,5 +1,10 @@ package mineplex.core.chat; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; @@ -12,17 +17,14 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; -import java.util.function.Function; import java.util.stream.Collectors; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; -import org.apache.commons.lang3.Validate; +import org.bukkit.ChatColor; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -37,6 +39,7 @@ import org.json.simple.JSONObject; import org.json.simple.JSONValue; import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.account.permissions.Permission; @@ -44,24 +47,28 @@ import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.chat.command.BroadcastCommand; import mineplex.core.chat.command.ChatSlowCommand; import mineplex.core.chat.command.HelpCommand; +import mineplex.core.chat.command.ListEmotesCommand; import mineplex.core.chat.command.SilenceCommand; -import mineplex.core.chat.command.extra.ChatExtraCommand; +import mineplex.core.chat.event.FormatPlayerChatEvent; +import mineplex.core.chat.format.ChatFormatComponent; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTime; -import mineplex.core.communities.CommunityManager; import mineplex.core.incognito.IncognitoManager; import mineplex.core.preferences.Preference; import mineplex.core.preferences.PreferencesManager; +import mineplex.core.preferences.UserPreferences; import mineplex.core.recharge.Recharge; +@ReflectivelyCreateMiniPlugin public class Chat extends MiniPlugin { public enum Perm implements Permission { ALLOW_CAPS, + ALLOW_COLOUR, BYPASS_COOLDOWN, BYPASS_SLOW, BYPASS_SILENCE, @@ -73,6 +80,7 @@ public class Chat extends MiniPlugin SLOW_CHAT_COMMAND, BROADCAST_COMMAND, HELP_COMMAND, + WHITE_CHAT, CHAT_EXTRA_COMMAND, MOD_CHAT_EXTRA_COMMAND, @@ -83,6 +91,21 @@ public class Chat extends MiniPlugin private static final String STRIP_HACKUSATION_REGEX = "[^A-Za-z ]"; private static final List HACKUSATIONS = Arrays.asList("hack", "hax", "hacker", "hacking", "cheat", "cheater", "cheating", "forcefield", "flyhack", "flyhacking", "autoclick", "aimbot"); private static final int MAX_CAPS_PER_MSG = 30; + public static final Map EMOTES = new HashMap<>(); + + static + { + EMOTES.put("ヽ༼ຈل͜ຈ༽ノ", ":donger:"); + EMOTES.put("¯\\_(ツ)_/¯", ":shrug:"); + EMOTES.put("༼ つ ◕_◕ ༽つ", ":ameno:"); + EMOTES.put("(╯°□°)╯︵ ┻━┻", ":tableflip:"); + EMOTES.put("┬─┬ノ(ಠ_ಠノ)", ":tablesit:"); + EMOTES.put("(౮⦦ʖ౮)", ":lenny:"); + EMOTES.put("ಠ_ಠ", ":disapproval:"); + EMOTES.put("(☞゚ヮ゚)☞", ":same:"); + EMOTES.put("ლ(ಥ Д ಥ )ლ", ":why:"); + EMOTES.put("(≖_≖)", ":squint:"); + } // Cleanspeak private static final String FILTER_URL = "https://chat.mineplex.com:8003/content/item/moderate"; @@ -97,13 +120,10 @@ public class Chat extends MiniPlugin private long _silenceLength; private BukkitTask _silenceTask; - //TODO: remove this because it's stupid - private List> _highPriorityFilters = new ArrayList<>(); - private List> _lowPriorityFilters = new ArrayList<>(); - private Map _playerLastMessage = new HashMap<>(); + private final List _formatComponents = new ArrayList<>(); - public Chat() + private Chat() { super("Chat"); @@ -128,6 +148,7 @@ public class Chat extends MiniPlugin private void generatePermissions() { PermissionGroup.ADMIN.setPermission(Perm.ALLOW_CAPS, true, true); + PermissionGroup.ADMIN.setPermission(Perm.ALLOW_COLOUR, true, true); PermissionGroup.MOD.setPermission(Perm.BYPASS_COOLDOWN, true, true); PermissionGroup.TRAINEE.setPermission(Perm.BYPASS_SLOW, true, true); PermissionGroup.MOD.setPermission(Perm.BYPASS_SILENCE, true, true); @@ -152,8 +173,13 @@ public class Chat extends MiniPlugin addCommand(new BroadcastCommand(this)); addCommand(new ChatSlowCommand(this)); addCommand(new HelpCommand(this)); + addCommand(new ListEmotesCommand(this)); + } - ChatExtraCommand.addCommands(this); + public void setFormatComponents(ChatFormatComponent... components) + { + _formatComponents.clear(); + _formatComponents.addAll(Arrays.asList(components)); } public CoreClientManager getClientManager() @@ -272,7 +298,7 @@ public class Chat extends MiniPlugin } else { - player.sendMessage(F.main(getName(),"Chat is silenced for " + F.time(UtilTime.MakeStr(_silenceLength - System.currentTimeMillis(), 1)) + ".")); + player.sendMessage(F.main(getName(), "Chat is silenced for " + F.time(UtilTime.MakeStr(_silenceLength - System.currentTimeMillis(), 1)) + ".")); } } @@ -314,7 +340,7 @@ public class Chat extends MiniPlugin return content; } - private JSONArray buildPartsArray(String ...messages) + private JSONArray buildPartsArray(String... messages) { JSONArray parts = new JSONArray(); @@ -326,7 +352,7 @@ public class Chat extends MiniPlugin return parts; } - private JSONObject buildRequestObject(Player player, String ...messages) + private JSONObject buildRequestObject(Player player, String... messages) { JSONObject content = new JSONObject(); @@ -450,20 +476,24 @@ public class Chat extends MiniPlugin public static void trustCert() throws Exception { TrustManager[] trustAllCerts = new TrustManager[] - { - new X509TrustManager() - { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(X509Certificate[] certs, String authType) { } - - public void checkServerTrusted(X509Certificate[] certs, String authType) { } - - } - }; + new X509TrustManager() + { + public java.security.cert.X509Certificate[] getAcceptedIssuers() + { + return null; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) + { + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) + { + } + + } + }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); @@ -476,7 +506,7 @@ public class Chat extends MiniPlugin HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); } - public List getReplacements(JSONObject responseJson, String ...originalMessages) + public List getReplacements(JSONObject responseJson, String... originalMessages) { // Again, no content means no good if (!responseJson.containsKey("content")) @@ -530,7 +560,7 @@ public class Chat extends MiniPlugin return replacements; } - public List filterMessages(Player player, boolean useBackup, String ...messages) + public List filterMessages(Player player, boolean useBackup, String... messages) { if (_clientManager.Get(player).hasPermission(Perm.BYPASS_CHAT_FILTER) && _preferencesManager.get(player).isActive(Preference.BYPASS_CHAT_FILTER)) @@ -595,36 +625,21 @@ public class Chat extends MiniPlugin return filterMessages(player, message).get(0); } - public void addFilter(Function restriction, FilterPriority priority) - { - Validate.isTrue(priority != null, "Priority must not be null."); - - switch (priority) - { - case HIGH: - _highPriorityFilters.add(restriction); - break; - case LOW: - _lowPriorityFilters.add(restriction); - } - } - /** * Check whether the given player is allowed to send a given message in chat. * This method will also inform the player of why they are not allowed to, if inform is true. * It will check last sent message, but will not handle updating it. - * @param sender - The player who is sending the message + * + * @param sender - The player who is sending the message * @param message - The message the player is attempting to send - * @param inform - Whether the player should be informed if they cannot chat + * @param inform - Whether the player should be informed if they cannot chat * @return - Whether this player can chat */ public boolean canChat(Player sender, String message, boolean inform) { CoreClient client = _clientManager.Get(sender); - if (_incognitoManager != null && _incognitoManager.Get(sender).Status - && !message.startsWith(CommunityManager.CHAT_PREFIX) - && !UtilServer.isTestServer()) + if (_incognitoManager != null && _incognitoManager.Get(sender).Status && !UtilServer.isTestServer()) { if (inform) { @@ -729,15 +744,17 @@ public class Chat extends MiniPlugin @EventHandler public void preventMe(PlayerCommandPreprocessEvent event) { - if (event.getMessage().toLowerCase().startsWith("/me ") - || event.getMessage().toLowerCase().startsWith("/bukkit") - || event.getMessage().toLowerCase().startsWith("/minecraft")) + if (event.getPlayer().isOp()) { - if (!event.getPlayer().isOp()) - { - event.getPlayer().sendMessage(F.main(getName(), "Nope, not allowed!")); - event.setCancelled(true); - } + return; + } + + String lowerCase = event.getMessage().toLowerCase(); + + if (lowerCase.startsWith("/me ") || lowerCase.startsWith("/bukkit") || lowerCase.startsWith("/minecraft")) + { + event.getPlayer().sendMessage(F.main(getName(), "Nope, not allowed!")); + event.setCancelled(true); } } @@ -751,62 +768,118 @@ public class Chat extends MiniPlugin } } - @EventHandler(priority = EventPriority.LOWEST) - public void filterChat(AsyncPlayerChatEvent event) - { - if (event.isCancelled()) - return; - - if (event.isAsynchronous()) - { - Player player = event.getPlayer(); - - String message = filterMessage(player, true, event.getMessage()); - - if (message.isEmpty()) - { - event.setCancelled(true); - } - else - { - event.setMessage(message); - } - } - } - - @EventHandler(priority = EventPriority.LOW) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void handleChat(AsyncPlayerChatEvent event) { - if (event.isCancelled()) - { - return; - } - - Player sender = event.getPlayer(); - - for (Function filter : _highPriorityFilters) - { - if (filter.apply(event)) - { - event.setCancelled(true); - return; - } - } - - if (!canChat(sender, event.getMessage(), true)) + if (!event.isAsynchronous()) { event.setCancelled(true); return; } - event.setMessage(decapsifyIfNecessary(sender, event.getMessage())); + Player sender = event.getPlayer(); + String message = event.getMessage(); - updateLastMessage(sender, event.getMessage()); + CoreClient client = _clientManager.Get(sender); + UserPreferences preferences = _preferencesManager.get(sender); + ChatChannel channel = ChatChannel.PUBLIC; - if (event.isAsynchronous()) + for (ChatChannel other : ChatChannel.values()) { - event.getRecipients().removeIf(player -> !_preferencesManager.get(player).isActive(Preference.SHOW_CHAT)); + if (other.getPrefix() != null && message.startsWith(other.getPrefix())) + { + channel = other; + message = message.substring(1); + break; + } } + + if (channel.isModerated() && !canChat(sender, message)) + { + event.setCancelled(true); + return; + } + + event.setMessage(message); + + if (event.isCancelled() || message.isEmpty()) + { + event.setCancelled(true); + return; + } + + FormatPlayerChatEvent customEvent = new FormatPlayerChatEvent(event, channel, _formatComponents); + UtilServer.CallEvent(customEvent); + + if (customEvent.isCancelled() || customEvent.getRecipients().isEmpty()) + { + event.setCancelled(true); + return; + } + + message = customEvent.getMessage(); + + if (channel.isModerated()) + { + event.getRecipients().removeIf(player -> !preferences.isActive(Preference.SHOW_CHAT)); + } + + if (customEvent.isFiltered()) + { + message = decapsifyIfNecessary(sender, message); + message = filterMessage(sender, true, message); + } + + if (message.isEmpty()) + { + event.setCancelled(true); + return; + } + + if (client.hasPermission(Perm.CHAT_EXTRA_COMMAND)) + { + ChatColor colour = null; + + if (preferences.isActive(Preference.COLOR_SUFFIXES)) + { + colour = client.getRealOrDisguisedPrimaryGroup().getColor(); + } + + for (Entry entry : EMOTES.entrySet()) + { + message = message.replace(entry.getValue(), (colour == null ? "" : colour) + entry.getKey() + customEvent.getMessageColour()); + } + } + + updateLastMessage(sender, message); + event.setCancelled(true); + + if (client.hasPermission(Perm.ALLOW_COLOUR)) + { + message = ChatColor.translateAlternateColorCodes('&', message); + } + + final TextComponent formatted = new TextComponent(""); + List components = customEvent.getFormatComponents(); + + for (ChatFormatComponent component : components) + { + BaseComponent text = component.getText(sender); + + if (text.toPlainText().isEmpty()) + { + continue; + } + + formatted.addExtra(text); + formatted.addExtra(" "); + } + + TextComponent messageContent = new TextComponent(message); + messageContent.setColor(customEvent.getMessageColour()); + formatted.addExtra(messageContent); + + event.getRecipients().forEach(player -> player.spigot().sendMessage(formatted)); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/ChatChannel.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/ChatChannel.java new file mode 100644 index 000000000..458513dd4 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/ChatChannel.java @@ -0,0 +1,29 @@ +package mineplex.core.chat; + +public enum ChatChannel +{ + + PUBLIC(null, true), + PARTY("@", false), + COMMUNITY("!", false), + TEAM("#", true); + + private final String _prefix; + private final boolean _moderated; + + ChatChannel(String prefix, boolean moderated) + { + _prefix = prefix; + _moderated = moderated; + } + + public String getPrefix() + { + return _prefix; + } + + public boolean isModerated() + { + return _moderated; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/FilterPriority.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/FilterPriority.java deleted file mode 100644 index 71aae5059..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/FilterPriority.java +++ /dev/null @@ -1,7 +0,0 @@ -package mineplex.core.chat; - -public enum FilterPriority -{ - HIGH, - LOW; -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/IChatMessageFormatter.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/IChatMessageFormatter.java deleted file mode 100644 index 94a7f1dac..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/IChatMessageFormatter.java +++ /dev/null @@ -1,21 +0,0 @@ -package mineplex.core.chat; - -import org.bukkit.entity.Player; - -/** - * This is an interface that provides a method to format chat message. - * Needed for AntiSpam's shadow mute feature. - * - * @author Shaun Bennett - */ -public interface IChatMessageFormatter -{ - /** - * Returns the proper format for the chat message to be sent - * - * @param player Player sending the message - * @param message The message the player is trying to send - * @return the format of the chat message, - */ - public ChatFormat getChatFormat(Player player, String message); -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/MessageData.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/MessageData.java index 770389534..b4f5dd9c1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/MessageData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/MessageData.java @@ -2,18 +2,14 @@ package mineplex.core.chat; public class MessageData { - private String _message; - private long _timeSent; - public MessageData(String message) - { - this(message, System.currentTimeMillis()); - } + private final String _message; + private final long _timeSent; - public MessageData(String message, long timeSent) + MessageData(String message) { _message = message; - _timeSent = timeSent; + _timeSent = System.currentTimeMillis(); } public String getMessage() @@ -25,4 +21,4 @@ public class MessageData { return _timeSent; } -} +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/command/ListEmotesCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/command/ListEmotesCommand.java new file mode 100644 index 000000000..305625863 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/command/ListEmotesCommand.java @@ -0,0 +1,25 @@ +package mineplex.core.chat.command; + +import org.bukkit.entity.Player; + +import mineplex.core.chat.Chat; +import mineplex.core.chat.Chat.Perm; +import mineplex.core.command.CommandBase; +import mineplex.core.common.util.F; + +public class ListEmotesCommand extends CommandBase +{ + + public ListEmotesCommand(Chat plugin) + { + super(plugin, Perm.CHAT_EXTRA_COMMAND, "emotes"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage(F.main(Plugin.getName(), "Emotes List:")); + Chat.EMOTES.forEach((emote, how) -> caller.sendMessage(F.elem(how) + " -> " + F.elem(emote))); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/command/extra/ChatExtraCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/command/extra/ChatExtraCommand.java deleted file mode 100644 index 5e1889557..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/command/extra/ChatExtraCommand.java +++ /dev/null @@ -1,106 +0,0 @@ -package mineplex.core.chat.command.extra; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.bukkit.entity.Player; - -import mineplex.core.account.permissions.Permission; -import mineplex.core.chat.Chat; -import mineplex.core.command.CommandBase; -import mineplex.core.command.CommandCenter; -import mineplex.core.common.Pair; -import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilServer; -import mineplex.core.preferences.Preference; -import mineplex.core.recharge.Recharge; - -public class ChatExtraCommand extends CommandBase -{ - private static final long RECHARGE_TIME = 1000; - private static final String RECHARGE_FORMAT = "ChatPrefixCmd-%s"; - private static final List> DEFAULT_EXTRA_COMMANDS = new ArrayList<>(); - private final String _extra; - - static - { - addDefaultExtraCommand("ヽ༼ຈل͜ຈ༽ノ", "donger"); - addDefaultExtraCommand("¯\\_(ツ)_/¯", "shrug"); - addDefaultExtraCommand("༼ つ ◕_◕ ༽つ", "ameno"); - addDefaultExtraCommand("(╯°□°)╯︵ ┻━┻", "tableflip"); - addDefaultExtraCommand("┬─┬ノ(ಠ_ಠノ)", "tablesit"); - addDefaultExtraCommand("(౮⦦ʖ౮)", "lenny"); - addDefaultExtraCommand("ಠ_ಠ", "disapproval"); - addDefaultExtraCommand("(☞゚ヮ゚)☞", "same", "fingerguns", "thisguy"); - addDefaultExtraCommand("ლ(ಥ Д ಥ )ლ", "why"); - addDefaultExtraCommand("(≖_≖)", "squint"); - } - - public ChatExtraCommand(Chat plugin, Permission permission, String extra, String... aliases) - { - super(plugin, permission, aliases); - - _extra = extra; - - CommandCenter.ALLOW_SPAM_IF_LAST.addAll(Arrays.asList(aliases)); - } - - public ChatExtraCommand(Chat plugin, String extra, String... aliases) - { - this(plugin, Chat.Perm.CHAT_EXTRA_COMMAND, extra, aliases); - } - - public static void addCommands(Chat plugin) - { - for (Pair defaultCommand : DEFAULT_EXTRA_COMMANDS) - { - plugin.addCommand(new ChatExtraCommand(plugin, defaultCommand.getRight(), defaultCommand.getLeft())); - } - - plugin.addCommand(new ChatExtraCommand(plugin, Chat.Perm.MOD_CHAT_EXTRA_COMMAND, C.cGold + "›⪾", "fishy")); - plugin.addCommand(new ChatExtraCommand(plugin, Chat.Perm.ADMIN_CHAT_EXTRA_COMMAND, C.cPurple + "(ノ◕ヮ◕)ノ*:・゚✧", "magic")); - } - - public static void addDefaultExtraCommand(String extra, String... aliases) - { - DEFAULT_EXTRA_COMMANDS.add(Pair.create(aliases, extra)); - } - - private String getRechargeName() - { - return String.format(RECHARGE_FORMAT, _extra); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (!Recharge.Instance.use(caller, getRechargeName(), RECHARGE_TIME, false, false)) - { - reply(caller, "Please wait before using that command again."); - return; - } - - UtilServer.runAsync(() -> - { - String chatMessage = ""; - - if (args.length > 0) - { - chatMessage = Plugin.filterMessage(caller, Arrays.stream(args).collect(Collectors.joining(" "))) + " "; - } - - if (Plugin.getPreferencesManager().get(caller).isActive(Preference.COLOR_SUFFIXES)) - { - chatMessage += Plugin.getClientManager().Get(caller).getRealOrDisguisedPrimaryGroup().getColor() + _extra; - } - else - { - chatMessage += _extra; - } - - caller.chat(chatMessage.trim()); - }); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/event/FormatPlayerChatEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/event/FormatPlayerChatEvent.java new file mode 100644 index 000000000..45ae5235a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/event/FormatPlayerChatEvent.java @@ -0,0 +1,109 @@ +package mineplex.core.chat.event; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.md_5.bungee.api.ChatColor; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerEvent; + +import mineplex.core.chat.ChatChannel; +import mineplex.core.chat.format.ChatFormatComponent; + +public class FormatPlayerChatEvent extends PlayerEvent implements Cancellable +{ + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + public static HandlerList getHandlerList() + { + return HANDLER_LIST; + } + + private final AsyncPlayerChatEvent _parentEvent; + private final ChatChannel _chatChannel; + private final List _formatComponents; + private ChatColor _messageColour; + private boolean _filtered, _cancelled; + + public FormatPlayerChatEvent(AsyncPlayerChatEvent parentEvent, ChatChannel chatChannel, List formatComponents) + { + super(parentEvent.getPlayer()); + + _parentEvent = parentEvent; + _chatChannel = chatChannel; + _formatComponents = new ArrayList<>(formatComponents); + _messageColour = ChatColor.WHITE; + _filtered = true; + _cancelled = parentEvent.isCancelled(); + } + + public List getFormatComponents() + { + return _formatComponents; + } + + public void setMessage(String message) + { + _parentEvent.setMessage(message); + } + + public String getMessage() + { + return _parentEvent.getMessage(); + } + + public Set getRecipients() + { + return _parentEvent.getRecipients(); + } + + public ChatChannel getChatChannel() + { + return _chatChannel; + } + + public void setMessageColour(ChatColor messageColour) + { + _messageColour = messageColour; + } + + public ChatColor getMessageColour() + { + return _messageColour; + } + + public void setFiltered(boolean filtered) + { + _filtered = filtered; + } + + public boolean isFiltered() + { + return _filtered; + } + + @Override + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + @Override + public HandlerList getHandlers() + { + return HANDLER_LIST; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/format/ChatFormatComponent.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/format/ChatFormatComponent.java new file mode 100644 index 000000000..57415b143 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/format/ChatFormatComponent.java @@ -0,0 +1,12 @@ +package mineplex.core.chat.format; + +import net.md_5.bungee.api.chat.BaseComponent; + +import org.bukkit.entity.Player; + +public interface ChatFormatComponent +{ + + BaseComponent getText(Player player); + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/format/LevelFormatComponent.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/format/LevelFormatComponent.java new file mode 100644 index 000000000..6c75bdcee --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/format/LevelFormatComponent.java @@ -0,0 +1,25 @@ +package mineplex.core.chat.format; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; + +import org.bukkit.entity.Player; + +import mineplex.core.achievement.AchievementManager; + +public class LevelFormatComponent implements ChatFormatComponent +{ + + private final AchievementManager _achievementManager; + + public LevelFormatComponent(AchievementManager achievementManager) + { + _achievementManager = achievementManager; + } + + @Override + public BaseComponent getText(Player player) + { + return new TextComponent(_achievementManager.getMineplexLevel(player)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/format/RankFormatComponent.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/format/RankFormatComponent.java new file mode 100644 index 000000000..a7779cbc1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/format/RankFormatComponent.java @@ -0,0 +1,38 @@ +package mineplex.core.chat.format; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.HoverEvent.Action; +import net.md_5.bungee.api.chat.TextComponent; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.permissions.PermissionGroup; + +public class RankFormatComponent implements ChatFormatComponent +{ + + private final CoreClientManager _clientManager; + + public RankFormatComponent(CoreClientManager clientManager) + { + _clientManager = clientManager; + } + + @Override + public BaseComponent getText(Player player) + { + PermissionGroup group = _clientManager.Get(player).getRealOrDisguisedPrimaryGroup(); + + TextComponent component = new TextComponent(group.getDisplay(false, true, false, false)); + component.setColor(group.getColor().asBungee()); + component.setBold(true); + component.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(group.getDisplay(true, true, true, true) + ChatColor.WHITE + "\n" + group.getDescription()) + .create())); + + return component; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java index 7eec9be4b..e150058f8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java @@ -21,7 +21,6 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -31,6 +30,8 @@ import mineplex.core.account.ILoginProcessor; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.chat.Chat; +import mineplex.core.chat.ChatChannel; +import mineplex.core.chat.event.FormatPlayerChatEvent; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; @@ -82,7 +83,6 @@ import mineplex.core.preferences.Preference; import mineplex.core.preferences.PreferencesManager; import mineplex.core.recharge.Recharge; import mineplex.core.serverConfig.ServerConfiguration; -import mineplex.core.treasure.animation.animations.reward.CommonRewardAnimation; import mineplex.serverdata.Region; import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.data.PlayerStatus; @@ -115,7 +115,6 @@ public class CommunityManager extends MiniDbClientPlugin COMMUNITY_UNINVITE_STAFF_COMMAND, } - public final static String CHAT_PREFIX = "!"; public final static String COMMUNITY_CHAT_KEY = "core.communities.chat.selected"; private final static int MAX_NAME_LENGTH = 15; @@ -992,10 +991,10 @@ public class CommunityManager extends MiniDbClientPlugin } } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onChat(AsyncPlayerChatEvent event) + @EventHandler(ignoreCancelled = true) + public void onChat(FormatPlayerChatEvent event) { - if (!event.getMessage().startsWith(CHAT_PREFIX)) + if (event.getChatChannel() != ChatChannel.COMMUNITY) { return; } @@ -1031,14 +1030,6 @@ public class CommunityManager extends MiniDbClientPlugin } } - String newMessage = event.getMessage().substring(1).trim(); - - if (newMessage.length() == 0) - { - UtilPlayer.message(sender, F.main(getName(), "You can't send an empty message.")); - return; - } - Community target = _loadedCommunities.get(memberData.getCommunityChattingTo()); if (target == null || !target.getMembers().containsKey(event.getPlayer().getUniqueId())) @@ -1049,7 +1040,7 @@ public class CommunityManager extends MiniDbClientPlugin { if (Recharge.Instance.use(sender, "Community Chat to " + target.getId(), target.getChatDelay(), false, false)) { - new CommunityChat(sender.getName(), target.getId(), newMessage).publish(); + new CommunityChat(sender.getName(), target.getId(), event.getMessage()).publish(); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java index 83ff95fca..03973f105 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/manager/PartyJoinManager.java @@ -1,12 +1,16 @@ package mineplex.core.party.manager; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Random; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.TextComponent; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -20,6 +24,9 @@ import com.google.common.collect.Lists; import mineplex.core.Managers; import mineplex.core.account.CoreClientManager; +import mineplex.core.chat.ChatChannel; +import mineplex.core.chat.event.FormatPlayerChatEvent; +import mineplex.core.chat.format.ChatFormatComponent; import mineplex.core.command.CommandCenter; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilItem; @@ -44,10 +51,27 @@ import mineplex.serverdata.data.MinecraftServer; */ public class PartyJoinManager implements Listener { + private final TwoFactorAuth _twofactor = Managers.require(TwoFactorAuth.class); private final PartyManager _plugin; private final int _maxPlayers; - + private final ChatFormatComponent[] _partyComponents = + { + sender -> + { + TextComponent component = new TextComponent("PARTY"); + component.setColor(ChatColor.DARK_PURPLE); + component.setBold(true); + return component; + }, + sender -> + { + TextComponent component = new TextComponent(sender.getName()); + component.setColor(ChatColor.WHITE); + component.setBold(true); + return component; + } + }; private final Map _pendingTransfers = new ConcurrentHashMap<>(); public PartyJoinManager(PartyManager plugin) @@ -356,4 +380,27 @@ public class PartyJoinManager implements Listener CommandCenter.getCommands().get("party").Execute(event.getPlayer(), new String[0]); } } + + @EventHandler + public void onChat(FormatPlayerChatEvent event) + { + if (event.getChatChannel() != ChatChannel.PARTY) + { + return; + } + + Party party = _plugin.getPartyByPlayer(event.getPlayer()); + + if (party == null) + { + event.getPlayer().sendMessage(F.main(_plugin.getName(), "You are not in a Party!")); + event.setCancelled(true); + return; + } + + event.setMessageColour(ChatColor.LIGHT_PURPLE); + event.getRecipients().removeIf(other -> !party.isMember(other)); + event.getFormatComponents().clear(); + Collections.addAll(event.getFormatComponents(), _partyComponents); + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 998bbbf16..2adcd8e00 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -161,7 +161,7 @@ public class Clans extends JavaPlugin StatsManager statsManager = new StatsManager(this, _clientManager); EloManager eloManager = new EloManager(this, _clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, incognito, eloManager); - Chat chat = new Chat(); + Chat chat = require(Chat.class); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, require(FriendManager.class), chat); new MemoryFix(this); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index f61949ccc..9619dad38 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -25,7 +25,6 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; @@ -51,6 +50,8 @@ import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.achievement.AchievementManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; +import mineplex.core.chat.ChatChannel; +import mineplex.core.chat.event.FormatPlayerChatEvent; import mineplex.core.common.Pair; import mineplex.core.common.events.PlayerMessageEvent; import mineplex.core.common.util.C; @@ -329,7 +330,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat _clanDisplay = new ClansDisplay(plugin, this); _clanGame = new ClansGame(plugin, this); _clanUtility = new ClansUtility(this); - _tutorial = new TutorialManager(plugin, clientManager, donationManager, chat, hologramManager, this, _npcManager, _taskManager); + _tutorial = new TutorialManager(plugin, clientManager, donationManager, hologramManager, this, _npcManager, _taskManager); _itemMapManager = new ItemMapManager(this, _tutorial, _worldEvent); new TntGeneratorManager(plugin, this); new SupplyDropManager(plugin); @@ -948,37 +949,52 @@ public class ClansManager extends MiniClientPlugin implements IRelat private void handleClanChat(Player player, String message, ClanInfo clan, String rank) { + message = _chat.filterMessage(player, true, message); + + if (message.isEmpty()) + { + return; + } + for (Player cur : clan.getOnlinePlayers()) { - message = _chat.filterMessage(player, message); - UtilPlayer.message(cur, String.format(rank + C.cAqua + "%s " + C.cDAqua + "%s", player.getName(), message)); } } private void handleAllyChat(Player player, String message, ClanInfo clan, String rank) { - List recipients = new ArrayList<>(); - - clan.getOnlinePlayers().forEach(recipients::add); + final String filtered = _chat.filterMessage(player, true, message); + + if (filtered.isEmpty()) + { + return; + } + + List recipients = new ArrayList<>(clan.getOnlinePlayers()); for (String allyName : clan.getAllyMap().keySet()) { ClanInfo ally = _clanUtility.getClanByClanName(allyName); if (ally == null) continue; - - ally.getOnlinePlayers().forEach(recipients::add); + + recipients.addAll(ally.getOnlinePlayers()); } - - final String filtered = _chat.filterMessage(player, message); - + recipients.forEach(p -> UtilPlayer.message(p, String.format(rank + C.cDGreen + clan.getName() + " " + C.cDGreen + "%s " + C.cGreen + "%s", player.getName(), filtered))); recipients.clear(); } - private void handleRegularChat(AsyncPlayerChatEvent event, ClanInfo clan, String rank) + private void handleRegularChat(FormatPlayerChatEvent event, ClanInfo clan, String rank) { + String message = _chat.filterMessage(event.getPlayer(), true, event.getMessage()); + + if (message.isEmpty()) + { + return; + } + if (clan == null) { for (Player other : event.getRecipients()) @@ -995,8 +1011,6 @@ public class ClansManager extends MiniClientPlugin implements IRelat List recipients = new ArrayList<>(); - String message = event.getMessage();//_chat.filterMessage(event.getPlayer(), event.getMessage()); - for (Player other : event.getRecipients()) { if (_tutorial.inTutorial(other)) @@ -1046,9 +1060,19 @@ public class ClansManager extends MiniClientPlugin implements IRelat } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void handlePlayerChat(AsyncPlayerChatEvent event) + @EventHandler(ignoreCancelled = true) + public void handlePlayerChat(FormatPlayerChatEvent event) { + if (event.getChatChannel() != ChatChannel.PUBLIC) + { + if (event.getChatChannel() == ChatChannel.TEAM) + { + event.setCancelled(true); + } + + return; + } + ClientClan client = Get(event.getPlayer()); if (client == null) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java index d3b9ab399..398fe6de4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java @@ -2,19 +2,17 @@ package mineplex.game.clans.tutorial; import java.util.ArrayList; import java.util.EnumMap; -import java.util.Iterator; import java.util.List; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.chat.Chat; -import mineplex.core.chat.FilterPriority; import mineplex.core.common.events.PlayerRecieveBroadcastEvent; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -48,7 +46,7 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement private EnumMap _tutorialMap; private EnumMap _shopMap; // Don't need to do anything with shops currently - public TutorialManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Chat chat, HologramManager hologram, ClansManager clansManager, NpcManager npcManager, TaskManager taskManager) + public TutorialManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, HologramManager hologram, ClansManager clansManager, NpcManager npcManager, TaskManager taskManager) { super("Clans Tutorial", plugin); @@ -61,30 +59,6 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement addTutorial(TutorialType.MAIN, new ClansMainTutorial(plugin, clansManager, _clansMessageManager, hologram, npcManager, taskManager)); - chat.addFilter(event -> - { - if (inTutorial(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "You are not allowed to speak while in a tutorial.")); - - return Boolean.TRUE; - } - - Iterator recipients = event.getRecipients().iterator(); - - while (recipients.hasNext()) - { - Player recipient = recipients.next(); - - if (inTutorial(recipient)) - { - recipients.remove(); - } - } - - return Boolean.FALSE; - }, FilterPriority.HIGH); - generatePermissions(); } @@ -123,6 +97,21 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement event.setCancelled(true); } + + @EventHandler + public void playerChat(AsyncPlayerChatEvent event) + { + Player player = event.getPlayer(); + + if (inTutorial(player)) + { + player.sendMessage(F.main("Clans", "You are not allowed to speak while in a tutorial.")); + event.setCancelled(true); + return; + } + + event.getRecipients().removeIf(this::inTutorial); + } @Override public void addCommands() diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index c3df220f9..161ce2ae7 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -157,8 +157,7 @@ public class ClansHub extends JavaPlugin ClansTransferManager serverManager = new ClansTransferManager(this, clientManager, donationManager, partyManager, portal); - Chat chat = new Chat(); - new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); + new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, require(Chat.class)); new MemoryFix(this); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.CLANS_HUB); new CustomTagFix(this, packetHandler); diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java index e61554cf7..6c50df527 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/HubManager.java @@ -53,8 +53,10 @@ import mineplex.core.blockrestore.BlockRestore; import mineplex.core.bonuses.BonusManager; import mineplex.core.boosters.BoosterManager; import mineplex.core.botspam.BotSpamManager; +import mineplex.core.chat.Chat; import mineplex.core.chat.ChatFormat; -import mineplex.core.chat.IChatMessageFormatter; +import mineplex.core.chat.format.LevelFormatComponent; +import mineplex.core.chat.format.RankFormatComponent; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; @@ -126,7 +128,7 @@ import net.minecraft.server.v1_8_R3.EntityPlayer; /** * Main manager for clans hub */ -public class HubManager extends MiniPlugin implements IChatMessageFormatter +public class HubManager extends MiniPlugin { public enum Perm implements Permission { @@ -208,6 +210,16 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, petManager, _treasureManager, boosterManager, punish); new MenuManager(_plugin); + require(Chat.class).setFormatComponents( + new LevelFormatComponent(achievementManager), + new RankFormatComponent(clientManager), + player -> + { + TextComponent component = new TextComponent(player.getName()); + component.setColor(net.md_5.bungee.api.ChatColor.YELLOW); + return component; + } + ); _petManager = petManager; _partyManager = partyManager; @@ -528,104 +540,15 @@ public class HubManager extends MiniPlugin implements IChatMessageFormatter } } - @EventHandler - public void PlayerChat(AsyncPlayerChatEvent event) + @EventHandler(ignoreCancelled = true) + public void playerChat(AsyncPlayerChatEvent event) { - if (event.isCancelled()) - return; - - //Dont Let Chat Near Spawn! - if (UtilMath.offset2d(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).hasPermission(Perm.SPAWN_PM)) + //Don't Let Chat Near Spawn! + if (UtilMath.offset2dSquared(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).hasPermission(Perm.SPAWN_PM)) { UtilPlayer.message(event.getPlayer(), F.main("Chat", "You must leave spawn before you can chat!")); event.setCancelled(true); - return; } - - Player player = event.getPlayer(); - String playerName = player.getName(); - - PermissionGroup group = _clientManager.Get(player).getRealOrDisguisedPrimaryGroup(); - - //Level Prefix - String levelStr = _achievementManager.getMineplexLevel(player); - - //Rank Prefix - String rankStr = ""; - if (!group.getDisplay(false, false, false, false).isEmpty()) - { - rankStr = group.getDisplay(true, true, true, false) + " "; - } - //Party Chat - if (event.getMessage().charAt(0) == '@') - { - Party party = _partyManager.getPartyByPlayer(player); - if (party != null) - { - event.setMessage(event.getMessage().substring(1, event.getMessage().length())); - event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s"); - - event.getRecipients().removeIf(other -> !party.getMembers().contains(other)); - } - else - { - UtilPlayer.message(player, F.main("Party", "You are not in a Party.")); - event.setCancelled(true); - } - - return; - } - else - { - TextComponent rankComponent = new TextComponent(rankStr); - TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName); - TextComponent component = new TextComponent(); - - rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(group.getDisplay(true, true, true, true) + ChatColor.WHITE + "\n" + group.getDescription()).create())); - - component.setText(levelStr); - component.addExtra(rankComponent); - component.addExtra(playerNameText); - component.addExtra(" " + ChatColor.WHITE + event.getMessage()); - - if (!event.isCancelled()) - { - for (Player other : event.getRecipients()) - { - other.spigot().sendMessage(component); - } - } - event.setCancelled(true); - } - } - - @Override - public ChatFormat getChatFormat(Player player, String message) - { - PermissionGroup group = _clientManager.Get(player).getRealOrDisguisedPrimaryGroup(); - - //Level Prefix - String levelStr = _achievementManager.getMineplexLevel(player); - - //Rank Prefix - String rankStr = ""; - if (!group.getDisplay(false, false, false, false).isEmpty()) - { - rankStr = group.getDisplay(true, true, true, false) + " "; - } - - TextComponent rankComponent = new TextComponent(rankStr); - TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + "%1$s"); - TextComponent component = new TextComponent(); - - rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(group.getDisplay(true, true, true, true) + ChatColor.WHITE + "\n" + group.getDescription()).create())); - - component.setText(levelStr); - component.addExtra(rankComponent); - component.addExtra(playerNameText); - component.addExtra(" " + ChatColor.WHITE + "%2$s"); - - return new ChatFormat(component.toLegacyText(), false); } @EventHandler diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 6d0bf9807..4d39c76d5 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -157,8 +157,7 @@ public class Hub extends JavaPlugin implements IRelation require(MineplexGameManager.class); - Chat chat = new Chat(); - new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); + new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, require(Chat.class)); new MemoryFix(this); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.HUB); new CustomTagFix(this, packetHandler); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index fe6588494..d41d7be4d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -3,16 +3,13 @@ package mineplex.hub; import java.util.List; import java.util.UUID; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.HoverEvent.Action; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import net.minecraft.server.v1_8_R3.EntityInsentient; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.WorldServer; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -44,8 +41,9 @@ import mineplex.core.benefit.BenefitManager; import mineplex.core.bonuses.BonusManager; import mineplex.core.boosters.BoosterManager; import mineplex.core.botspam.BotSpamManager; -import mineplex.core.chat.ChatFormat; -import mineplex.core.chat.IChatMessageFormatter; +import mineplex.core.chat.Chat; +import mineplex.core.chat.format.LevelFormatComponent; +import mineplex.core.chat.format.RankFormatComponent; import mineplex.core.common.generator.VoidGenerator; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -73,7 +71,6 @@ import mineplex.core.mission.MissionTrackerType; import mineplex.core.noteblock.MusicManager; import mineplex.core.notifier.NotificationManager; import mineplex.core.npc.NpcManager; -import mineplex.core.party.Party; import mineplex.core.party.PartyManager; import mineplex.core.pet.PetManager; import mineplex.core.poll.PollManager; @@ -113,7 +110,7 @@ import mineplex.hub.world.HubWorldManager; import mineplex.minecraft.game.core.combat.DeathMessageType; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; -public class HubManager extends MiniClientPlugin implements IChatMessageFormatter +public class HubManager extends MiniClientPlugin { public enum Perm implements Permission { @@ -198,8 +195,17 @@ public class HubManager extends MiniClientPlugin implements IChatMess //new SoccerManager(this, _gadgetManager); new MenuManager(_plugin); - AntiSpamManager antiSpam = new AntiSpamManager(); - antiSpam.setMessageFormatter(this); + require(AntiSpamManager.class); + require(Chat.class).setFormatComponents( + new LevelFormatComponent(achievementManager), + new RankFormatComponent(clientManager), + player -> + { + TextComponent component = new TextComponent(player.getName()); + component.setColor(ChatColor.YELLOW); + return component; + } + ); _petManager = petManager; _partyManager = partyManager; @@ -408,110 +414,15 @@ public class HubManager extends MiniClientPlugin implements IChatMess } } - @EventHandler - public void PlayerChat(AsyncPlayerChatEvent event) + @EventHandler(ignoreCancelled = true) + public void playerChat(AsyncPlayerChatEvent event) { - if (event.isCancelled()) - return; - - //Dont Let Chat Near Spawn! + //Don't Let Chat Near Spawn! if (UtilMath.offset2dSquared(GetSpawn(), event.getPlayer().getLocation()) == 0 && !_clientManager.Get(event.getPlayer()).hasPermission(Perm.SPAWN_PM)) { UtilPlayer.message(event.getPlayer(), F.main("Chat", "You must leave spawn before you can chat!")); event.setCancelled(true); - return; } - - Player player = event.getPlayer(); - String playerName = player.getName(); - PermissionGroup group = GetClients().Get(player).getRealOrDisguisedPrimaryGroup(); - - //Level Prefix - String levelStr = _achievementManager.getMineplexLevel(player); - - //Rank Prefix - String rankStr = ""; - if (!group.getDisplay(false, false, false, false).isEmpty()) - { - rankStr = group.getDisplay(true, true, true, false) + " "; - } - //Party Chat - if (event.getMessage().charAt(0) == '@') - { - Party party = _partyManager.getPartyByPlayer(player); - if (party != null) - { - if (event.getMessage().length() > 1) - { - event.setMessage(event.getMessage().substring(1, event.getMessage().length()).trim()); - event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + playerName + " " + C.cPurple + "%2$s"); - - event.getRecipients().removeIf(other -> !party.getMembers().contains(other)); - } - else - { - UtilPlayer.message(player, F.main("Party", "Where's the message?")); - event.setCancelled(true); - } - } - else - { - UtilPlayer.message(player, F.main("Party", "You are not in a Party.")); - event.setCancelled(true); - } - - } - else - { - TextComponent rankComponent = new TextComponent(rankStr); - TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + playerName); - TextComponent component = new TextComponent(); - - rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(group.getDisplay(true, true, true, true) + ChatColor.WHITE + "\n" + group.getDescription()).create())); - - component.setText(levelStr); - component.addExtra(rankComponent); - component.addExtra(playerNameText); - component.addExtra(" " + ChatColor.WHITE + event.getMessage()); - - if (!event.isCancelled()) - { - for (Player other : event.getRecipients()) - { - other.spigot().sendMessage(component); - } - } - event.setCancelled(true); - } - } - - @Override - public ChatFormat getChatFormat(Player player, String message) - { - PermissionGroup group = GetClients().Get(player).getRealOrDisguisedPrimaryGroup(); - - //Level Prefix - String levelStr = _achievementManager.getMineplexLevel(player); - - //Rank Prefix - String rankStr = ""; - if (!group.getDisplay(false, false, false, false).isEmpty()) - { - rankStr = group.getDisplay(true, true, true, false) + " "; - } - - TextComponent rankComponent = new TextComponent(rankStr); - TextComponent playerNameText = new TextComponent(ChatColor.YELLOW + "%1$s"); - TextComponent component = new TextComponent(); - - rankComponent.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(group.getDisplay(true, true, true, true) + ChatColor.WHITE + "\n" + group.getDescription()).create())); - - component.setText(levelStr); - component.addExtra(rankComponent); - component.addExtra(playerNameText); - component.addExtra(" " + ChatColor.WHITE + "%2$s"); - - return new ChatFormat(component.toLegacyText(), false); } @Override diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java index 2aeb88067..2311ddb61 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java @@ -14,7 +14,6 @@ import com.mojang.authlib.GameProfile; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.bonuses.BonusRepository; -import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; import mineplex.core.common.Constants; import mineplex.core.creature.Creature; @@ -70,8 +69,7 @@ public class StaffServer extends JavaPlugin InventoryManager inventoryManager = new InventoryManager(this, clientManager); BonusRepository bonusRepository = new BonusRepository(this, null, donationManager); new AchievementManager(statsManager, clientManager, donationManager, null, eloManager); - new Chat(); - new MemoryFix(this); + new MemoryFix(this); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.HUB); require(PacketHandler.class); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 1f79b2a0f..8af360834 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -165,7 +165,7 @@ public class Arcade extends JavaPlugin EloManager eloManager = new EloManager(this, clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); FriendManager friendManager = require(FriendManager.class); - Chat chat = new Chat(); + Chat chat = require(Chat.class); new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 58ebd7bae..12fe3395c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -1651,8 +1651,7 @@ public abstract class Game extends ListenerComponent implements Lifetimed if (!Manager.IsRewardStats()) return; - if (!_stats.containsKey(player)) - _stats.put(player, new HashMap<>()); + _stats.computeIfAbsent(player, k -> new HashMap<>()); if (global) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java index 35e830491..c5e5d4a60 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java @@ -1,34 +1,34 @@ package nautilus.game.arcade.managers.chat; import java.text.DecimalFormat; -import java.util.AbstractMap; -import java.util.AbstractMap.SimpleEntry; -import java.util.Collection; +import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Map; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.HoverEvent.Action; +import net.md_5.bungee.api.chat.TextComponent; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.jooq.tools.json.JSONObject; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; -import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.chat.ChatChannel; +import mineplex.core.chat.event.FormatPlayerChatEvent; +import mineplex.core.chat.format.LevelFormatComponent; +import mineplex.core.chat.format.RankFormatComponent; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.party.Party; +import mineplex.core.common.util.UtilServer; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game; -import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.managers.GameHostManager; public class GameChatManager implements Listener { @@ -41,374 +41,232 @@ public class GameChatManager implements Listener private final ArcadeManager _manager; - private LinkedList _chatStats; + private final LinkedList _chatStats; - public boolean TeamSpy; + public boolean TeamSpy = true; public GameChatManager(ArcadeManager manager) { _manager = manager; - - _manager.getPluginManager().registerEvents(this, _manager.getPlugin()); + UtilServer.RegisterEvents(this); _chatStats = new LinkedList<>(); + manager.GetChat().setFormatComponents( + new LevelFormatComponent(_manager.GetAchievement()), + new RankFormatComponent(_manager.GetClients()), + player -> + { + TextComponent component = new TextComponent(player.getName()); + component.setColor(_manager.GetColor(player).asBungee()); + return component; + } + ); - TeamSpy = true; - generatePermissions(); } - + private void generatePermissions() { - PermissionGroup.MOD.setPermission(Perm.TEAM_SPY, true, true); PermissionGroup.TRAINEE.setPermission(Perm.SPEC_ALWAYS_SPEAK, true, true); PermissionGroup.MOD.setPermission(Perm.SPEC_ALWAYS_HEAR, true, true); } - @EventHandler - public void MeCancel(PlayerCommandPreprocessEvent event) + @EventHandler(ignoreCancelled = true) + public void playerChat(FormatPlayerChatEvent event) { - if (event.getMessage().startsWith("/me ")) - { - UtilPlayer.message(event.getPlayer(), F.main("Mirror", "You can't see /me messages, are you a vampire?")); - event.setCancelled(true); - } - } + ChatChannel chatChannel = event.getChatChannel(); - @EventHandler - public void HandleChat(AsyncPlayerChatEvent event) - { - if (event.isCancelled() || event.getMessage().isEmpty()) + if (!chatChannel.isModerated()) + { return; - if (event.getMessage() == null) - return; - if (event.getMessage().trim().length() == 0) + } + + Game game = _manager.GetGame(); + + if (game == null) + { return; + } + + event.getFormatComponents().clear(); Player sender = event.getPlayer(); - String senderName = sender.getName(); + GameTeam team = game.GetTeam(sender); - String format; - String name; - String message; - - - //Dead Prefix - String dead = ""; - if (_manager.GetGame() != null) + if (team != null && !team.IsAlive(sender)) { - if (_manager.GetGame().GetTeam(sender) != null) + event.getFormatComponents().add(player -> { - if (!_manager.GetGame().IsAlive(sender)) - { - dead = C.cGray + "Dead " + C.Reset; - } + TextComponent component = new TextComponent("Dead"); + component.setColor(net.md_5.bungee.api.ChatColor.GRAY); + return component; + }); + } + + event.getFormatComponents().add(new LevelFormatComponent(_manager.GetAchievement())); + + GameHostManager hostManager = _manager.GetGameHostManager(); + String mpsName = null; + + if (hostManager.isHost(sender)) + { + if (hostManager.isEventServer()) + { + mpsName = "Event Host"; } - } - - PermissionGroup group = _manager.GetClients().Get(sender).getRealOrDisguisedPrimaryGroup(); - - //Level - String levelStr = ""; - if (!_manager.GetGameHostManager().isPrivateServer()) - levelStr = _manager.GetAchievement().getMineplexLevel(sender); - - String rankStr = ""; - //Rank Prefix & MPS Host Prefix - if (_manager.GetGameHostManager().isHost(event.getPlayer())) - { - if (_manager.GetGameHostManager().isEventServer()) - rankStr = C.cDGreen + C.Bold + "Event Host " + C.Reset; - else if (_manager.GetGameHostManager().isCommunityServer()) - rankStr = C.cDGreen + C.Bold + "MCS Host " + C.Reset; - else - rankStr = C.cDGreen + C.Bold + "MPS Host " + C.Reset; - } - else if (_manager.GetGameHostManager().isAdmin(event.getPlayer(), false)) - { - if (_manager.GetGameHostManager().isEventServer()) - rankStr = C.cDGreen + C.Bold + "Event Co-Host " + C.Reset; - else if (_manager.GetGameHostManager().isCommunityServer()) - rankStr = C.cDGreen + C.Bold + "MCS Co-Host " + C.Reset; - else - rankStr = C.cDGreen + C.Bold + "MPS Co-Host " + C.Reset; - } - else if (!group.getDisplay(false, false, false, false).isEmpty()) - { - rankStr = group.getDisplay(true, true, true, false) + " " + C.Reset; - } - - //Party Chat - if (event.getMessage().charAt(0) == '@') - { - Party party = _manager.getPartyManager().getPartyByPlayer(sender); - if (party != null) + else if (hostManager.isCommunityServer()) { - if (event.getMessage().length() > 1) - { - event.setMessage(event.getMessage().substring(1, event.getMessage().length())); - event.setFormat(levelStr + C.cDPurple + C.Bold + "Party " + C.cWhite + C.Bold + event.getPlayer().getName() + " " + C.cPurple + "%2$s"); - - event.getRecipients().removeIf(other -> !party.getMembers().contains(other)); - } - else - { - UtilPlayer.message(event.getPlayer(), F.main("Party", "Where's the message?")); - event.setCancelled(true); - } + mpsName = C.cDGreenB + "MCS Host " + C.Reset; } else { - UtilPlayer.message(event.getPlayer(), F.main("Party", "You are not in a Party.")); - event.setCancelled(true); + mpsName = C.cDGreenB + "MPS Host " + C.Reset; + } + } + else if (hostManager.isAdmin(sender, false)) + { + if (hostManager.isEventServer()) + { + mpsName = C.cDGreenB + "Event Co-Host " + C.Reset; + } + else if (hostManager.isCommunityServer()) + { + mpsName = C.cDGreenB + "MCS Co-Host " + C.Reset; + } + else + { + mpsName = C.cDGreenB + "MPS Co-Host " + C.Reset; } - - return; } - event.setFormat(levelStr + rankStr + senderName + " " + C.cWhite + "%2$s"); - - if (rankStr.equals("")) - format = levelStr; + if (mpsName == null) + { + event.getFormatComponents().add(new RankFormatComponent(_manager.GetClients())); + } else - format = event.getFormat().split(rankStr)[0]; + { + String finalRank = mpsName; - name = _manager.GetColor(sender) + sender.getName() + C.Reset; - if (event.getMessage().charAt(0) == '#') - message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + event.getMessage().substring(1); + event.getFormatComponents().add(player -> + { + TextComponent component = new TextComponent(finalRank); + + component.setColor(net.md_5.bungee.api.ChatColor.DARK_GREEN); + component.setBold(true); + + return component; + }); + } + + if (chatChannel == ChatChannel.TEAM && team != null && team.IsAlive(sender)) + { + event.getRecipients().removeIf(receiver -> + { + if (TeamSpy && _manager.GetClients().Get(receiver).hasPermission(Perm.TEAM_SPY)) + { + return false; + } + + GameTeam receiverTeam = game.GetTeam(receiver); + return receiverTeam == null || !receiverTeam.equals(team); + }); + + event.getFormatComponents().add(0, player -> + { + TextComponent component = new TextComponent("TEAM"); + component.setBold(true); + return component; + }); + } else - message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + event.getMessage(); - - if (_manager.GetGame() == null || _manager.GetGame().GetState() != GameState.Live) { - event.setFormat(levelStr + rankStr + senderName + " " + C.cWhite + "%2$s"); - - if (safeSend(sender, format, rankStr, group, name, message, event.getRecipients())) + if (!game.ShowEveryoneSpecChat) { - event.setCancelled(true); - } - - return; - } - - //Base Format - event.setFormat(dead + levelStr + rankStr + _manager.GetColor(sender) + senderName + " " + C.cWhite + "%2$s"); - - //Public/Private (Not If Player Dead) - if (_manager.GetGame() != null && _manager.GetGame().InProgress()) - { - boolean globalMessage = false; - - //Team - GameTeam team = _manager.GetGame().GetTeam(sender); - - if (team != null) - { - boolean isPriv = event.getMessage().charAt(0) == '#'; - - if (isPriv) - event.setMessage(event.getMessage().substring(1, event.getMessage().length())); - else - globalMessage = true; - - event.setFormat(isPriv ? C.cWhiteB + "Team " + dead + levelStr + rankStr + senderName + " " + C.cWhite + "%2$s" : dead + levelStr + rankStr + team.GetColor() + senderName + " " + C.cWhite + "%2$s"); - - if (rankStr.equals("")) - format = isPriv ? C.cWhiteB + "Team " + dead + levelStr : dead + levelStr; - else - format = event.getFormat().split(rankStr)[0]; - - name = isPriv ? team.GetColor() + sender.getName() : _manager.GetColor(sender) + sender.getName(); - } - else - { - globalMessage = true; - event.setFormat(dead + levelStr + rankStr + senderName + " " + C.cWhite + "%2$s"); - - if (rankStr.equals("")) - format = dead + levelStr; - else - format = event.getFormat().split(rankStr)[0]; - - name = _manager.GetColor(sender) + sender.getName(); - } - - if (globalMessage) - { - if (!_manager.GetGame().ShowEveryoneSpecChat) + event.getRecipients().removeIf(receiver -> { - //Team Message Remove Recipient - Iterator recipientIterator = event.getRecipients().iterator(); - - while (recipientIterator.hasNext()) + if (_manager.IsAlive(sender) || _manager.GetClients().Get(sender).hasPermission(Perm.SPEC_ALWAYS_SPEAK)) { - Player receiver = recipientIterator.next(); - - if (_manager.IsAlive(sender) || _manager.GetClients().Get(sender).hasPermission(Perm.SPEC_ALWAYS_SPEAK)) - { - continue; - } - - if (!_manager.IsAlive(receiver) || _manager.GetClients().Get(receiver).hasPermission(Perm.SPEC_ALWAYS_HEAR)) - { - continue; - } - - recipientIterator.remove(); + return false; } - } - if (safeSend(sender, format, rankStr, group, name, message, event.getRecipients())) - { - event.setCancelled(true); - } - return; - } - - //Team Message Remove Recipient - Iterator recipientIterator = event.getRecipients().iterator(); - - while (recipientIterator.hasNext()) - { - Player receiver = recipientIterator.next(); - - if (!_manager.GetServerConfig().Tournament && _manager.GetClients().Get(receiver).hasPermission(Perm.TEAM_SPY)) - { - if (TeamSpy) - { - continue; - } - } - - GameTeam recTeam = _manager.GetGame().GetTeam(receiver); - GameTeam sendTeam = _manager.GetGame().GetTeam(sender); - - if (recTeam == null || sendTeam == null) - { - continue; - } - - if (!recTeam.equals(sendTeam)) - { - recipientIterator.remove(); - } - } - - if (safeSend(sender, format, rankStr, group, name, message, event.getRecipients())) - { - event.setCancelled(true); + return _manager.IsAlive(receiver) && !_manager.GetClients().Get(receiver).hasPermission(Perm.SPEC_ALWAYS_HEAR); + }); } } - } - public boolean safeSend(Player sender, String prefix, String rankStr, PermissionGroup group, String name, String message, Collection sendto) - { - final JsonMessage json = buildJSON(sender, prefix, rankStr, group, name, _chatStats, message); - try + event.getFormatComponents().add(player -> { - json.send(JsonMessage.MessageType.CHAT_BOX, sendto.toArray(new Player[0])); - return true; - } - catch (Exception e) - { - System.out.println("ChatStats Failed to send JSON message.."); - System.out.println(json); - return false; - } + TextComponent component = new TextComponent(player.getName()); + + component.setColor(_manager.GetColor(player).asBungee()); + component.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder(String.join("\n", buildHoverText(player))) + .create())); + + return component; + }); } public void setGameChatStats(ChatStatData... stats) { - _chatStats = new LinkedList<>(); + _chatStats.clear(); Collections.addAll(_chatStats, stats); } - private JsonMessage buildJSON(Player player, String prefix, String rankStr, PermissionGroup group, String name, LinkedList hoverText, String message) + private List buildHoverText(Player player) { - if (_manager.GetGame() == null || _manager.GetGame().inLobby()) - { - if (group.getDisplay(false, false, false, false).isEmpty()) - { - return new JsonMessage("").extra(JSONObject.escape(prefix)) - .add(JSONObject.escape(rankStr)).add(JSONObject.escape(name)).add(JSONObject.escape(message)); - } - - return new JsonMessage("").extra(JSONObject.escape(prefix)) - .add(JSONObject.escape(rankStr)).hover("show_text", group.getDisplay(true, true, true, false) + C.cWhite + "\n" + group.getDescription()) - .add(JSONObject.escape(name)).add(JSONObject.escape(message)); - } - - LinkedList> temp = new LinkedList<>(); - ChatColor teamColor = _manager.GetColor(player); - - temp.add(new AbstractMap.SimpleEntry<>(teamColor + C.Bold + ChatColor.stripColor(name) + teamColor + "'s stats", "")); - temp.add(new AbstractMap.SimpleEntry<>(" ", "")); - Game game = _manager.GetGame(); - String gameName = game.GetName(); + List lines = new ArrayList<>(); - if (!_manager.GetGame().GetStats().containsKey(player)) + String rank = _manager.GetClients().Get(player).getPrimaryGroup().getDisplay(true, true, true, false); + + lines.add(rank + (rank.isEmpty() ? "" : " ") + _manager.GetColor(player) + player.getName() + "'s Stats"); + lines.add(""); + + if (game == null || !game.GetStats().containsKey(player)) { - temp.add(new SimpleEntry<>(C.cGray + "No in-game stats available", "")); + lines.add("No in-game stats available."); } else { - for (ChatStatData statData : hoverText) + Map stats = game.GetStats().get(player); + String gameName = game.GetName(); + + _chatStats.forEach(statData -> { String display = (statData.getDisplay() == null ? statData.getStat() : statData.getDisplay()); if (!statData.isValue()) { - temp.add(new SimpleEntry<>(statData.getDisplay(), "")); - continue; + lines.add(statData.getDisplay()); + return; } if (statData.getStat().equalsIgnoreCase("kit")) { - temp.add(new SimpleEntry<>(display + ": ", game.GetKit(player).GetName())); - continue; + lines.add(buildLine(display, game.GetKit(player).GetName())); + return; } if (statData.getStat().equalsIgnoreCase("kdratio")) { - int kills; - int deaths; + int kills = stats.getOrDefault(gameName + ".Kills", 0); + int deaths = stats.getOrDefault(gameName + ".Deaths", 0); - kills = game.GetStats().get(player).getOrDefault(gameName + ".Kills", 0); - - deaths = game.GetStats().get(player).getOrDefault(gameName + ".Deaths", 0); - - temp.add(new SimpleEntry<>(display + ": ", "" + getRatio(kills, deaths, "##.##"))); - continue; + lines.add(buildLine(display, String.valueOf(getRatio(kills, deaths, "##.##")))); + return; } - if (game.GetStats().get(player).containsKey(gameName + "." + statData.getStat())) - { - temp.add(new SimpleEntry<>(display + ": ", (game.GetStats().get(player).get(gameName + "." + statData.getStat()).toString()))); - } - else - { - temp.add(new SimpleEntry<>(display + ": ", "0")); - } - } + lines.add(buildLine(display, (stats.getOrDefault(gameName + "." + statData.getStat(), 0).toString()))); + }); } - StringBuilder stats = new StringBuilder(); - for (int i = 0; i < temp.size(); i++) - { - stats.append(C.cWhite).append(JSONObject.escape(temp.get(i).getKey())).append(C.cGray).append(JSONObject.escape(temp.get(i).getValue())).append(i >= temp.size() - 1 ? "" : "\\n"); - } + return lines; + } - if (group.getDisplay(false, false, false, false).isEmpty()) - { - return new JsonMessage("").extra(JSONObject.escape(prefix)) - .add(JSONObject.escape(rankStr)).add(JSONObject.escape(name)).hover("show_text", stats.toString()).add(JSONObject.escape(message)); - } - - return new JsonMessage("").extra(JSONObject.escape(prefix)) - .add(JSONObject.escape(rankStr)).hover("show_text", group.getDisplay(true, true, true, false) + ChatColor.WHITE + "\n" + group.getDescription()) - .add(JSONObject.escape(name)).hover("show_text", stats.toString()).add(JSONObject.escape(message)); + private String buildLine(String first, String second) + { + return C.cWhite + first + C.cGray + ": " + second; } private double getRatio(int var1, int var2, String format) diff --git a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java index c248d3bc9..095916b11 100644 --- a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java +++ b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java @@ -114,8 +114,7 @@ public class Hub extends JavaPlugin EloManager eloManager = new EloManager(this, _clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, incognito, eloManager); FriendManager friendManager = require(FriendManager.class); - Chat chat = new Chat(); - new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); + new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, require(Chat.class)); BlockRestore blockRestore = require(BlockRestore.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 623d757d7..02b1261fb 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -1,6 +1,6 @@ package mineplex.gemhunters; -import static mineplex.core.Managers.require; +import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.World; @@ -97,7 +97,8 @@ import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; -import net.minecraft.server.v1_8_R3.MinecraftServer; + +import static mineplex.core.Managers.require; /** * Gem Hunters main class
@@ -210,8 +211,7 @@ public class GemHunters extends JavaPlugin AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); // Chat/Messaging - Chat chat = new Chat(); - new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, require(FriendManager.class), chat); + new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, require(FriendManager.class), require(Chat.class)); // Parties new PartyManager();