Exemple #1
0
  public boolean handleCommand(Player player, String[] split) {

    try {

      split[0] = split[0].substring(1);

      // Quick script shortcut
      if (split[0].matches("^[^/].*\\.js$")) {
        String[] newSplit = new String[split.length + 1];
        System.arraycopy(split, 0, newSplit, 1, split.length);
        newSplit[0] = "cs";
        newSplit[1] = newSplit[1];
        split = newSplit;
      }

      // No command found!
      if (!commandMap.hasCommand(split[0])) {
        return false;
      }

      try {
        commandMap.execute(split, player, this, player);
      } catch (CommandPermissionsException e) {
        player.sendMessage("You don't have permission to do this.");
      } catch (MissingNestedCommandException e) {
        player.sendMessage(e.getUsage());
      } catch (CommandUsageException e) {
        player.sendMessage(e.getMessage());
        player.sendMessage(e.getUsage());
      } catch (WrappedCommandException e) {
        throw e.getCause();
      } catch (UnhandledCommandException e) {
        return false;
      } finally {

      }

    } catch (Throwable excp) {

      player.sendMessage("Please report this error:");
      player.sendMessage(excp.getMessage());
    }

    return true;
  }
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    try {
      this.commands.execute(cmd.getName(), args, sender, sender);
    } catch (CommandPermissionsException e) {
      sender.sendMessage(ChatColor.RED + lang.get("exceptions.noPermission"));
    } 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 + lang.get("exceptions.numExpected"));
      } else {
        sender.sendMessage(ChatColor.RED + lang.get("exceptions.errorOccurred"));
        e.printStackTrace();
      }
    } catch (CommandException e) {
      sender.sendMessage(ChatColor.RED + e.getMessage());
    }

    return true;
  }