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 | 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()); } }
/** * Called on a command. */ @Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { try { commands.execute(cmd.getName(), args, sender, sender); } catch (CommandPermissionsException e) { sender.sendMessage(ChatColor.RED + "You don't have permission."); } catch (MissingNestedCommandException e) { sender.sendMessage(ChatColor.RED + e.getUsage()); } catch (CommandUsageException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); sender.sendMessage(ChatColor.RED + e.getUsage()); } catch (WrappedCommandException e) { if (e.getCause() instanceof NumberFormatException) { sender.sendMessage(ChatColor.RED + "Number expected, string received instead."); } else { sender.sendMessage(ChatColor.RED + "An error has occurred. See console."); e.printStackTrace(); } } catch (CommandException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); } return true; }
Throwable t = e.getCause(); actor.printError("Please report this error: [See console]"); actor.printRaw(t.getClass().getName() + ": " + t.getMessage());
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { try { Actor actor = wrapCommandSender(sender); try { commands.execute(cmd.getName(), args, actor, actor); } catch (Throwable t) { Throwable next = t; do { WorldGuard.getInstance().getExceptionConverter().convert(next); next = next.getCause(); } while (next != null); throw t; } } catch (CommandPermissionsException e) { sender.sendMessage(ChatColor.RED + "You don't have permission."); } catch (MissingNestedCommandException e) { sender.sendMessage(ChatColor.RED + e.getUsage()); } catch (CommandUsageException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); sender.sendMessage(ChatColor.RED + e.getUsage()); } catch (WrappedCommandException e) { sender.sendMessage(ChatColor.RED + e.getCause().getMessage()); } catch (CommandException e) { sender.sendMessage(ChatColor.RED + e.getMessage()); } return true; }
@Override public void convert(Throwable t) throws CommandException { Class<?> throwableClass = t.getClass(); for (ExceptionHandler handler : handlers) { if (handler.cls.isAssignableFrom(throwableClass)) { try { handler.method.invoke(this, t); } catch (InvocationTargetException e) { if (e.getCause() instanceof CommandException) { throw (CommandException) e.getCause(); } throw new WrappedCommandException(e); } catch (IllegalArgumentException | IllegalAccessException e) { throw new WrappedCommandException(e); } } } }
@Override public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException { // We have permission for this command if we have permissions for subcommands if (parentCommands.length != 0 && !testPermission(locals)) { throw new CommandPermissionsException(); } String[] split = CommandContext.split(arguments); Set<String> aliases = getPrimaryAliases(); if (aliases.isEmpty()) { throw new InvalidUsageException("This command has no sub-commands.", this); } else if (split.length > 0) { String subCommand = split[0]; String subArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length)); String[] subParents = Arrays.copyOf(parentCommands, parentCommands.length + 1); subParents[parentCommands.length] = subCommand; CommandMapping mapping = get(subCommand); if (mapping != null) { try { return mapping.getCallable().call(subArguments, locals, subParents); } catch (CommandException e) { e.prependStack(subCommand); throw e; } catch (Throwable t) { throw new WrappedCommandException(t); } } } throw new InvalidUsageException("Please choose a sub-command.", this, true); }
throw (CommandException) e.getCause(); throw new WrappedCommandException(e); } catch (Throwable t) { throw new WrappedCommandException(t);
@Override public Deform call(CommandArgs args, CommandLocals locals) throws CommandException { FlagData flagData = getFlagParser().call(args, locals); String expression = expressionParser.call(args, locals); boolean rawCoords = rawCoordsFlag.get(flagData, false); boolean offset = offsetFlag.get(flagData, false); Deform deform = new Deform(expression); if (rawCoords) { deform.setMode(Mode.RAW_COORD); } else if (offset) { deform.setMode(Mode.OFFSET); Player player = (Player) locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(locals.get(Actor.class)); try { deform.setOffset(session.getPlacementPosition(player).toVector3()); } catch (IncompleteRegionException e) { throw new WrappedCommandException(e); } } else { deform.setMode(Mode.UNIT_CUBE); } return deform; }
throw (RuntimeException) e.getCause(); } else { throw new WrappedCommandException(e.getCause());