From 2a872716425965fc640e990d847b8fccaf91f355 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Fri, 19 Mar 2021 08:58:29 -0500 Subject: [PATCH 1/7] 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()); + }); } } From b03870c0aa9562c430f02e6803dce4784139b25d Mon Sep 17 00:00:00 2001 From: Paldiu Date: Fri, 19 Mar 2021 10:39:58 -0500 Subject: [PATCH 2/7] SQL Fixes :) --- .../bridge/CoreProtectBridge.java | 16 ++++++++-------- .../totalfreedommod/world/WorldRestrictions.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java index 8c60857d..dc846cd1 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/CoreProtectBridge.java @@ -1,11 +1,7 @@ package me.totalfreedom.totalfreedommod.bridge; import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.text.DecimalFormat; import java.util.Arrays; import java.util.Collections; @@ -228,11 +224,12 @@ public class CoreProtectBridge extends FreedomService String database = ConfigEntry.COREPROTECT_MYSQL_DATABASE.getString(); String url = host + ":" + port + "/" + database + "?user=" + username + "&password=" + password + "&useSSL=false"; connection = DriverManager.getConnection("jdbc:sql://" + url); - final Statement statement = connection.createStatement(); + final PreparedStatement statement = connection.prepareStatement("SELECT id FROM co_world WHERE world = ?"); statement.setQueryTimeout(30); // Obtain world ID from CoreProtect database - ResultSet resultSet = statement.executeQuery("SELECT id FROM co_world WHERE world = '" + world.getName() + "'"); + statement.setString(1, world.getName()); + ResultSet resultSet = statement.executeQuery(); String worldID = null; while (resultSet.next()) { @@ -250,7 +247,10 @@ public class CoreProtectBridge extends FreedomService // Iterate through each table and delete their data if the world ID matches for (String table : tables) { - statement.executeQuery("DELETE FROM " + table + " WHERE wid = " + worldID); + final PreparedStatement statement1 = connection.prepareStatement("DELETE FROM ? WHERE wid = ?"); + statement1.setString(1, table); + statement1.setString(2, worldID); + statement1.executeQuery(); } connection.close(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java index df5e6f0a..f1869635 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java @@ -139,7 +139,7 @@ public class WorldRestrictions extends FreedomService event.setCancelled(true); } - if (command.equals("coreprotect") || command.equals("core") || command.equals("co")) + if (command.equalsIgnoreCase("coreprotect") || command.equalsIgnoreCase("core") || command.equalsIgnoreCase("co")) { player.sendMessage(ChatColor.RED + "Only " + allowed + " are allowed to use CoreProtect here."); event.setCancelled(true); From b3b68ebd132a80e8675865e1d9687638493ce843 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Sun, 21 Mar 2021 14:02:43 -0500 Subject: [PATCH 3/7] Switch to Allman Formatting --- .../me/totalfreedom/totalfreedommod/ChatManager.java | 7 +++++-- .../discord/DiscordToAdminChatListener.java | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index cb2ffe4a..eebefc44 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -159,14 +159,17 @@ public class ChatManager extends FreedomService FLog.info("[ADMIN] " + sender.getName() + " " + display.getTag() + ": " + message, true); plugin.dc.messageAdminChatChannel(sender.getName() + " \u00BB " + message); - server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player)).forEach(player -> { + 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 { + } + 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)); } }); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java index cdfe2dee..29814c3d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java @@ -56,10 +56,12 @@ public class DiscordToAdminChatListener extends ListenerAdapter FLog.info(message.toString()); - Bukkit.getOnlinePlayers().stream().filter(player -> TotalFreedomMod.getPlugin().al.isAdmin(player)).forEach(player -> { + 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)) { + 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()) @@ -67,7 +69,9 @@ public class DiscordToAdminChatListener extends ListenerAdapter .replace("%rankcolor%", color.toString()) .replace("%msg%", FUtil.colorize(msg.getContentDisplay())); builder.append(FUtil.colorize(m)); - } else { + } + else + { String m = ChatColor.DARK_RED + member.getEffectiveName() + " " + ChatColor.DARK_GRAY + tag + ChatColor.DARK_GRAY + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(msg.getContentDisplay()); From 97672c2fff8b4de48ffbfd32a8dd39edccb2decd Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 22 Mar 2021 09:57:09 -0500 Subject: [PATCH 4/7] Update DiscordToAdminChatListener.java This is the only way we can load media after [Discord] and [Formatting] without rewriting the method --- .../discord/DiscordToAdminChatListener.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java index 29814c3d..7be85478 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java @@ -43,16 +43,6 @@ public class DiscordToAdminChatListener extends ListenerAdapter message.append(msg.getContentDisplay()); ComponentBuilder builder = new ComponentBuilder(msg.toString()); - if (!msg.getAttachments().isEmpty()) - { - for (Message.Attachment attachment : msg.getAttachments()) - { - TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); - text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); - builder.append(text); - message.append("[Media]"); // for logging - } - } FLog.info(message.toString()); @@ -77,6 +67,18 @@ public class DiscordToAdminChatListener extends ListenerAdapter + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(msg.getContentDisplay()); builder.append(m); } + + if (!msg.getAttachments().isEmpty()) + { + for (Message.Attachment attachment : msg.getAttachments()) + { + TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); + text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); + builder.append(text); + message.append("[Media]"); // for logging + } + } + player.spigot().sendMessage(builder.create()); }); } From 14309275fb4d0bcabd7f3253347053cf5e746813 Mon Sep 17 00:00:00 2001 From: TFTWPhoenix <61560519+TFTWPhoenix@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:16:01 -0500 Subject: [PATCH 5/7] Remove /premium --- .../command/Command_premium.java | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_premium.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_premium.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_premium.java deleted file mode 100644 index 4fdec9cf..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_premium.java +++ /dev/null @@ -1,83 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import me.totalfreedom.totalfreedommod.rank.Rank; -import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FSync; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) -@CommandParameters(description = "Validates if a given account is premium, or cracked.", usage = "/ ", aliases = "prem") -public class Command_premium extends FreedomCommand -{ - - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - if (args.length != 1) - { - return false; - } - - final Player player = getPlayer(args[0]); - final String name; - - if (player != null) - { - name = player.getName(); - } - else - { - name = args[0]; - } - - new BukkitRunnable() - { - @Override - public void run() - { - try - { - final URL getUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + name); - final HttpURLConnection urlConnection = (HttpURLConnection)getUrl.openConnection(); - urlConnection.setRequestProperty("User-Agent", ""); - String message; - /*old code - BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) - //message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes"); - */ - try - { - if (urlConnection.getResponseCode() == 200) - { - message = ChatColor.GREEN + "Yes"; - } - else - { - message = ChatColor.RED + "No"; - } - FSync.playerMsg(sender, "Player " + name + " is premium: " + message); - } - catch (IOException e) - { - FSync.playerMsg(sender, ChatColor.RED + "There was an error on trying to connect to the API server"); - } - - } - catch (IOException ex) - { - FLog.severe(ex); - msg("There was an error querying the API server.", ChatColor.RED); - } - } - }.runTaskAsynchronously(plugin); - - return true; - } -} \ No newline at end of file From dca5e3029106802763380b90cf676cf7b4387858 Mon Sep 17 00:00:00 2001 From: Elmon11 Date: Sun, 4 Apr 2021 14:24:06 +0200 Subject: [PATCH 6/7] Actually display assistant exec in game (#37) * Actually display assistant exec in game * Update RankManager.java * Update ConfigEntry.java * Update FUtil.java Co-authored-by: Nathan Curran <30569566+Focusvity@users.noreply.github.com> --- .../totalfreedom/totalfreedommod/config/ConfigEntry.java | 2 +- .../me/totalfreedom/totalfreedommod/rank/RankManager.java | 7 ++++++- .../java/me/totalfreedom/totalfreedommod/util/FUtil.java | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index c19bad9d..2832bdf1 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -57,7 +57,7 @@ public enum ConfigEntry SERVER_LOGIN_SUBTITLE(String.class, "server.login_title.subtitle"), SERVER_OWNERS(List.class, "server.owners"), SERVER_EXECUTIVES(List.class, "server.executives"), - SERVER_ASSTISTANT_EXECUTIVES(List.class, "server.assistant_executives"), + SERVER_ASSISTANT_EXECUTIVES(List.class, "server.assistant_executives"), SERVER_MASTER_BUILDER_MANAGEMENT(List.class, "server.master_builder_management"), SERVER_BAN_URL(String.class, "server.ban_url"), SERVER_INDEFBAN_URL(String.class, "server.indefban_url"), diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java index 15ebe5e4..d246b19f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/RankManager.java @@ -61,6 +61,11 @@ public class RankManager extends FreedomService { return Title.EXECUTIVE; } + + if (ConfigEntry.SERVER_ASSISTANT_EXECUTIVES.getList().contains(player.getName()) && plugin.al.isAdmin(player)) + { + return Title.ASSTEXEC; + } if (plugin.al.isVerifiedAdmin(player)) { @@ -313,4 +318,4 @@ public class RankManager extends FreedomService team.addPlayer(player); } } -} \ No newline at end of file +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 83d3c949..b6e5390f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -139,7 +139,7 @@ public class FUtil public static boolean isExecutive(String name) { - return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name) || ConfigEntry.SERVER_ASSTISTANT_EXECUTIVES.getStringList().contains(name); + return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name) || ConfigEntry.SERVER_ASSISTANT_EXECUTIVES.getStringList().contains(name); } public static boolean isDeveloper(Player player) From 27f5f18962bd58bc4dbb735ddaca8eff6b00bc87 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 5 Apr 2021 22:11:12 +0100 Subject: [PATCH 7/7] FS-143 Resolution (#42) * Bump to patch version. * Fixes FS-143 Various changes to make it work better with logging and things like that. --- pom.xml | 2 +- .../discord/DiscordToAdminChatListener.java | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 1eafcf5b..1f29ace6 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ me.totalfreedom TotalFreedomMod - 2021.02 + 2021.02-Patch.01-RC01 jar diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java index 7be85478..fed58efb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToAdminChatListener.java @@ -23,6 +23,7 @@ import org.bukkit.entity.Player; public class DiscordToAdminChatListener extends ListenerAdapter { + DiscordToMinecraftListener dtml = new DiscordToMinecraftListener(); public static net.md_5.bungee.api.ChatColor getColor(Displayable display) @@ -37,17 +38,29 @@ public class DiscordToAdminChatListener extends ListenerAdapter { Member member = event.getMember(); 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(); + String mediamessage = ChatColor.YELLOW + " [Media]"; - message.append(msg.getContentDisplay()); + StringBuilder logmessage = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET); + String lm = ChatColor.DARK_RED + member.getEffectiveName() + " " + + ChatColor.DARK_GRAY + tag + ChatColor.DARK_GRAY + + ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(msg.getContentDisplay()); + logmessage.append(lm); - ComponentBuilder builder = new ComponentBuilder(msg.toString()); + if (!msg.getAttachments().isEmpty()) + { + + logmessage.append(mediamessage); // Actually for logging... - FLog.info(message.toString()); + } + FLog.info(logmessage.toString()); Bukkit.getOnlinePlayers().stream().filter(player -> TotalFreedomMod.getPlugin().al.isAdmin(player)).forEach(player -> { + StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET); + + ComponentBuilder builder = new ComponentBuilder(message.toString()); + Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(player); String format = admin.getAcFormat(); if (!Strings.isNullOrEmpty(format)) @@ -59,6 +72,7 @@ public class DiscordToAdminChatListener extends ListenerAdapter .replace("%rankcolor%", color.toString()) .replace("%msg%", FUtil.colorize(msg.getContentDisplay())); builder.append(FUtil.colorize(m)); + } else { @@ -72,14 +86,13 @@ public class DiscordToAdminChatListener extends ListenerAdapter { for (Message.Attachment attachment : msg.getAttachments()) { - TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); + TextComponent text = new TextComponent(mediamessage); text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); builder.append(text); - message.append("[Media]"); // for logging } } - player.spigot().sendMessage(builder.create()); + }); } } @@ -124,4 +137,4 @@ public class DiscordToAdminChatListener extends ListenerAdapter return Rank.OP.getAbbr(); } } -} \ No newline at end of file +}