@Override public Number call(CommandArgs args, CommandLocals locals) throws CommandException { try { String next = args.next(); try { return Double.parseDouble(next); } catch (NumberFormatException ignored) { throw new CommandException("The value for <" + name + "> should be a number. '" + next + "' is not a number."); } } catch (MissingArgumentException e) { throw new CommandException("Missing value for <" + name + "> (try a number)."); } }
@Override public void onFailure(@Nullable Throwable throwable) { try { exceptionConverter.convert(throwable); } catch (CommandException e) { String failure = this.failure != null ? this.failure : "An error occurred"; String message = e.getMessage() != null ? e.getMessage() : "An unknown error occurred. Please see the console!"; sender.printError(failure + ": " + message); } }
@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); }
public Actor wrapCommandSender(CommandSender sender) { if (sender instanceof Player) { return wrapPlayer((Player) sender); } try { return new BukkitCommandSender(getWorldEdit(), sender); } catch (CommandException e) { e.printStackTrace(); } return null; }
@ExceptionMatch public void convert(NumberFormatException e) throws CommandException { final Matcher matcher = numberFormat.matcher(e.getMessage()); if (matcher.matches()) { throw new CommandException("Number expected; string \"" + matcher.group(1) + "\" given."); } else { throw new CommandException("Number expected; string given."); } }
@Subscribe public void handleCommandSuggestion(CommandSuggestionEvent event) { try { CommandLocals locals = new CommandLocals(); locals.put(Actor.class, event.getActor()); locals.put("arguments", event.getArguments()); event.setSuggestions(dispatcher.getSuggestions(event.getArguments(), locals)); } catch (CommandException e) { event.getActor().printError(e.getMessage()); } }
public void fromString(String str) throws CommandException { Type type = Type.findByPattern(str); if (type != null) { this.type = type; } else { throw new CommandException("Acceptable types: projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all"); } }
log.log(Level.SEVERE, "An unexpected error while handling a WorldEdit command", t); } catch (CommandException e) { String message = e.getMessage(); if (message != null) { actor.printError(e.getMessage()); } else { actor.printError("An unknown error has occurred! Please see console.");
@Override public String call(CommandArgs args, CommandLocals locals) throws CommandException { try { return args.next(); } catch (MissingArgumentException e) { throw new CommandException("Missing value for <" + name + ">."); } }
/** * Called on player chat. * * @param event Relevant event details */ @EventHandler public void onChat(AsyncPlayerChatEvent event) { if (sessions.getSession(AdministrativeSession.class, event.getPlayer()).isMute()) { event.getPlayer().sendMessage(ChatColor.RED + "You are muted."); event.setCancelled(true); } else if (event.getMessage().startsWith("@") && config.twitterStyle) { final String message = event.getMessage(); int spaceIndex = message.indexOf(" "); if (spaceIndex > -1) { try { String name = message.substring(1, spaceIndex); if (name.length() <= 0) { return; } messagePlayer(event.getPlayer(), name, message.substring(spaceIndex + 1)); } catch (CommandException e) { event.getPlayer().sendMessage(ChatColor.RED + e.getMessage()); } event.setCancelled(true); } } }
@ExceptionMatch public void convert(FileSelectionAbortedException e) throws CommandException { throw new CommandException("File selection aborted."); }
@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; }
@ExceptionMatch public void convert(IncompleteRegionException e) throws CommandException { throw new CommandException("Make a region selection first."); }
/** * 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; }
@ExceptionMatch public void convert(EmptyClipboardException e) throws CommandException { throw new CommandException("Your clipboard is empty. Use //copy first."); }
@Override public T call(CommandArgs args, CommandLocals locals) throws CommandException { try { String classifier = args.next(); CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase()); if (executor != null) { return executor.call(args, locals); } else { throw new CommandException("'" + classifier + "' isn't a valid option for '" + name + "'. " + "Try one of: " + Joiner.on(", ").join(primaryAliases)); } } catch (MissingArgumentException e) { throw new CommandException("Missing value for <" + name + "> " + "(try one of " + Joiner.on(" | ").join(primaryAliases) + ")."); } }
@ExceptionMatch public void convert(MaxChangedBlocksException e) throws CommandException { throw new CommandException("Max blocks changed in an operation reached (" + e.getBlockLimit() + ")."); }
@ExceptionMatch public void convert(DisallowedItemException e) throws CommandException { throw new CommandException("Block '" + e.getID() + "' not allowed (see WorldEdit configuration)."); }
@ExceptionMatch public void convert(UnknownItemException e) throws CommandException { throw new CommandException("Block name '" + e.getID() + "' was not recognized."); }
@ExceptionMatch public void convert(ExpressionException e) throws CommandException { throw new CommandException(e.getMessage()); }