public Map<String, ProtectedRegion> getRegions() {
    HashMap<String, ProtectedRegion> ret = new HashMap<String, ProtectedRegion>();
    ret.putAll(this.cRegions);
    ret.putAll(this.pRegions);

    for (Map.Entry<String, ProtectedRegion> entry : ret.entrySet()) {
      ProtectedRegion region = entry.getValue();

      String parentId = region.getParentId();
      if (parentId != null) {
        try {
          region.setParent(ret.get(parentId));
        } catch (CircularInheritanceException ex) {
        }
      } else {
        try {
          region.setParent(null);
        } catch (CircularInheritanceException ex) {
        }
      }

      if (region.getOwners() == null) {
        region.setOwners(new DefaultDomain());
      } else if (region.getMembers() == null) {
        region.setMembers(new DefaultDomain());
      }
    }

    return ret;
  }
 /**
  * Copy attributes from another region.
  *
  * @param other the other region
  */
 public void copyFrom(ProtectedRegion other) {
   checkNotNull(other);
   setMembers(other.getMembers());
   setOwners(other.getOwners());
   setFlags(other.getFlags());
   setPriority(other.getPriority());
   try {
     setParent(other.getParent());
   } catch (CircularInheritanceException ignore) {
     // This should not be thrown
   }
 }
Beispiel #3
0
  public void allowUser(Player player, String[] args) {
    if (args.length != 3) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

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

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

    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;
    }

    if (region.isOwner(localPlayer)) {
      region.getMembers().addPlayer(args[1]);
      player.sendMessage(
          ChatColor.GREEN
              + "Allowed "
              + ChatColor.RED
              + args[1]
              + ChatColor.GREEN
              + " to region "
              + ChatColor.RED
              + args[2]
              + ChatColor.GREEN
              + ".");

      Player targetPlayer = Bukkit.getServer().getPlayerExact(args[1]);
      if (targetPlayer != null) {
        targetPlayer.sendMessage(
            ChatColor.GREEN
                + player.getName()
                + " has added you as a member in the "
                + ChatColor.RED
                + args[2]
                + ChatColor.GREEN
                + " region.");
      }

    } else {
      player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]);
    }
  }
  /**
   * Checks whether a player is a member of the region or any of its parents.
   *
   * @param player player to check
   * @return whether an member
   */
  public boolean isMemberOnly(LocalPlayer player) {
    if (members.contains(player)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getMembers().contains(player)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
  /**
   * Checks whether a player is a member OR OWNER of the region or any of its parents.
   *
   * @param playerName player name to check
   * @return whether an owner or member
   * @deprecated Names are deprecated
   */
  @Deprecated
  public boolean isMember(String playerName) {
    checkNotNull(playerName);

    if (isOwner(playerName)) {
      return true;
    }

    if (members.contains(playerName)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getMembers().contains(playerName)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
  @Override
  public void takeRegion(Player newOwner, String world, String region) {
    final ProtectedRegion protectedRegion =
        SimpleRegionMarket.wgManager.getProtectedRegion(Bukkit.getWorld(world), region);

    if (Utils.getEntryBoolean(this, world, region, "taken")) {
      final Player oldOwner = Bukkit.getPlayer(Utils.getEntryString(this, world, region, "owner"));
      final ArrayList<String> list = new ArrayList<String>();
      list.add(region);
      list.add(newOwner.getName());
      LangHandler.NormalOut(oldOwner, "PLAYER.REGION.JUST_TAKEN_BY", list);
      untakeRegion(world, region);
    } else {
      // Clear Members
      protectedRegion.setMembers(new DefaultDomain());
    }

    protectedRegion.getMembers().addPlayer(SimpleRegionMarket.wgManager.wrapPlayer(newOwner));

    checkTakeActions(protectedRegion, world);

    Utils.setEntry(this, world, region, "taken", true);
    Utils.setEntry(this, world, region, "owner", newOwner.getName());
    Utils.setEntry(
        this,
        world,
        region,
        "expiredate",
        System.currentTimeMillis() + Utils.getEntryLong(this, world, region, "renttime"));
    Utils.setEntry(this, world, region, "hidden", true);

    final ArrayList<String> list = new ArrayList<String>();
    list.add(region);
    LangHandler.NormalOut(newOwner, "PLAYER.REGION.RENT", list);

    tokenManager.updateSigns(this, world, region);
  }
Beispiel #7
0
  public void denyUser(Player player, String[] args) {
    if (args.length != 3) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

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

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

    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;
    }

    if (region.isOwner(localPlayer)) {
      region.getMembers().removePlayer(args[1]);
      player.sendMessage(
          ChatColor.GREEN
              + "Removed player "
              + ChatColor.RED
              + args[1]
              + ChatColor.GREEN
              + " from region "
              + ChatColor.RED
              + args[2]
              + ChatColor.GREEN
              + ".");
    } else {
      player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]);
    }
  }
  @Override
  protected void action() throws CommandException {
    ProtectedRegion region = null;
    if (args.length == 1
        || (args.length == 2
            && args[1].equalsIgnoreCase("sel"))) { // No regionname specified. Get highest priority
      if (all) { // Allowed to get all regions
        region = getHighestPriorityRegion();
      } else { // Only allowed to get their own regions
        region = getHighestOwnedPriorityRegion(true);
      }
    } else {
      validateRegionID(args[1]); // Check if valid region
      region = getRegion(args[1]); // Get the region by name
      if (!all) { // If not acces to all regions
        String playername = p.getName();
        if (!region.getMembers().contains(p.getUniqueId())
            && !region.getOwners().contains(p.getUniqueId())) { // Check if owner or member
          throw new IRGException("You are not the owner or member of the specified region.");
        }
      }
    }

    if (args[args.length - 1].equalsIgnoreCase("sel")) { // Select region
      if (p.hasPermission(Perm.select.toString())) {
        setPlayerSelection(region);
      }
    }

    RegionPrintoutBuilder builder = new RegionPrintoutBuilder(region, null); // Build the string
    try {
      // First line
      builder.append(ChatColor.GRAY);
      builder.append(
          "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
      builder.append(" Region Info ");
      builder.append(
          "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
      builder.append("\n");
      // Basic info
      builder.appendBasics();
      builder.appendFlags();
      builder.appendParents();

      // Users
      builder.append(ChatColor.BLUE + "Owners: ");
      builder.append(uuidSetToString(region.getOwners()));
      builder.append("\n");
      builder.append(ChatColor.BLUE + "Members: ");
      builder.append(uuidSetToString(region.getMembers()));
      builder.append("\n");

      // Bounds
      builder.appendBounds();

      // Send
      builder.send(p);
    } catch (Exception e) {
      Util.badMsg(p, "An error occurred, sorry!");
      Log.warn("Error occurred (IRG Info Command): " + e.getMessage());
    }
  }