Ejemplo n.º 1
0
  /**
   * Set the curParent. This checks to make sure that it will not result in circular inheritance.
   *
   * @param parent the curParent to setFlag
   * @throws CircularInheritanceException
   */
  public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
    if (parent == null) {
      this.parent = null;
      return;
    }

    if (parent == this) {
      throw new CircularInheritanceException();
    }

    ProtectedRegion p = parent.getParent();
    while (p != null) {
      if (p == this) {
        throw new CircularInheritanceException();
      }
      p = p.getParent();
    }

    this.parent = parent;
  }
 /**
  * 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
   }
 }
Ejemplo n.º 3
0
  @Override
  public ApplicableRegionSet getApplicableRegions(Vector pt) {
    TreeSet<ProtectedRegion> appRegions = new TreeSet<ProtectedRegion>();

    for (ProtectedRegion region : regions.values()) {
      if (region.contains(pt)) {
        appRegions.add(region);

        ProtectedRegion parent = region.getParent();

        while (parent != null) {
          if (!appRegions.contains(parent)) {
            appRegions.add(parent);
          }

          parent = parent.getParent();
        }
      }
    }

    return new ApplicableRegionSet(appRegions, regions.get("__global__"));
  }
Ejemplo n.º 4
0
  /**
   * 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;
  }
Ejemplo n.º 5
0
  @Override
  public void removeRegion(String id) {
    ProtectedRegion region = regions.get(id.toLowerCase());
    regions.remove(id.toLowerCase());

    if (region != null) {
      List<String> removeRegions = new ArrayList<String>();
      for (ProtectedRegion curRegion : regions.values()) {
        if (curRegion.getParent() == region) {
          removeRegions.add(curRegion.getId().toLowerCase());
        }
      }

      for (String remId : removeRegions) {
        removeRegion(remId);
      }
    }
  }
  /**
   * Checks whether a player is an owner of region or any of its parents.
   *
   * @param player player to check
   * @return whether an owner
   */
  public boolean isOwner(LocalPlayer player) {
    checkNotNull(player);

    if (owners.contains(player)) {
      return true;
    }

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

      curParent = curParent.getParent();
    }

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

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

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

      curParent = curParent.getParent();
    }

    return false;
  }