From bbbccc2b1054928172034a61063295f25a9c943f Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:10:19 +0100 Subject: [PATCH 01/25] Update some dependencies --- pom.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 10c5156b..2462b359 100644 --- a/pom.xml +++ b/pom.xml @@ -108,7 +108,7 @@ commons-io commons-io - 2.11.0 + 2.13.0 compile @@ -122,7 +122,7 @@ org.bstats bstats-bukkit - 3.0.0 + 3.0.2 compile @@ -157,14 +157,14 @@ net.dv8tion JDA - 4.4.0_352 + 4.4.1_353 provided net.coreprotect coreprotect - 21.2 + 21.3 provided @@ -178,7 +178,7 @@ io.papermc paperlib - 1.0.7 + 1.0.8 compile @@ -213,21 +213,21 @@ org.jetbrains annotations - 23.0.0 + 24.0.1 compile org.apache.maven.plugins maven-checkstyle-plugin - 3.1.2 + 3.4.1 compile org.junit.jupiter junit-jupiter - 5.9.0 + 5.10.0 compile @@ -259,7 +259,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.11.0 TotalFreedomMod.jar 17 @@ -363,7 +363,7 @@ org.codehaus.mojo buildnumber-maven-plugin - 3.0.0 + 3.2.0 generate-resources From 07b35537487bcc36846c329efb80b0ed45a03d5b Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:16:26 +0100 Subject: [PATCH 02/25] Update Essentials & WorldGuard --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2462b359..688bff50 100644 --- a/pom.xml +++ b/pom.xml @@ -171,7 +171,7 @@ com.sk89q.worldguard worldguard-bukkit - 7.0.7 + 7.0.8 provided @@ -192,7 +192,7 @@ net.essentialsx EssentialsX - 2.19.6 + 2.20.0 provided From f67db2286d6eb12841a3b39f7a57516d3fdcd2f5 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:18:26 +0100 Subject: [PATCH 03/25] Update GitHub actions dependencies --- .github/workflows/codacy-analysis.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/java17-maven.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codacy-analysis.yml b/.github/workflows/codacy-analysis.yml index 03d6feb4..36f06235 100644 --- a/.github/workflows/codacy-analysis.yml +++ b/.github/workflows/codacy-analysis.yml @@ -25,7 +25,7 @@ jobs: # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@v4.2.0 + uses: codacy/codacy-analysis-cli-action@v4.3.0 with: # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository # You can also omit the token and run the tools that support default configurations diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3f65d1a0..04854953 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -38,7 +38,7 @@ jobs: uses: actions/checkout@v3 - name: Setup Java JDK - uses: actions/setup-java@v3.9.0 + uses: actions/setup-java@v3.11.0 with: # The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28 java-version: 17 diff --git a/.github/workflows/java17-maven.yml b/.github/workflows/java17-maven.yml index d4f15b30..01a4721f 100644 --- a/.github/workflows/java17-maven.yml +++ b/.github/workflows/java17-maven.yml @@ -13,7 +13,7 @@ jobs: # Java 16 Builds - name: Set up JDK 17 - uses: actions/setup-java@v3.9.0 + uses: actions/setup-java@v3.11.0 with: java-version: 17 distribution: 'adopt' From 9ce4dc6f3ad83b83a5144b44cc4f3f506dae58b2 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:21:41 +0100 Subject: [PATCH 04/25] Fix CommandSpy colours --- .../java/me/totalfreedom/totalfreedommod/CommandSpy.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java index 5d2730d6..bc4989cf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java @@ -1,7 +1,7 @@ package me.totalfreedom.totalfreedommod; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -23,7 +23,7 @@ public class CommandSpy extends FreedomService { server.getOnlinePlayers().stream().filter(player -> plugin.al.isAdmin(player) && plugin.al.getAdmin(player).getCommandSpy() && player != event.getPlayer()).forEach(player -> - player.sendMessage(Component.text(event.getPlayer().getName()).append(Component.text(": ")) - .append(Component.text(event.getMessage())))); + player.sendMessage(Component.text(event.getPlayer().getName(), NamedTextColor.GRAY).append(Component.text(": ", NamedTextColor.GRAY)) + .append(Component.text(event.getMessage(), NamedTextColor.GRAY)))); } } \ No newline at end of file From 6e140ace7dae0e5c0f11fa49b03a885432d7768c Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:26:47 +0100 Subject: [PATCH 05/25] Fix /ci tab completion throwing exceptions --- src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 512c69ea..5fbab633 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -21,6 +21,7 @@ import java.time.Instant; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.bukkit.Bukkit.getServer; @@ -144,10 +145,11 @@ public class FUtil return (count == 1 ? "" : "s"); } + @SuppressWarnings("java:S6204") public static List getPlayerList() { return getServer().getOnlinePlayers().stream().filter(player -> - !TotalFreedomMod.getPlugin().al.isVanished(player.getUniqueId())).map(HumanEntity::getName).toList(); + !TotalFreedomMod.getPlugin().al.isVanished(player.getUniqueId())).map(HumanEntity::getName).collect(Collectors.toList()); } public static String listToString(List list) From 08115470b0879e3e2bfa3ab5bdfe2c4321cccf20 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:28:58 +0100 Subject: [PATCH 06/25] Fix reactions showing up in Discord bridge & colour codes showing up in bridge --- .../totalfreedommod/ChatManager.java | 11 ++++- .../totalfreedom/totalfreedommod/Muter.java | 13 ++---- .../totalfreedommod/discord/Discord.java | 28 +++++++++---- .../totalfreedommod/shop/Shop.java | 41 ++++++++++++------- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index 116a4beb..e63a7a2d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -46,8 +46,13 @@ public class ChatManager extends FreedomService private void handleChatEvent(AsyncPlayerChatEvent event) { final Player player = event.getPlayer(); - String message = event.getMessage().trim(); - + String originalMessage = event.getMessage(); + if (plugin.mu.onPlayerChat(player) || plugin.sh.handlePlayerChat(player, originalMessage)) + { + event.setCancelled(true); + return; + } + String message = originalMessage.trim(); // Format colors and strip &k message = FUtil.colorize(message); message = message.replaceAll(ChatColor.MAGIC.toString(), "&k"); @@ -82,6 +87,8 @@ public class ChatManager extends FreedomService return; } + plugin.dc.onPlayerChat(player, ChatColor.stripColor(message)); + // Check for 4chan trigger if (ConfigEntry.FOURCHAN_ENABLED.getBoolean()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Muter.java b/src/main/java/me/totalfreedom/totalfreedommod/Muter.java index 270b848c..a83d9802 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Muter.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Muter.java @@ -3,7 +3,6 @@ package me.totalfreedom.totalfreedommod; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FSync; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; @@ -11,7 +10,6 @@ import org.bukkit.command.Command; 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.PlayerCommandPreprocessEvent; public class Muter extends FreedomService @@ -26,26 +24,23 @@ public class Muter extends FreedomService { } - @EventHandler(priority = EventPriority.HIGHEST) - public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) + public boolean onPlayerChat(Player player) { - Player player = event.getPlayer(); - FPlayer fPlayer = plugin.pl.getPlayerSync(player); if (!fPlayer.isMuted()) { - return; + return false; } if (plugin.al.isAdminSync(player)) { fPlayer.setMuted(false); - return; + return false; } player.sendMessage(Component.text("You are muted.", NamedTextColor.RED)); - event.setCancelled(true); + return true; } @EventHandler(priority = EventPriority.LOW) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 156d4582..51bd6d60 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -514,16 +514,28 @@ public class Discord extends FreedomService } } - @EventHandler(ignoreCancelled = true) - public void onAsyncPlayerChat(AsyncPlayerChatEvent event) + public void onPlayerChat(Player player, String message) { - Player player = event.getPlayer(); - String message = event.getMessage(); - - if (!ConfigEntry.ADMIN_ONLY_MODE.getBoolean() && !server.hasWhitelist() - && !plugin.pl.getPlayer(player).isMuted() && bot != null) + if (ConfigEntry.ADMIN_ONLY_MODE.getBoolean()) { - messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message)); + return; } + + if (server.hasWhitelist()) + { + return; + } + + if (plugin.pl.getPlayer(player).isMuted()) + { + return; + } + + if (bot == null) + { + return; + } + + messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message)); } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java index f12fb04d..43af8b97 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/shop/Shop.java @@ -21,7 +21,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -412,23 +411,35 @@ public class Shop extends FreedomService } - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) + public boolean handlePlayerChat(Player player, String message) { - String message = event.getMessage(); - Player player = event.getPlayer(); - - if (ConfigEntry.SHOP_ENABLED.getBoolean() && ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean() - && !plugin.sh.reactionString.isEmpty() && message.equals(plugin.sh.reactionString)) + if (!ConfigEntry.SHOP_ENABLED.getBoolean()) { - event.setCancelled(true); - PlayerData data = plugin.pl.getData(player); - data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin); - plugin.pl.save(data); - plugin.sh.endReaction(player.getName()); - player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD - + plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!"); + return false; } + + if (!ConfigEntry.SHOP_REACTIONS_ENABLED.getBoolean()) + { + return false; + } + + if (plugin.sh.reactionString.isEmpty()) + { + return false; + } + + if (!message.equals(plugin.sh.reactionString)) + { + return false; + } + + PlayerData data = plugin.pl.getData(player); + data.setCoins(data.getCoins() + plugin.sh.coinsPerReactionWin); + plugin.pl.save(data); + plugin.sh.endReaction(player.getName()); + player.sendMessage(ChatColor.GREEN + "You have been given " + ChatColor.GOLD + + plugin.sh.coinsPerReactionWin + ChatColor.GREEN + " coins!"); + return true; } public ShopItem getShopItem(int slot) From 00e54034918a523b472d2d02778cc9f41b321eb8 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:30:46 +0100 Subject: [PATCH 07/25] Remove SK89Q maven repositories --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index 688bff50..b8475e6d 100644 --- a/pom.xml +++ b/pom.xml @@ -65,11 +65,6 @@ https://maven.elmakers.com/repository/ - - sk89q-snapshots - https://maven.sk89q.com/artifactory/repo - - dv8tion m2-dv8tion @@ -91,11 +86,6 @@ https://repo.dmulloy2.net/nexus/repository/public/ - - sk89q-repo - https://maven.sk89q.com/repo/ - - esentialsx-repo https://repo.essentialsx.net/releases/ From 04029eb1443136484873e892c389d3d0673df890 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 19 Jun 2023 15:56:19 -0300 Subject: [PATCH 08/25] Don't try to vanish/unvanish offline players... (cherry picked from commit a03ecfd6f3248a6b4588db19549d4daf76952742) --- .../totalfreedom/totalfreedommod/bridge/EssentialsBridge.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java index 8764c915..2bd26bda 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java @@ -129,7 +129,7 @@ public class EssentialsBridge extends FreedomService try { User user = getEssentialsUser(username); - if (user != null) + if (user != null && user.getBase().isOnline()) { user.setVanished(vanished); } @@ -210,4 +210,4 @@ public class EssentialsBridge extends FreedomService return ess != null && ess.isEnabled(); } -} \ No newline at end of file +} From ac704614c0d713b689b6216a7164479113873e40 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 00:38:02 +0100 Subject: [PATCH 09/25] Fix updated plugin versions --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b8475e6d..0a422201 100644 --- a/pom.xml +++ b/pom.xml @@ -210,7 +210,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.4.1 + 3.3.0 compile @@ -378,7 +378,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.3.0 + 3.4.1 package From 08c8393abcd0d73ff55277883e9a54ff89a08e05 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 01:50:46 +0100 Subject: [PATCH 10/25] Fix ArrayIndexOutOfBounds when a newly added admin leaves the game --- .../totalfreedommod/admin/ActivityLogEntry.java | 9 +++++++-- .../me/totalfreedom/totalfreedommod/admin/AdminList.java | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java index eb056fcb..037f8548 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/ActivityLogEntry.java @@ -66,8 +66,13 @@ public class ActivityLogEntry implements IConfig public void addLogin() { - Date currentTime = Date.from(Instant.now()); - timestamps.add("Login: " + FUtil.dateToString(currentTime)); + this.addLogin(System.currentTimeMillis()); + } + + public void addLogin(final long timestamp) + { + Date time = Date.from(Instant.ofEpochMilli(timestamp)); + timestamps.add("Login: " + FUtil.dateToString(time)); } public void addLogout() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 84ec6d15..23715310 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -194,6 +194,15 @@ public class AdminList extends FreedomService // Save admin plugin.sql.addAdmin(admin); + // Add login time + UUID uuid = admin.getUuid(); + Player player = Bukkit.getPlayer(uuid); + + if (player != null) + { + plugin.acl.getActivityLog(player).addLogin(player.getLastLogin()); + } + return true; } From 597a46462364ab956804da0ba379a44c392e8b02 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 01:59:46 +0100 Subject: [PATCH 11/25] Add run/ to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3e444ba6..4db7b93b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ manifest.mf ehthumbs.db Thumbs.db .idea/inspectionProfiles/Project_Default.xml + +# Common working directory +run/ \ No newline at end of file From eb99dcd3a39696f7f69c4875a95a6109727d9ab4 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 02:00:34 +0100 Subject: [PATCH 12/25] Optimize EssentialsBridge imports --- .../totalfreedom/totalfreedommod/bridge/EssentialsBridge.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java index 2bd26bda..36b7861a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/EssentialsBridge.java @@ -6,7 +6,6 @@ import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -14,7 +13,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.plugin.Plugin; From 011535cf16c496b7e2a8a873ba0a3b5daa33b226 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 03:45:22 +0100 Subject: [PATCH 13/25] Make Discord report filing system asynchronous --- .../command/Command_report.java | 29 ++- .../totalfreedommod/discord/Discord.java | 170 ++++++++---------- 2 files changed, 96 insertions(+), 103 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java index 554c1f6d..6568d8ed 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_report.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; @@ -8,11 +10,28 @@ import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME, blockHostConsole = true) @CommandParameters(description = "Report a player for all admins to see.", usage = "/ ") public class Command_report extends FreedomCommand { + private void handleLog(final @Nullable Boolean value, final @Nullable Throwable ex, final CommandSender sender) + { + if (ex != null) + { + sender.sendMessage(Component.text("An error occurred while attempting to log your previously filed report to a Discord channel.", NamedTextColor.RED)); + ex.printStackTrace(); + return; + } + + if (Boolean.FALSE.equals(value)) + { + return; + } + + sender.sendMessage(Component.text("The report you previously filed has been successfully logged to a Discord channel. Please note that spamming reports is not allowed, and you will be sanctioned if you are found to be doing it.", NamedTextColor.GRAY)); + } @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -50,18 +69,16 @@ public class Command_report extends FreedomCommand } String report = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); - plugin.cm.reportAction(playerSender, (player == null) ? offlinePlayer.getName() : player.getName(), report); + String reportedUsername = (player == null) ? offlinePlayer.getName() : player.getName(); + plugin.cm.reportAction(playerSender, reportedUsername, report); - boolean logged = false; + msg(ChatColor.GREEN + "Thank you, your report is being processed."); if (plugin.dc.enabled) { - logged = (player == null) ? plugin.dc.sendReportOffline(playerSender, offlinePlayer, report) : plugin.dc.sendReport(playerSender, player, report); + plugin.dc.sendReport(playerSender.getName(), reportedUsername, report).whenCompleteAsync((logged, ex) -> handleLog(logged, ex, sender)); } - msg(ChatColor.GREEN + "Thank you, your report has been successfully logged." - + (logged ? ChatColor.RED + "\nNote: This report has been logged to a discord channel, as with any report system, spamming reports can lead to you getting banned." : "")); - return true; } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 51bd6d60..737e9362 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -3,10 +3,7 @@ package me.totalfreedom.totalfreedommod.discord; import com.google.common.base.Strings; import java.time.Instant; import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import javax.security.auth.login.LoginException; @@ -26,11 +23,9 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.SelfUser; import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.ReadyEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.requests.GatewayIntent; @@ -42,16 +37,18 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.WordUtils; import org.apache.commons.lang3.RandomStringUtils; +import org.bukkit.Bukkit; import org.bukkit.GameRule; +import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class Discord extends FreedomService { @@ -402,107 +399,86 @@ public class Discord extends FreedomService return true; } - public boolean sendReportOffline(Player reporter, OfflinePlayer reported, String reason) + public CompletableFuture sendReport(String reporterName, String reportedName, String reason) { - if (!shouldISendReport()) + return CompletableFuture.supplyAsync(() -> { - return false; - } - - final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString()); - - if (server == null) - { - FLog.severe("The guild ID specified in the config is invalid."); - return false; - } - - final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString()); - - if (channel == null) - { - FLog.severe("The report channel ID specified in the config is invalid."); - return false; - } - - final EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setTitle("Report for " + reported.getName() + " (offline)"); - embedBuilder.setDescription(reason); - embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png"); - embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now())); - if (plugin.esb.isEnabled()) - { - com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reported.getName()); - String location = "World: " + Objects.requireNonNull(user.getLastLocation().getWorld()).getName() + ", X: " + user.getLastLocation().getBlockX() + ", Y: " + user.getLastLocation().getBlockY() + ", Z: " + user.getLastLocation().getBlockZ(); - embedBuilder.addField("Location", location, true); - embedBuilder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true); - if (user.getNickname() != null) + if (!shouldISendReport()) { - embedBuilder.addField("Nickname", user.getNickname(), true); + return false; } - } - MessageEmbed embed = embedBuilder.build(); - Message message = channel.sendMessageEmbeds(embed).complete(); - if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty()) - { - message.addReaction("\uD83D\uDCCB").complete(); - } + final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString()); - return true; - } - - public boolean sendReport(Player reporter, Player reported, String reason) - { - if (!shouldISendReport()) - { - return false; - } - - final Guild server = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString()); - - if (server == null) - { - FLog.severe("The guild ID specified in the config is invalid."); - return false; - } - - final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString()); - - if (channel == null) - { - FLog.severe("The report channel ID specified in the config is invalid."); - return false; - } - - final EmbedBuilder embedBuilder = new EmbedBuilder(); - embedBuilder.setTitle("Report for " + reported.getName()); - embedBuilder.setDescription(reason); - embedBuilder.setFooter("Reported by " + reporter.getName(), "https://minotar.net/helm/" + reporter.getName() + ".png"); - embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now())); - String location = "World: " + Objects.requireNonNull(reported.getLocation().getWorld()).getName() + ", X: " + reported.getLocation().getBlockX() + ", Y: " + reported.getLocation().getBlockY() + ", Z: " + reported.getLocation().getBlockZ(); - embedBuilder.addField("Location", location, true); - embedBuilder.addField("Game Mode", WordUtils.capitalizeFully(reported.getGameMode().name()), true); - - if (plugin.esb.isEnabled()) - { - com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reported.getName()); - embedBuilder.addField("God Mode", WordUtils.capitalizeFully(String.valueOf(user.isGodModeEnabled())), true); - if (user.getNickname() != null) + if (server == null) { - embedBuilder.addField("Nickname", user.getNickname(), true); + FLog.severe("The guild ID specified in the config is invalid."); + return false; } - } - MessageEmbed embed = embedBuilder.build(); - Message message = channel.sendMessageEmbeds(embed).complete(); + final TextChannel channel = server.getTextChannelById(ConfigEntry.DISCORD_REPORT_CHANNEL_ID.getString()); - if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty()) - { - message.addReaction("\uD83D\uDCCB").complete(); - } + if (channel == null) + { + FLog.severe("The report channel ID specified in the config is invalid."); + return false; + } - return true; + Player onlinePlayer = Bukkit.getPlayer(reportedName); + boolean online = onlinePlayer != null; + + final EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setTitle("Report for " + reportedName + (online ? "" : " (offline)")); + embedBuilder.setDescription(reason); + embedBuilder.setFooter("Reported by " + reporterName, "https://minotar.net/helm/" + reporterName + ".png"); + embedBuilder.setTimestamp(Instant.from(ZonedDateTime.now())); + + Location location = null; + Boolean godMode = null; + String nickName = null; + + if (plugin.esb.isEnabled()) + { + com.earth2me.essentials.User user = plugin.esb.getEssentialsUser(reportedName); + if (!online) + { + location = user.getLastLocation(); + } + + godMode = user.isGodModeEnabled(); + nickName = user.getNickname(); + } + + if (location == null && online) + { + location = onlinePlayer.getLocation(); + } + + if (location != null) + { + embedBuilder.addField("Location", "World: " + location.getWorld().getName() + ", X: " + location.getBlockX() + ", Y: " + location.getBlockY() + ", Z: " + location.getBlockZ(), true); + } + + if (godMode != null) + { + embedBuilder.addField("God Mode", WordUtils.capitalizeFully(godMode.toString()), true); + } + + if (nickName != null) + { + embedBuilder.addField("Nickname", nickName, true); + } + + MessageEmbed embed = embedBuilder.build(); + Message message = channel.sendMessageEmbeds(embed).complete(); + + if (!ConfigEntry.DISCORD_REPORT_ARCHIVE_CHANNEL_ID.getString().isEmpty()) + { + message.addReaction("\uD83D\uDCCB").complete(); + } + + return true; + }); } // Do no ask why this is here. I spent two hours trying to make a simple thing work From 80f19f03490c465e35ce333bd3e142cbaeee4094 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 03:47:05 +0100 Subject: [PATCH 14/25] Disable mentions in archival message --- .../totalfreedommod/discord/MessageReactionListener.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java index 738a2e5e..c89bc8f9 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java @@ -10,6 +10,8 @@ import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import java.util.Collections; + public class MessageReactionListener extends ListenerAdapter { public void onMessageReactionAdd(MessageReactionAddEvent messageReactionAddEvent) @@ -59,6 +61,7 @@ public class MessageReactionListener extends ListenerAdapter final MessageEmbed embed = message.getEmbeds().get(0); final MessageBuilder archiveMessageBuilder = new MessageBuilder(); archiveMessageBuilder.setContent("Report completed by " + completer.getUser().getAsMention() + " (" + Discord.deformat(completer.getUser().getAsTag() + ")")); + archiveMessageBuilder.setAllowedMentions(Collections.emptyList()); archiveMessageBuilder.setEmbed(embed); final Message archiveMessage = archiveMessageBuilder.build(); From 8876076a9d4ac4cb846d955a97e516e492a83660 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 03:47:33 +0100 Subject: [PATCH 15/25] Fix JDA deprecation issue --- .../totalfreedommod/discord/MessageReactionListener.java | 2 +- .../totalfreedommod/discord/command/DiscordCommandManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java index c89bc8f9..c34aa5d5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/MessageReactionListener.java @@ -62,7 +62,7 @@ public class MessageReactionListener extends ListenerAdapter final MessageBuilder archiveMessageBuilder = new MessageBuilder(); archiveMessageBuilder.setContent("Report completed by " + completer.getUser().getAsMention() + " (" + Discord.deformat(completer.getUser().getAsTag() + ")")); archiveMessageBuilder.setAllowedMentions(Collections.emptyList()); - archiveMessageBuilder.setEmbed(embed); + archiveMessageBuilder.setEmbeds(embed); final Message archiveMessage = archiveMessageBuilder.build(); archiveChannel.sendMessage(archiveMessage).complete(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java index 93f1c60b..55e52ca6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java @@ -71,7 +71,7 @@ public class DiscordCommandManager embedBuilder.setTitle("Command error"); embedBuilder.setColor(Color.RED); embedBuilder.setDescription("You don't have permission to execute this command."); - messageBuilder.setEmbed(embedBuilder.build()); + messageBuilder.setEmbeds(embedBuilder.build()); final Message message = messageBuilder.build(); final CompletableFuture futureMessage = channel.sendMessage(message).submit(true); From b2c636f919df283be185371c8d5644af051754cd Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 03:57:24 +0100 Subject: [PATCH 16/25] Fix invalid Discord command handling --- .../discord/DiscordToMinecraftListener.java | 3 +-- .../discord/command/DiscordCommandManager.java | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index bd8d849d..81519493 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -58,9 +58,8 @@ public class DiscordToMinecraftListener extends ListenerAdapter final Message msg = event.getMessage(); final String content = msg.getContentStripped(); - if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString())) + if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString()) && Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel)) { - Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel); return; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java index 55e52ca6..1426444b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java @@ -46,11 +46,21 @@ public class DiscordCommandManager FLog.info("Loaded " + commands.size() + " Discord commands."); } - public void parse(String content, Member member, TextChannel channel) + public boolean parse(String content, Member member, TextChannel channel) { List args = new ArrayList<>(Arrays.asList(content.split(" "))); + if (args.isEmpty()) + { + return false; + } - final String alias = args.remove(0).split(PREFIX)[1]; // The joys of command parsing + final String[] aliasParts = args.remove(0).split(PREFIX); + if (aliasParts.length < 2) + { + return false; + } + + final String alias = aliasParts[1]; for (DiscordCommand command : commands) { @@ -63,6 +73,7 @@ public class DiscordCommandManager final CompletableFuture futureMessage = channel.sendMessage(message).submit(true); this.discord.sentMessages.add(futureMessage); + return true; } else { @@ -77,8 +88,11 @@ public class DiscordCommandManager final CompletableFuture futureMessage = channel.sendMessage(message).submit(true); this.discord.sentMessages.add(futureMessage); + return true; } } } + + return false; } } From ec19b6d3982c47454d25bb7bed5b37c7dc9a072d Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 04:13:40 +0100 Subject: [PATCH 17/25] Make the Discord command parsing more forgiving --- .../discord/DiscordToMinecraftListener.java | 2 +- .../discord/command/DiscordCommandManager.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java index 81519493..29a7bdcb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/DiscordToMinecraftListener.java @@ -58,7 +58,7 @@ public class DiscordToMinecraftListener extends ListenerAdapter final Message msg = event.getMessage(); final String content = msg.getContentStripped(); - if (content.startsWith(ConfigEntry.DISCORD_PREFIX.getString()) && Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel)) + if (content.toLowerCase().startsWith(ConfigEntry.DISCORD_PREFIX.getString().toLowerCase()) && Discord.DISCORD_COMMAND_MANAGER.parse(content, member, textChannel)) { return; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java index 1426444b..4f669230 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/command/DiscordCommandManager.java @@ -48,20 +48,20 @@ public class DiscordCommandManager public boolean parse(String content, Member member, TextChannel channel) { - List args = new ArrayList<>(Arrays.asList(content.split(" "))); + final String actualContent = content.substring(PREFIX.length()).trim(); + List args = new ArrayList<>(Arrays.asList(actualContent.split(" "))); if (args.isEmpty()) { return false; } - final String[] aliasParts = args.remove(0).split(PREFIX); - if (aliasParts.length < 2) + final String alias = args.get(0); + + if (alias.isEmpty()) { return false; } - final String alias = aliasParts[1]; - for (DiscordCommand command : commands) { if (command.getCommandName().equalsIgnoreCase(alias) || command.getAliases().contains(alias.toLowerCase())) From b4dd35c4df34d0f60aaa0ebd149ff0799d58ed05 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 15:13:17 +0100 Subject: [PATCH 18/25] Stop pinning minor & patch revisions of workflows --- .github/workflows/codacy-analysis.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/java17-maven.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codacy-analysis.yml b/.github/workflows/codacy-analysis.yml index 36f06235..f982745c 100644 --- a/.github/workflows/codacy-analysis.yml +++ b/.github/workflows/codacy-analysis.yml @@ -25,7 +25,7 @@ jobs: # Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis - name: Run Codacy Analysis CLI - uses: codacy/codacy-analysis-cli-action@v4.3.0 + uses: codacy/codacy-analysis-cli-action@v4 with: # Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository # You can also omit the token and run the tools that support default configurations diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 04854953..839de4aa 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -38,7 +38,7 @@ jobs: uses: actions/checkout@v3 - name: Setup Java JDK - uses: actions/setup-java@v3.11.0 + uses: actions/setup-java@v3 with: # The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28 java-version: 17 diff --git a/.github/workflows/java17-maven.yml b/.github/workflows/java17-maven.yml index 01a4721f..2d46e8e5 100644 --- a/.github/workflows/java17-maven.yml +++ b/.github/workflows/java17-maven.yml @@ -13,7 +13,7 @@ jobs: # Java 16 Builds - name: Set up JDK 17 - uses: actions/setup-java@v3.11.0 + uses: actions/setup-java@v3 with: java-version: 17 distribution: 'adopt' From 794a25ba1600eecaf862691f5981fab1d092cbfe Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 16:40:25 +0100 Subject: [PATCH 19/25] Remove getCommandMap() method in CommandBlocker --- .../blocking/command/CommandBlocker.java | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java index e1da4f2d..7a91d0cb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/command/CommandBlocker.java @@ -30,24 +30,6 @@ public class CommandBlocker extends FreedomService private final Map entryList = Maps.newHashMap(); private final List unknownCommands = Lists.newArrayList(); - public static CommandMap getCommandMap() - { - try - { - SimplePluginManager simplePluginManager = (SimplePluginManager)Bukkit.getServer().getPluginManager(); - - Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - - return (SimpleCommandMap)commandMapField.get(simplePluginManager); - } - catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) - { - FLog.severe("Failed to get command map field (" + e.getMessage() + ")"); - } - return null; - } - @Override public void onStart() { @@ -65,7 +47,7 @@ public class CommandBlocker extends FreedomService entryList.clear(); unknownCommands.clear(); - final CommandMap commandMap = getCommandMap(); + final CommandMap commandMap = Bukkit.getCommandMap(); @SuppressWarnings("unchecked") List blockedCommands = (List)ConfigEntry.BLOCKED_COMMANDS.getList(); From 9bef4581aa9a234ccd665de766c2a31bdd19fc07 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 17:08:05 +0100 Subject: [PATCH 20/25] Use Bukkit.getScheduler().runTaskAsynchronously to execute the report --- .../java/me/totalfreedom/totalfreedommod/discord/Discord.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 737e9362..0c6c8f1f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -478,7 +478,7 @@ public class Discord extends FreedomService } return true; - }); + }, t -> Bukkit.getScheduler().runTaskAsynchronously(plugin, t)); } // Do no ask why this is here. I spent two hours trying to make a simple thing work From 476c87ceb068c67f625980a13da5597a67a3022a Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 17:32:28 +0100 Subject: [PATCH 21/25] Improve Discord bridge sanitization --- .../totalfreedommod/discord/Discord.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java index 0c6c8f1f..fc4bb0b8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/discord/Discord.java @@ -279,12 +279,6 @@ public class Discord extends FreedomService { String newMessage = message; - if (message.contains("@")) - { - // \u200B is Zero Width Space, invisible on Discord - newMessage = message.replaceAll("@", "@\u200B"); - } - if (message.toLowerCase().contains("discord.gg")) // discord.gg/invite works as an invite { return ""; @@ -300,10 +294,10 @@ public class Discord extends FreedomService if (message.contains("§")) { - newMessage = message.replaceAll("§", ""); + newMessage = message.replace("§", ""); } - return deformat(newMessage); + return newMessage; } public void messageChatChannel(String message) @@ -321,7 +315,7 @@ public class Discord extends FreedomService if (enabled && !chat_channel_id.isEmpty()) { - CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).submit(true); + CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).allowedMentions(Collections.emptyList()).submit(true); sentMessages.add(sentMessage); } } @@ -341,7 +335,7 @@ public class Discord extends FreedomService if (enabled && !chat_channel_id.isEmpty()) { - CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).submit(true); + CompletableFuture sentMessage = Objects.requireNonNull(bot.getTextChannelById(chat_channel_id)).sendMessage(sanitizedMessage).allowedMentions(Collections.emptyList()).submit(true); sentMessages.add(sentMessage); } } @@ -512,6 +506,6 @@ public class Discord extends FreedomService return; } - messageChatChannel(player.getName() + " \u00BB " + ChatColor.stripColor(message)); + messageChatChannel(deformat(player.getName()) + " \u00BB " + ChatColor.stripColor(message)); } } \ No newline at end of file From 11c24cff68b14970ecab1158c32b6994a5f9a2d7 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 17:42:32 +0100 Subject: [PATCH 22/25] Ignore cancelled interact events --- .../totalfreedom/totalfreedommod/blocking/InteractBlocker.java | 2 +- src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index 08437c25..da48ab2b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -26,7 +26,7 @@ public class InteractBlocker extends FreedomService { } - @EventHandler(priority = EventPriority.HIGH) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { switch (event.getAction()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 08ae5252..773294d3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -95,7 +95,7 @@ public class ItemFun extends FreedomService { } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onPlayerEntityInteract(PlayerInteractEntityEvent event) { From 9e584069e6bd41695292fd52871f7f1b2f4f194e Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 17:43:15 +0100 Subject: [PATCH 23/25] Ignore interact events from Spectators --- .../totalfreedommod/blocking/InteractBlocker.java | 5 +++++ .../totalfreedom/totalfreedommod/fun/ItemFun.java | 13 ++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java index da48ab2b..a8183c32 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InteractBlocker.java @@ -4,6 +4,7 @@ import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.Groups; import org.bukkit.ChatColor; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.EntityType; @@ -69,6 +70,10 @@ public class InteractBlocker extends FreedomService private void handleRightClick(PlayerInteractEvent event) { final Player player = event.getPlayer(); + if (player.getGameMode().equals(GameMode.SPECTATOR)) { + return; + } + final Block clickedBlock = event.getClickedBlock(); if (clickedBlock != null && clickedBlock.getType() == Material.RESPAWN_ANCHOR && !ConfigEntry.ALLOW_RESPAWN_ANCHORS.getBoolean()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java index 773294d3..e3597942 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/ItemFun.java @@ -13,13 +13,7 @@ import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.shop.ShopItem; import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.SoundCategory; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Arrow; import org.bukkit.entity.EnderPearl; @@ -100,6 +94,11 @@ public class ItemFun extends FreedomService { Player player = event.getPlayer(); + if (player.getGameMode().equals(GameMode.SPECTATOR)) + { + return; + } + Entity entity = event.getRightClicked(); FPlayer fPlayer = plugin.pl.getPlayer(player); From 12512764510a20e798abac757000356dcf64a317 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 18:32:59 +0100 Subject: [PATCH 24/25] Fix formatting in AdminList --- .../java/me/totalfreedom/totalfreedommod/admin/AdminList.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 23715310..aa7f3441 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -274,7 +274,8 @@ public class AdminList extends FreedomService ResultSet currentSave = plugin.sql.getAdminByUuid(admin.getUuid()); for (Map.Entry entry : admin.toSQLStorable().entrySet()) { - Object storedValue = plugin.sql.getValue(currentSave, entry.getKey(), entry.getValue()); if (storedValue != null && !storedValue.equals(entry.getValue()) || storedValue == null && entry.getValue() != null || entry.getValue() == null) + Object storedValue = plugin.sql.getValue(currentSave, entry.getKey(), entry.getValue()); + if (storedValue != null && !storedValue.equals(entry.getValue()) || storedValue == null && entry.getValue() != null || entry.getValue() == null) { plugin.sql.setAdminValue(admin, entry.getKey(), entry.getValue()); } From 0559e99fb1e408bf8f165d9e9f0d0c3211aecbf1 Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 25 Jul 2023 18:56:06 +0100 Subject: [PATCH 25/25] Drop ptero_id column from admin table Fixes a SQLException thrown when adding admins to an older table schema version. --- .../java/me/totalfreedom/totalfreedommod/sql/SQLite.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index d435537e..70b026ff 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -90,6 +90,15 @@ public class SQLite extends FreedomService { FLog.severe("Failed to create the admins table: " + e.getMessage()); } + } else + { + try + { + connection.createStatement().execute("ALTER TABLE `admins` DROP COLUMN `ptero_id`"); + } catch (SQLException e) + { + // Ignore the error. If someone else wants to add WORKING AND TESTED CODE to check if the `ptero_id` column exists, they can, but I couldn't find a good way. + } } if (tableExists(meta, "players")) {