From 15ece1a3dc14880afa0d8dbed691ee027e15a93a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 18 Dec 2016 12:57:57 +0100 Subject: [PATCH] Made custom chat event cancellable --- src/main/java/buttondevteam/chat/ChatProcessing.java | 4 ++-- .../java/buttondevteam/chat/listener/PlayerListener.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 412fc38..11b8c45 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -46,7 +46,7 @@ public class ChatProcessing { "dark_purple" }; // TODO private static boolean pingedconsole = false; - // Returns e.setCancelled + // Returns e.setCancelled for custom event public static boolean ProcessChat(Channel channel, CommandSender sender, String message) { long processstart = System.nanoTime(); if (PluginMain.essentials == null) @@ -398,6 +398,6 @@ public class ChatProcessing { DebugCommand.SendDebugMessage( "-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms"); DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms"); - return true; + return false; } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 062c8c0..336cbeb 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -63,14 +63,14 @@ public class PlayerListener implements Listener { public final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" }; - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) return; TBMCChatAPI.SendChatMessage( TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel, event.getPlayer(), event.getMessage()); - event.setCancelled(true); + event.setCancelled(true); // The custom event should only be cancelled when muted or similar } @EventHandler(priority = EventPriority.HIGHEST) @@ -339,7 +339,7 @@ public class PlayerListener implements Listener { @EventHandler public void onPlayerTBMCChat(TBMCChatEvent e) { try { - ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()); + e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage())); } catch (Exception ex) { for (Player p : Bukkit.getOnlinePlayers()) p.sendMessage("§c!§r[" @@ -347,6 +347,7 @@ public class PlayerListener implements Listener { ? ((Player) e.getSender()).getDisplayName() : e.getSender().getName()) + "> " + e.getMessage()); TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex); + e.setCancelled(true); } } }