Ejemplo n.º 1
0
  void setUpExitRegion() throws Exception {
    DefaultDomain domain = new DefaultDomain();
    domain.addGroup(BUILDER_GROUP);

    ProtectedRegion region =
        new ProtectedCuboidRegion(
            EXIT_ID, new BlockVector(-1, 0, -1), new BlockVector(-10, 255, -10));

    region.setOwners(domain);
    manager.addRegion(region);

    entryRegion = region;
    // same as above
    entryRegion.setFlag(DefaultFlag.EXIT, StateFlag.State.DENY);
    entryRegion.setFlag(DefaultFlag.EXIT.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
  }
Ejemplo n.º 2
0
  void setUpEntryRegion() {
    DefaultDomain domain = new DefaultDomain();
    domain.addGroup(VIP_GROUP);

    ProtectedRegion region =
        new ProtectedCuboidRegion(ENTRY_ID, new BlockVector(1, 0, 1), new BlockVector(10, 255, 10));

    region.setMembers(domain);
    manager.addRegion(region);

    entryRegion = region;
    // this is the way it's supposed to work
    // whatever the group flag is set to is the group that the flag APPLIES to
    // in this case, non members (esskay) should be DENIED entry
    entryRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
    entryRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
  }
Ejemplo n.º 3
0
 public <V> void setFlag(ProtectedRegion region, Flag<V> flag, CommandSender sender, String value)
     throws InvalidFlagFormat {
   region.setFlag(flag, flag.parseInput(plugin, sender, value));
 }
Ejemplo n.º 4
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());
    }
  }