IRCCommandEvent should be cancellable.

This commit is contained in:
cnaude 2017-06-15 20:40:20 -07:00
parent e765453811
commit e975975688
2 changed files with 24 additions and 14 deletions

View File

@ -61,24 +61,19 @@ public class CommandQueueWatcher {
isCommandBookCommand = plugin.commandBookHook.isCommandBookCommand(cmd); isCommandBookCommand = plugin.commandBookHook.isCommandBookCommand(cmd);
plugin.logDebug("Is this is a CommandBook command? " + Boolean.toString(isCommandBookCommand)); plugin.logDebug("Is this is a CommandBook command? " + Boolean.toString(isCommandBookCommand));
} }
if ( if ((plugin.getServer().getVersion().contains("MC: 1.8")
(plugin.getServer().getVersion().contains("MC: 1.8")
&& (plugin.getServer().getVersion().contains("Spigot")) && (plugin.getServer().getVersion().contains("Spigot"))
&& plugin.getServer().getPluginCommand(cmd) == null && plugin.getServer().getPluginCommand(cmd) == null
&& !isCommandBookCommand) && !isCommandBookCommand)
|| || (plugin.getServer().getVersion().contains("MC: 1.9")
(plugin.getServer().getVersion().contains("MC: 1.9")
&& plugin.getServer().getPluginCommand(cmd) == null && plugin.getServer().getPluginCommand(cmd) == null
&& !isCommandBookCommand) && !isCommandBookCommand)
|| || (plugin.getServer().getVersion().contains("MC: 1.10")
(plugin.getServer().getVersion().contains("MC: 1.10")
&& plugin.getServer().getPluginCommand(cmd) == null && plugin.getServer().getPluginCommand(cmd) == null
&& !isCommandBookCommand) && !isCommandBookCommand)
|| || (plugin.getServer().getVersion().contains("MC: 1.11")
(plugin.getServer().getVersion().contains("MC: 1.11")
&& plugin.getServer().getPluginCommand(cmd) == null && plugin.getServer().getPluginCommand(cmd) == null
&& !isCommandBookCommand) && !isCommandBookCommand)) {
) {
plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand()); plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand());
plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand()); plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand());
@ -90,7 +85,10 @@ public class CommandQueueWatcher {
} catch (CommandException ce) { } catch (CommandException ce) {
plugin.logError("Error running command: " + ce.getMessage()); 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);
}
} }
} }

View File

@ -17,6 +17,7 @@
package com.cnaude.purpleirc.Events; package com.cnaude.purpleirc.Events;
import com.cnaude.purpleirc.IRCCommand; import com.cnaude.purpleirc.IRCCommand;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; 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 * @author Chris Naude Event listener for plugins that want to catch command events
* from PurpleIRC * from PurpleIRC
*/ */
public class IRCCommandEvent extends Event { public class IRCCommandEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();
private final IRCCommand ircCommand; private final IRCCommand ircCommand;
private boolean cancelled;
/** /**
* *
@ -62,4 +64,14 @@ public class IRCCommandEvent extends Event {
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return HANDLERS; return HANDLERS;
} }
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
} }