diff --git a/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java b/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java index 759fc16..d29eb3e 100644 --- a/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java +++ b/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java @@ -61,28 +61,23 @@ public class CommandQueueWatcher { isCommandBookCommand = plugin.commandBookHook.isCommandBookCommand(cmd); plugin.logDebug("Is this is a CommandBook command? " + Boolean.toString(isCommandBookCommand)); } - if ( - (plugin.getServer().getVersion().contains("MC: 1.8") + if ((plugin.getServer().getVersion().contains("MC: 1.8") && (plugin.getServer().getVersion().contains("Spigot")) && plugin.getServer().getPluginCommand(cmd) == null && !isCommandBookCommand) - || - (plugin.getServer().getVersion().contains("MC: 1.9") + || (plugin.getServer().getVersion().contains("MC: 1.9") && plugin.getServer().getPluginCommand(cmd) == null && !isCommandBookCommand) - || - (plugin.getServer().getVersion().contains("MC: 1.10") + || (plugin.getServer().getVersion().contains("MC: 1.10") && plugin.getServer().getPluginCommand(cmd) == null && !isCommandBookCommand) - || - (plugin.getServer().getVersion().contains("MC: 1.11") + || (plugin.getServer().getVersion().contains("MC: 1.11") && plugin.getServer().getPluginCommand(cmd) == null - && !isCommandBookCommand) - ) { + && !isCommandBookCommand)) { plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand()); plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand()); - ircCommand.getIRCConsoleCommandSender().sendMessage(plugin.tokenizer.ircCommandSentTokenizer(ircCommand.getGameCommand())); + ircCommand.getIRCConsoleCommandSender().sendMessage(plugin.tokenizer.ircCommandSentTokenizer(ircCommand.getGameCommand())); } else { plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand()); plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand()); @@ -90,7 +85,10 @@ public class CommandQueueWatcher { } catch (CommandException ce) { plugin.logError("Error running command: " + ce.getMessage()); } - plugin.getServer().getPluginManager().callEvent(new IRCCommandEvent(ircCommand)); + IRCCommandEvent event = new IRCCommandEvent(ircCommand); + if (!event.isCancelled()) { + plugin.getServer().getPluginManager().callEvent(event); + } } } @@ -108,7 +106,7 @@ public class CommandQueueWatcher { /** * Add an IRCCommand to the command queue - * + * * @param command the IRC command to add to the queue */ public void add(IRCCommand command) { diff --git a/src/main/java/com/cnaude/purpleirc/Events/IRCCommandEvent.java b/src/main/java/com/cnaude/purpleirc/Events/IRCCommandEvent.java index 7541241..a026938 100644 --- a/src/main/java/com/cnaude/purpleirc/Events/IRCCommandEvent.java +++ b/src/main/java/com/cnaude/purpleirc/Events/IRCCommandEvent.java @@ -17,6 +17,7 @@ package com.cnaude.purpleirc.Events; import com.cnaude.purpleirc.IRCCommand; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -25,10 +26,11 @@ import org.bukkit.event.HandlerList; * @author Chris Naude Event listener for plugins that want to catch command events * from PurpleIRC */ -public class IRCCommandEvent extends Event { +public class IRCCommandEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); private final IRCCommand ircCommand; + private boolean cancelled; /** * @@ -62,4 +64,14 @@ public class IRCCommandEvent extends Event { public static HandlerList getHandlerList() { return HANDLERS; } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } }