From 2a872716425965fc640e990d847b8fccaf91f355 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Fri, 19 Mar 2021 08:58:29 -0500 Subject: [PATCH] Should fix FS-143 --- .../totalfreedommod/ChatManager.java | 27 +++----- .../totalfreedommod/admin/Admin.java | 8 --- .../discord/DiscordToAdminChatListener.java | 62 +++++++------------ 3 files changed, 34 insertions(+), 63 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 19054c8a..cb2ffe4a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -159,24 +159,17 @@ public class ChatManager extends FreedomService FLog.info("[ADMIN] " + sender.getName() + " " + display.getTag() + ": " + message, true); plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message); - for (Player player : server.getOnlinePlayers()) - { - if (plugin.al.isAdmin(player)) - { - Admin admin = plugin.al.getAdmin(player); - if (!Strings.isNullOrEmpty(admin.getAcFormat())) - { - String format = admin.getAcFormat(); - ChatColor color = getColor(display); - String msg = format.replace("%name%", sender.getName()).replace("%rank%", display.getAbbr()).replace("%rankcolor%", color.toString()).replace("%msg%", message); - player.sendMessage(FUtil.colorize(msg)); - } - else - { - player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + sender.getName() + ChatColor.DARK_GRAY + " [" + getColoredTag(display) + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(message)); - } + server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player -> { + Admin admin = plugin.al.getAdmin(player); + if (!Strings.isNullOrEmpty(admin.getAcFormat())) { + String format = admin.getAcFormat(); + ChatColor color = getColor(display); + String msg = format.replace("%name%", sender.getName()).replace("%rank%", display.getAbbr()).replace("%rankcolor%", color.toString()).replace("%msg%", message); + player.sendMessage(FUtil.colorize(msg)); + } else { + player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + sender.getName() + ChatColor.DARK_GRAY + " [" + getColoredTag(display) + ChatColor.DARK_GRAY + "]" + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(message)); } - } + }); } public void reportAction(Player reporter, Player reported, String report) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 7e89dbd9..17920853 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -25,17 +25,9 @@ public class Admin private boolean active = true; private Rank rank = Rank.ADMIN; private Date lastLogin = new Date(); - - private Boolean commandSpy = false; - - private Boolean potionSpy = false; - - private String acFormat = null; - - private String pteroID = null; public Admin(Player player) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java index 8d9be126..cdfe2dee 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.discord; +import com.google.common.base.Strings; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.config.ConfigEntry; @@ -38,42 +39,14 @@ public class DiscordToAdminChatListener extends ListenerAdapter String tag = dtml.getDisplay(member); StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET); Message msg = event.getMessage(); - for (Player player : Bukkit.getOnlinePlayers()) - { - if (TotalFreedomMod.getPlugin().al.isAdmin(player)) - { - Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(player); - String format = admin.getAcFormat(); - if (format != null) - { - Displayable display = TotalFreedomMod.getPlugin().rm.getDisplay(player); - net.md_5.bungee.api.ChatColor color = getColor(display); - String m = format.replace("%name%", member.getEffectiveName()) - .replace("%rank%", getDisplay(member)) - .replace("%rankcolor%", color.toString()) - .replace("%msg%", FUtil.colorize(msg.getContentDisplay())); - message.append(FUtil.colorize(m)); - } - else - { - String m = ChatColor.DARK_RED + member.getEffectiveName() + " " - + ChatColor.DARK_GRAY + tag + ChatColor.DARK_GRAY - + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(msg.getContentDisplay()); - message.append(m); - } - } - } - ComponentBuilder builder = new ComponentBuilder(message.toString()); + message.append(msg.getContentDisplay()); + + ComponentBuilder builder = new ComponentBuilder(msg.toString()); if (!msg.getAttachments().isEmpty()) { for (Message.Attachment attachment : msg.getAttachments()) { - if (attachment.getUrl() == null) - { - continue; - } - TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); builder.append(text); @@ -81,14 +54,27 @@ public class DiscordToAdminChatListener extends ListenerAdapter } } - for (Player player : Bukkit.getOnlinePlayers()) - { - if (TotalFreedomMod.getPlugin().al.isAdmin(player)) - { - player.spigot().sendMessage(builder.create()); - } - } FLog.info(message.toString()); + + Bukkit.getOnlinePlayers().stream().filter(player -> TotalFreedomMod.getPlugin().al.isAdmin(player)).forEach(player -> { + Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(player); + String format = admin.getAcFormat(); + if (!Strings.isNullOrEmpty(format)) { + Displayable display = TotalFreedomMod.getPlugin().rm.getDisplay(player); + net.md_5.bungee.api.ChatColor color = getColor(display); + String m = format.replace("%name%", member.getEffectiveName()) + .replace("%rank%", getDisplay(member)) + .replace("%rankcolor%", color.toString()) + .replace("%msg%", FUtil.colorize(msg.getContentDisplay())); + builder.append(FUtil.colorize(m)); + } else { + String m = ChatColor.DARK_RED + member.getEffectiveName() + " " + + ChatColor.DARK_GRAY + tag + ChatColor.DARK_GRAY + + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(msg.getContentDisplay()); + builder.append(m); + } + player.spigot().sendMessage(builder.create()); + }); } }