예제 #1
0
 public <V> void setFlag(ProtectedRegion region, Flag<V> flag, CommandSender sender, String value)
     throws InvalidFlagFormat {
   region.setFlag(flag, flag.parseInput(plugin, sender, value));
 }
예제 #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());
    }
  }