Пример #1
0
  @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;
  }
Пример #2
0
  public void setFlags(Player sender, String[] args) {
    Player player = null;
    try {
      player = plugin.checkPlayer(sender);
    } catch (CommandException e1) {
      e1.printStackTrace();
      return;
    }

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    String value = null;

    if (args.length == 4) {
      value = args[3];
    } else if (args.length == 3) {
      //
    } else {
      player.sendMessage(ChatColor.RED + "Wrong usage! /pr help");
      return;
    }

    String id = "icp_" + player.getName() + "_" + args[1];
    String flagName = args[2];

    if (!(flagName.equals("use")
        || flagName.equals("chest-access")
        || flagName.equals("snow-fall")
        || flagName.equals("snow-melt")
        || flagName.equals("ice-form")
        || flagName.equals("ice-melt"))) {
      player.sendMessage(ChatColor.RED + "Unsupported flag! /pr help flags");
      return;
    }

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    Flag<?> foundFlag = null;

    for (Flag<?> flag : DefaultFlag.getFlags()) {
      if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", ""))) {
        foundFlag = flag;
        break;
      }
    }

    if (foundFlag == null) {
      StringBuilder list = new StringBuilder();

      for (Flag<?> flag : DefaultFlag.getFlags()) {
        if (list.length() > 0) {
          list.append(", ");
        }

        if (!region.isOwner(localPlayer)) {
          continue;
        }

        list.append(flag.getName());
      }

      player.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName);
      player.sendMessage(ChatColor.RED + "Available flags: " + list);
      return;
    }

    if (region.isOwner(localPlayer)) {

      if (value != null) {
        try {
          setFlag(region, foundFlag, sender, value);
        } catch (InvalidFlagFormat e) {
          player.sendMessage(ChatColor.RED + e.getMessage());
          return;
        }

        sender.sendMessage(
            ChatColor.YELLOW
                + "Region flag "
                + ChatColor.GREEN
                + foundFlag.getName()
                + ChatColor.YELLOW
                + " set.");
      } else {
        region.setFlag(foundFlag, null);

        sender.sendMessage(
            ChatColor.YELLOW
                + "Region flag "
                + ChatColor.GREEN
                + foundFlag.getName()
                + ChatColor.YELLOW
                + " cleared.");
      }

    } else {
      sender.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own this region!");
      return;
    }

    try {
      mgr.save();
    } catch (IOException e) {
      player.sendMessage(ChatColor.RED + "Failed to write regions file: " + e.getMessage());
    }
  }