From 2c155c241b82916238fa40924547c7a0a30fc328 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Mon, 8 Aug 2011 10:45:19 +0200 Subject: [PATCH] Added an invokeMethod hook to CommandsManager, that wraps method invocation and can be overridden --- .../util/commands/CommandsManager.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java b/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java index 6b7acd161..0c6f3241f 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java @@ -398,19 +398,23 @@ public void executeMethod(Method parent, String[] args, Object instance = instances.get(method); - try { - method.invoke(instance, methodArgs); - } catch (IllegalArgumentException e) { - logger.log(Level.SEVERE, "Failed to execute command", e); - } catch (IllegalAccessException e) { - logger.log(Level.SEVERE, "Failed to execute command", e); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof CommandException) { - throw (CommandException) e.getCause(); - } - - throw new WrappedCommandException(e.getCause()); + invokeMethod(parent, args, player, method, instance, methodArgs, argsCount); + } + } + + public void invokeMethod(Method parent, String[] args, T player, Method method, Object instance, Object[] methodArgs, int level) throws CommandException { + try { + method.invoke(instance, methodArgs); + } catch (IllegalArgumentException e) { + logger.log(Level.SEVERE, "Failed to execute command", e); + } catch (IllegalAccessException e) { + logger.log(Level.SEVERE, "Failed to execute command", e); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof CommandException) { + throw (CommandException) e.getCause(); } + + throw new WrappedCommandException(e.getCause()); } }