From 6a698bd54212d5bb0e104eefa66f16d4b9f85fdc Mon Sep 17 00:00:00 2001 From: cnaude Date: Wed, 21 Jun 2017 06:58:29 -0700 Subject: [PATCH] Better command exception handling. Fallback to ConsoleSender for vanilla commands. --- .../cnaude/purpleirc/CommandQueueWatcher.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java b/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java index f2f037b..5932300 100644 --- a/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java +++ b/src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java @@ -55,12 +55,27 @@ public class CommandQueueWatcher { if (ircCommand != null) { try { String cmd = ircCommand.getGameCommand().split(" ")[0]; - boolean isCommandBookCommand = false; + plugin.logDebug("CMD: " + cmd); + /* + boolean isCommandBookCommand = false; if (plugin.commandBookHook != null) { isCommandBookCommand = plugin.commandBookHook.isCommandBookCommand(cmd); plugin.logDebug("Is this is a CommandBook command? " + Boolean.toString(isCommandBookCommand)); } + */ + + try { + plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand()); + plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand()); + } catch (CommandException ex) { + plugin.logDebug("Falling back to ConsoleSender: " + ircCommand.getGameCommand()); + + plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand()); + ircCommand.getIRCConsoleCommandSender().sendMessage(plugin.tokenizer.ircCommandSentTokenizer(ircCommand.getGameCommand())); + } + + /* if ((plugin.getServer().getVersion().contains("MC: 1.8") && (plugin.getServer().getVersion().contains("Spigot")) && plugin.getServer().getPluginCommand(cmd) == null @@ -81,7 +96,8 @@ public class CommandQueueWatcher { } else { plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand()); plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand()); - } + } + */ } catch (CommandException ce) { plugin.logError("Error running command: " + ce.getMessage()); }