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)