diff options
Diffstat (limited to 'dicore3/command/src/main/java/io/dico/dicore/command/Command.java')
-rw-r--r-- | dicore3/command/src/main/java/io/dico/dicore/command/Command.java | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/dicore3/command/src/main/java/io/dico/dicore/command/Command.java b/dicore3/command/src/main/java/io/dico/dicore/command/Command.java index b66b5f5..868aa95 100644 --- a/dicore3/command/src/main/java/io/dico/dicore/command/Command.java +++ b/dicore3/command/src/main/java/io/dico/dicore/command/Command.java @@ -145,43 +145,50 @@ public abstract class Command { ExecutionContext executionContext = new ExecutionContext(sender, caller, this, buffer, false); try { - //System.out.println("In Command.execute(sender, caller, buffer)#try{"); - int i, n; - for (i = 0, n = contextFilterPostParameterIndex; i < n; i++) { - contextFilters.get(i).filterContext(executionContext); - } - - executionContext.parseParameters(); + executeWithContext(executionContext); + } catch (Throwable t) { + caller.getChatController().handleException(sender, executionContext, t); + } + } - for (n = contextFilters.size(); i < n; i++) { - contextFilters.get(i).filterContext(executionContext); - } + public void executeWithContext(ExecutionContext context) throws CommandException { + //System.out.println("In Command.execute(sender, caller, buffer)#try{"); + int i, n; + for (i = 0, n = contextFilterPostParameterIndex; i < n; i++) { + contextFilters.get(i).filterContext(context); + } - //System.out.println("Post-contextfilters"); + context.parseParameters(); - String message = execute(sender, executionContext); - caller.getChatController().sendMessage(sender, EMessageType.RESULT, message); - } catch (Throwable t) { - caller.getChatController().handleException(sender, executionContext, t); + for (n = contextFilters.size(); i < n; i++) { + contextFilters.get(i).filterContext(context); } + + //System.out.println("Post-contextfilters"); + + String message = execute(context.getSender(), context); + context.getAddress().getChatController().sendMessage(context.getSender(), EMessageType.RESULT, message); } public abstract String execute(CommandSender sender, ExecutionContext context) throws CommandException; public List<String> tabComplete(CommandSender sender, ICommandAddress caller, Location location, ArgumentBuffer buffer) { ExecutionContext executionContext = new ExecutionContext(sender, caller, this, buffer, true); - try { - int i, n; - for (i = 0, n = contextFilterPostParameterIndex; i < n; i++) { - contextFilters.get(i).filterContext(executionContext); - } + return tabCompleteWithContext(executionContext, location); } catch (CommandException ex) { return Collections.emptyList(); } + } + + public List<String> tabCompleteWithContext(ExecutionContext context, Location location) throws CommandException { + int i, n; + for (i = 0, n = contextFilterPostParameterIndex; i < n; i++) { + contextFilters.get(i).filterContext(context); + } - executionContext.parseParametersQuietly(); - return tabComplete(sender, executionContext, location); + context.parseParametersQuietly(); + return tabComplete(context.getSender(), context, location); } public List<String> tabComplete(CommandSender sender, ExecutionContext context, Location location) { |