From 92c145090920fee5458f04e92260b620809b28a5 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 12 Mar 2013 15:15:25 +1100 Subject: [PATCH] Fix issue #129 - make chat event fire for commands, and add isCommand method. --- .../java/net/md_5/bungee/api/event/ChatEvent.java | 10 ++++++++++ .../net/md_5/bungee/connection/UpstreamBridge.java | 14 ++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java index 29c50a5c..a0c327f3 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java @@ -30,4 +30,14 @@ public class ChatEvent extends TargetedEvent implements Cancellable super( sender, receiver ); this.message = message; } + + /** + * Checks whether this message is valid as a command + * + * @return if this message is a command + */ + public boolean isCommand() + { + return message.charAt( 0 ) == '/'; + } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index b503116d..95f0d509 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -67,19 +67,17 @@ public class UpstreamBridge extends PacketHandler @Override public void handle(Packet3Chat chat) throws Exception { - if ( chat.message.charAt( 0 ) == '/' ) + ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.message ); + if ( bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) + { + throw new CancelSendSignal(); + } + if ( chatEvent.isCommand() ) { if ( bungee.getPluginManager().dispatchCommand( con, chat.message.substring( 1 ) ) ) { throw new CancelSendSignal(); } - } else - { - ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.message ); - if ( bungee.getPluginManager().callEvent( chatEvent ).isCancelled() ) - { - throw new CancelSendSignal(); - } } }