From aae2b13e97ba8237b7e4c22e9a9005c03de659e7 Mon Sep 17 00:00:00 2001 From: xGinko Date: Tue, 5 Mar 2024 14:01:36 +0100 Subject: [PATCH] improve dirty reload compatibility improve join/leave messages --- .../AnarchyExploitFixes.java | 19 ++++- .../commands/ToggleConnectionMsgsCommand.java | 6 +- .../enums/NamespacedKeys.java | 2 +- .../modules/misc/FirstJoinMessages.java | 4 +- .../modules/misc/JoinLeaveMessages.java | 83 ++++++++----------- .../AnarchyExploitFixes.java | 34 ++++++-- .../commands/ToggleConnectionMsgsCommand.java | 9 +- .../modules/misc/FirstJoinMessages.java | 4 +- .../modules/misc/JoinLeaveMessages.java | 52 ++++-------- 9 files changed, 107 insertions(+), 106 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java index 0657a35bc..b7834c4cf 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java @@ -33,6 +33,7 @@ public class AnarchyExploitFixes extends JavaPlugin { private static Config config; private static TPSCache tpsCache; private static Logger logger; + private static Metrics metrics; private static boolean isServerFolia, foundProtocolLib; @Override @@ -87,11 +88,27 @@ public void onEnable() { AnarchyExploitFixesCommand.registerCommands(); logger.info("Loading metrics"); - new Metrics(this, 8700); + metrics = new Metrics(this, 8700); logger.info("Done."); } + @Override + public void onDisable() { + AnarchyExploitFixesModule.modules.forEach(AnarchyExploitFixesModule::disable); + AnarchyExploitFixesModule.modules.clear(); + if (metrics != null) { + metrics.shutdown(); + metrics = null; + } + instance = null; + config = null; + languageCacheMap = null; + tpsCache = null; + logger = null; + isServerFolia = foundProtocolLib = false; + } + public static AnarchyExploitFixes getInstance() { return instance; } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java index 3a20b52a8..46f0d65e2 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java @@ -30,13 +30,13 @@ public void onConMsgToggle(final CommandSender sender) { final boolean msgsWereVisible; PersistentDataContainer dataContainer = player.getPersistentDataContainer(); - if (!dataContainer.has(NamespacedKeys.SHOW_CONNECTION_MSGS.key(), PersistentDataType.BOOLEAN)) { + if (!dataContainer.has(NamespacedKeys.CONNECT_MSG_TOGGLE.key(), PersistentDataType.BOOLEAN)) { msgsWereVisible = AnarchyExploitFixes.getConfiguration().connectionMsgsAreOnByDefault; } else { - msgsWereVisible = dataContainer.get(NamespacedKeys.SHOW_CONNECTION_MSGS.key(), PersistentDataType.BOOLEAN); + msgsWereVisible = dataContainer.get(NamespacedKeys.CONNECT_MSG_TOGGLE.key(), PersistentDataType.BOOLEAN); } - dataContainer.set(NamespacedKeys.SHOW_CONNECTION_MSGS.key(), PersistentDataType.BOOLEAN, !msgsWereVisible); + dataContainer.set(NamespacedKeys.CONNECT_MSG_TOGGLE.key(), PersistentDataType.BOOLEAN, !msgsWereVisible); if (msgsWereVisible) { player.sendMessage(AnarchyExploitFixes.getLang(player.locale()).misc_disabledConnectionMsgs); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/NamespacedKeys.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/NamespacedKeys.java index b9a8db299..54da0ac88 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/NamespacedKeys.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/NamespacedKeys.java @@ -5,7 +5,7 @@ public enum NamespacedKeys { - SHOW_CONNECTION_MSGS(AnarchyExploitFixes.getKey("show-connection-msgs")); + CONNECT_MSG_TOGGLE(AnarchyExploitFixes.getKey("show-connection-msgs")); private final NamespacedKey key; diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java index 609db34e0..5a5c52ea0 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java @@ -75,10 +75,10 @@ private void onPlayerJoinEvent(PlayerJoinEvent event) { for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { final boolean showConnects; PersistentDataContainer dataContainer = onlinePlayer.getPersistentDataContainer(); - if (!dataContainer.has(NamespacedKeys.SHOW_CONNECTION_MSGS.key())) { + if (!dataContainer.has(NamespacedKeys.CONNECT_MSG_TOGGLE.key())) { showConnects = config.connectionMsgsAreOnByDefault; } else { - showConnects = dataContainer.get(NamespacedKeys.SHOW_CONNECTION_MSGS.key(), PersistentDataType.BOOLEAN); + showConnects = dataContainer.get(NamespacedKeys.CONNECT_MSG_TOGGLE.key(), PersistentDataType.BOOLEAN); } if (showConnects) { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java index f4c26a7e7..174d37789 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java @@ -25,7 +25,9 @@ public JoinLeaveMessages() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("misc.join-leave-messages.enable", "If you want to hide yourself or someone else when logging into the game,\nuse these permissions: anarchyexploitfixes.silentJoin, anarchyexploitfixes.silentLeave"); + config.addComment("misc.join-leave-messages.enable", + "If you want to hide yourself or someone else when logging into the game,\n" + + "use these permissions: anarchyexploitfixes.silentJoin, anarchyexploitfixes.silentLeave"); this.connectionMsgsOnByDefault = config.connectionMsgsAreOnByDefault; this.showInConsole = config.getBoolean("misc.join-leave-messages.show-in-console", false); this.firstJoinEnabled = config.getBoolean("misc.join-leave-messages.first-join-messages.enable", false); @@ -59,73 +61,54 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerJoinEvent(PlayerJoinEvent event) { event.joinMessage(null); - Player joiningPlayer = event.getPlayer(); - if (firstJoinEnabled && !joiningPlayer.hasPlayedBefore()) return; + final Player joiningPlayer = event.getPlayer(); if (joiningPlayer.hasPermission("anarchyexploitfixes.silentJoin")) return; + if (firstJoinEnabled && !joiningPlayer.hasPlayedBefore()) return; - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - final boolean showJoin; - PersistentDataContainer dataContainer = onlinePlayer.getPersistentDataContainer(); - if (!dataContainer.has(NamespacedKeys.SHOW_CONNECTION_MSGS.key())) { - showJoin = connectionMsgsOnByDefault; - } else { - showJoin = dataContainer.get(NamespacedKeys.SHOW_CONNECTION_MSGS.key(), PersistentDataType.BOOLEAN); - } - - if (showJoin) { - sendJoinMessage(onlinePlayer, joiningPlayer); - } + for (final Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { + onlinePlayer.getScheduler().execute(plugin, () -> { + final PersistentDataContainer dataContainer = onlinePlayer.getPersistentDataContainer(); + if ( + !dataContainer.has(NamespacedKeys.CONNECT_MSG_TOGGLE.key()) ? connectionMsgsOnByDefault : + dataContainer.get(NamespacedKeys.CONNECT_MSG_TOGGLE.key(), PersistentDataType.BOOLEAN) + ) { + onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.locale()).misc_joinMessage + .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(joiningPlayer.name()).build())); + } + }, null, 1L); } if (showInConsole) { - // Send to ConsoleSender so we can display colors - plugin.getServer().getConsoleSender().sendMessage(AnarchyExploitFixes.getLang(joiningPlayer.locale()).misc_joinMessage + plugin.getComponentLogger().info(AnarchyExploitFixes.getLang(joiningPlayer.locale()).misc_joinMessage .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(joiningPlayer.name()).build()) - .append(Component.text(" (" + joiningPlayer.locale() + ")")) - ); + .append(Component.text(" (" + joiningPlayer.locale() + ")"))); } } - private void sendJoinMessage(Player receiver, Player joiningPlayer) { - receiver.sendMessage(AnarchyExploitFixes.getLang(receiver.locale()).misc_joinMessage - .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(joiningPlayer.name()).build()) - ); - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerLeaveEvent(PlayerQuitEvent event) { event.quitMessage(null); - Player leavingPlayer = event.getPlayer(); + final Player leavingPlayer = event.getPlayer(); if (leavingPlayer.hasPermission("anarchyexploitfixes.silentLeave")) return; - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if (onlinePlayer.equals(leavingPlayer)) continue; // No need to send it to the leaver - - final boolean showLeave; - PersistentDataContainer dataContainer = onlinePlayer.getPersistentDataContainer(); - if (!dataContainer.has(NamespacedKeys.SHOW_CONNECTION_MSGS.key())) { - showLeave = connectionMsgsOnByDefault; - } else { - showLeave = dataContainer.get(NamespacedKeys.SHOW_CONNECTION_MSGS.key(), PersistentDataType.BOOLEAN); - } - - if (showLeave) { - sendLeaveMessage(onlinePlayer, leavingPlayer); - } + for (final Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { + onlinePlayer.getScheduler().execute(plugin, () -> { + if (onlinePlayer.getUniqueId().equals(leavingPlayer.getUniqueId())) return; + final PersistentDataContainer dataContainer = onlinePlayer.getPersistentDataContainer(); + if ( + !dataContainer.has(NamespacedKeys.CONNECT_MSG_TOGGLE.key()) ? connectionMsgsOnByDefault : + dataContainer.get(NamespacedKeys.CONNECT_MSG_TOGGLE.key(), PersistentDataType.BOOLEAN) + ) { + onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.locale()).misc_leaveMessage + .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(leavingPlayer.name()).build())); + } + }, null, 1L); } if (showInConsole) { - // Send to ConsoleSender so we can display colors - plugin.getServer().getConsoleSender().sendMessage(AnarchyExploitFixes.getLang(leavingPlayer.locale()).misc_leaveMessage + plugin.getComponentLogger().info(AnarchyExploitFixes.getLang(leavingPlayer.locale()).misc_leaveMessage .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(leavingPlayer.name()).build()) - .append(Component.text(" (" + leavingPlayer.locale() + ")")) - ); + .append(Component.text(" (" + leavingPlayer.locale() + ")"))); } } - - private void sendLeaveMessage(Player onlinePlayer, Player leavingPlayer) { - onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.locale()).misc_leaveMessage - .replaceText(TextReplacementConfig.builder().matchLiteral("%player%").replacement(leavingPlayer.name()).build()) - ); - } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java index 4f3065150..a234dfdba 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/AnarchyExploitFixes.java @@ -9,6 +9,7 @@ import org.bstats.bukkit.Metrics; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -28,11 +29,11 @@ public class AnarchyExploitFixes extends JavaPlugin { private static HashMap languageCacheMap; private static Config config; private static Logger logger; - private static int minorMCVersion; + private static Metrics metrics; private static boolean foundProtocolLib; public TPSCache tpsCache; - public final Set CONNECTION_MSG_TOGGLE = new HashSet<>(); + public static final Set CONNECT_MSG_TOGGLE = new HashSet<>(); @Override public void onEnable() { @@ -63,12 +64,11 @@ public void onEnable() { return; } - minorMCVersion = PaperLib.getMinecraftVersion(); - logger.info("Detected Version 1." + minorMCVersion + "." + PaperLib.getMinecraftPatchVersion()); + logger.info("Detected Version 1." + PaperLib.getMinecraftVersion() + "." + PaperLib.getMinecraftPatchVersion()); foundProtocolLib = getServer().getPluginManager().isPluginEnabled("ProtocolLib"); logger.info(foundProtocolLib ? "Found ProtocolLib" : "Could not find ProtocolLib"); - if (minorMCVersion < 12) { + if (PaperLib.getMinecraftVersion() < 12) { logger.warning("##########################################################"); logger.warning("# #"); logger.warning("# WARNING #"); @@ -90,11 +90,29 @@ public void onEnable() { AnarchyExploitFixesCommand.registerCommands(); logger.info("Loading metrics"); - new Metrics(this, 8700); + metrics = new Metrics(this, 8700); logger.info("Done."); } + @Override + public void onDisable() { + getServer().getScheduler().cancelTasks(this); + HandlerList.unregisterAll(this); + AnarchyExploitFixesModule.unregisterPacketListeners(this); + AnarchyExploitFixesModule.modules.clear(); + if (metrics != null) { + metrics.shutdown(); + metrics = null; + } + instance = null; + config = null; + languageCacheMap = null; + tpsCache = null; + logger = null; + foundProtocolLib = false; + } + public static AnarchyExploitFixes getInstance() { return instance; } @@ -118,7 +136,7 @@ public static LanguageCache getLang(String lang) { return languageCacheMap.getOrDefault(lang.replace("-", "_"), languageCacheMap.get(config.default_lang.toString().toLowerCase())); } public static int getMCVersion() { - return minorMCVersion; + return PaperLib.getMinecraftVersion(); } public static boolean isProtocolLibInstalled() { return foundProtocolLib; @@ -132,8 +150,8 @@ public void reloadPlugin() { private void reloadConfiguration() { try { config = new Config(); + tpsCache = TPSCache.create(config.max_tps_check_interval_millis); AnarchyExploitFixesModule.reloadModules(); - this.tpsCache = TPSCache.create(config.max_tps_check_interval_millis); config.saveConfig(); } catch (Exception e) { logger.severe("Failed to load config file! - " + e.getLocalizedMessage()); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java index 0c1ba3062..72a37145b 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/commands/ToggleConnectionMsgsCommand.java @@ -23,11 +23,10 @@ public void onConMsgToggle(final CommandSender sender) { return; } - AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); - Player player = (Player) sender; + final Player player = (Player) sender; - if (plugin.CONNECTION_MSG_TOGGLE.contains(player.getUniqueId())) { - plugin.CONNECTION_MSG_TOGGLE.remove(player.getUniqueId()); + if (AnarchyExploitFixes.CONNECT_MSG_TOGGLE.contains(player.getUniqueId())) { + AnarchyExploitFixes.CONNECT_MSG_TOGGLE.remove(player.getUniqueId()); if (AnarchyExploitFixes.getConfiguration().connectionMsgsAreOnByDefault) { sender.sendMessage(AnarchyExploitFixes.getLang(player.getLocale()).misc_enabledConnectionMsgs); @@ -35,7 +34,7 @@ public void onConMsgToggle(final CommandSender sender) { sender.sendMessage(AnarchyExploitFixes.getLang(player.getLocale()).misc_disabledConnectionMsgs); } } else { - plugin.CONNECTION_MSG_TOGGLE.add(player.getUniqueId()); + AnarchyExploitFixes.CONNECT_MSG_TOGGLE.add(player.getUniqueId()); if (AnarchyExploitFixes.getConfiguration().connectionMsgsAreOnByDefault) { sender.sendMessage(AnarchyExploitFixes.getLang(player.getLocale()).misc_disabledConnectionMsgs); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java index 91fd1b1ea..7b6b226dd 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/FirstJoinMessages.java @@ -64,8 +64,8 @@ private void onPlayerJoinEvent(PlayerJoinEvent event) { for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { if ( - config.connectionMsgsAreOnByDefault && !plugin.CONNECTION_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) - || !config.connectionMsgsAreOnByDefault && plugin.CONNECTION_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) + config.connectionMsgsAreOnByDefault && !AnarchyExploitFixes.CONNECT_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) + || !config.connectionMsgsAreOnByDefault && AnarchyExploitFixes.CONNECT_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) ) { sendFirstJoinMessage(onlinePlayer, joiningPlayer, joiningPlayersNumber); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java index a885a0d37..cb173fdf6 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/misc/JoinLeaveMessages.java @@ -20,7 +20,9 @@ public JoinLeaveMessages() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("misc.join-leave-messages.enable", "If you want to hide yourself or someone else when logging into the game,\nuse these permissions: anarchyexploitfixes.silentJoin, anarchyexploitfixes.silentLeave"); + config.addComment("misc.join-leave-messages.enable", + "If you want to hide yourself or someone else when logging into the game,\n" + + "use these permissions: anarchyexploitfixes.silentJoin, anarchyexploitfixes.silentLeave"); this.connectionMsgsOnByDefault = config.connectionMsgsAreOnByDefault; this.showInConsole = config.getBoolean("misc.join-leave-messages.show-in-console", false); this.firstJoinEnabled = config.getBoolean("misc.join-leave-messages.first-join-messages.enable", false); @@ -49,55 +51,37 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerJoinEvent(PlayerJoinEvent event) { event.setJoinMessage(null); - Player joiningPlayer = event.getPlayer(); - if (firstJoinEnabled && !joiningPlayer.hasPlayedBefore()) return; + final Player joiningPlayer = event.getPlayer(); if (joiningPlayer.hasPermission("anarchyexploitfixes.silentJoin")) return; + if (firstJoinEnabled && !joiningPlayer.hasPlayedBefore()) return; - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if ( - connectionMsgsOnByDefault && !plugin.CONNECTION_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) - || !connectionMsgsOnByDefault && plugin.CONNECTION_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) - ) { - sendJoinMessage(onlinePlayer, joiningPlayer); + for (final Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { + if (connectionMsgsOnByDefault != AnarchyExploitFixes.CONNECT_MSG_TOGGLE.contains(onlinePlayer.getUniqueId())) { + onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.getLocale()).misc_joinMessage + .replace("%player%", joiningPlayer.getName())); } } - // Use Bukkit.getLogger() here to avoid using the plugin's prefix + // Use Bukkit.getLogger() here so we can log without prefix if (showInConsole) Bukkit.getLogger().info(AnarchyExploitFixes.getLang(joiningPlayer.getLocale()).misc_joinMessage - .replace("%player%", joiningPlayer.getName()) - +" ("+joiningPlayer.getLocale()+")" - ); - } - - private void sendJoinMessage(Player receiver, Player joiningPlayer) { - receiver.sendMessage(AnarchyExploitFixes.getLang(receiver.getLocale()).misc_joinMessage.replace("%player%", joiningPlayer.getName())); + .replace("%player%", joiningPlayer.getName()) + " ("+joiningPlayer.getLocale() + ")"); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerLeaveEvent(PlayerQuitEvent event) { event.setQuitMessage(null); - Player leavingPlayer = event.getPlayer(); + final Player leavingPlayer = event.getPlayer(); if (leavingPlayer.hasPermission("anarchyexploitfixes.silentLeave")) return; - for (Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { - if (onlinePlayer.equals(leavingPlayer)) continue; // No need to send it to the leaver - if ( - connectionMsgsOnByDefault && !plugin.CONNECTION_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) - || !connectionMsgsOnByDefault && plugin.CONNECTION_MSG_TOGGLE.contains(onlinePlayer.getUniqueId()) - ) { - sendLeaveMessage(onlinePlayer, leavingPlayer); + for (final Player onlinePlayer : plugin.getServer().getOnlinePlayers()) { + if (onlinePlayer.getUniqueId().equals(leavingPlayer.getUniqueId())) continue; + if (connectionMsgsOnByDefault != AnarchyExploitFixes.CONNECT_MSG_TOGGLE.contains(onlinePlayer.getUniqueId())) { + onlinePlayer.sendMessage(AnarchyExploitFixes.getLang(onlinePlayer.getLocale()).misc_leaveMessage + .replace("%player%", leavingPlayer.getName())); } } if (showInConsole) Bukkit.getLogger().info(AnarchyExploitFixes.getLang(leavingPlayer.getLocale()).misc_leaveMessage - .replace("%player%", leavingPlayer.getName()) - +" ("+leavingPlayer.getLocale()+")" - ); - } - - private void sendLeaveMessage(Player receiver, Player leavingPlayer) { - receiver.sendMessage(AnarchyExploitFixes.getLang(receiver.getLocale()).misc_leaveMessage - .replace("%player%", leavingPlayer.getName()) - ); + .replace("%player%", leavingPlayer.getName()) + " (" + leavingPlayer.getLocale() + ")"); } }