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,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) {

View File

@ -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;
}
}