2011-02-24 11:19:35 +01:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldGuard
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldguard.protection.regions;
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.BlockVector;
|
2011-10-18 22:05:19 +02:00
|
|
|
import com.sk89q.worldedit.BlockVector2D;
|
2011-02-24 11:19:35 +01:00
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
import com.sk89q.worldguard.LocalPlayer;
|
|
|
|
import com.sk89q.worldguard.domains.DefaultDomain;
|
|
|
|
import com.sk89q.worldguard.protection.UnsupportedIntersectionException;
|
2011-03-27 00:59:06 +01:00
|
|
|
import com.sk89q.worldguard.protection.flags.Flag;
|
2011-02-24 11:19:35 +01:00
|
|
|
|
2012-11-03 05:19:20 +01:00
|
|
|
import java.awt.geom.Line2D;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* Represents a region of any shape and size that can be protected.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2011-02-24 11:19:35 +01:00
|
|
|
* @author sk89q
|
|
|
|
*/
|
|
|
|
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-10-18 22:05:19 +02:00
|
|
|
protected BlockVector min;
|
|
|
|
protected BlockVector max;
|
|
|
|
|
2011-04-02 11:03:32 +02:00
|
|
|
private static final Pattern idPattern = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* Holds the region's ID.
|
|
|
|
*/
|
|
|
|
private String id;
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* Priority.
|
|
|
|
*/
|
|
|
|
private int priority = 0;
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2011-02-28 17:19:51 +01:00
|
|
|
* Holds the curParent.
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
2011-04-02 23:11:12 +02:00
|
|
|
private ProtectedRegion parent;
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* List of owners.
|
|
|
|
*/
|
|
|
|
private DefaultDomain owners = new DefaultDomain();
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* List of members.
|
|
|
|
*/
|
|
|
|
private DefaultDomain members = new DefaultDomain();
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2011-03-27 00:59:06 +01:00
|
|
|
* List of flags.
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
2011-03-27 00:59:06 +01:00
|
|
|
private Map<Flag<?>, Object> flags = new HashMap<Flag<?>, Object>();
|
2011-02-24 11:19:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a new instance of this region.
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param id The id (name) of this region.
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public ProtectedRegion(String id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2011-10-18 22:05:19 +02:00
|
|
|
/**
|
|
|
|
* Sets the minimum and maximum points of the bounding box for a region
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param points The points to set. Must have at least one element.
|
2011-10-18 22:05:19 +02:00
|
|
|
*/
|
|
|
|
protected void setMinMaxPoints(List<Vector> points) {
|
|
|
|
int minX = points.get(0).getBlockX();
|
|
|
|
int minY = points.get(0).getBlockY();
|
|
|
|
int minZ = points.get(0).getBlockZ();
|
|
|
|
int maxX = minX;
|
|
|
|
int maxY = minY;
|
|
|
|
int maxZ = minZ;
|
|
|
|
|
|
|
|
for (Vector v : points) {
|
|
|
|
int x = v.getBlockX();
|
|
|
|
int y = v.getBlockY();
|
|
|
|
int z = v.getBlockZ();
|
|
|
|
|
|
|
|
if (x < minX) minX = x;
|
|
|
|
if (y < minY) minY = y;
|
|
|
|
if (z < minZ) minZ = z;
|
|
|
|
|
|
|
|
if (x > maxX) maxX = x;
|
|
|
|
if (y > maxY) maxY = y;
|
|
|
|
if (z > maxZ) maxZ = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
min = new BlockVector(minX, minY, minZ);
|
|
|
|
max = new BlockVector(maxX, maxY, maxZ);
|
|
|
|
}
|
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2012-02-21 00:14:55 +01:00
|
|
|
* Gets the id of this region
|
|
|
|
*
|
2011-02-24 11:19:35 +01:00
|
|
|
* @return the id
|
|
|
|
*/
|
|
|
|
public String getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the lower point of the cuboid.
|
|
|
|
*
|
|
|
|
* @return min point
|
|
|
|
*/
|
2011-10-18 22:05:19 +02:00
|
|
|
public BlockVector getMinimumPoint() {
|
|
|
|
return min;
|
|
|
|
}
|
2011-02-24 11:19:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the upper point of the cuboid.
|
|
|
|
*
|
|
|
|
* @return max point
|
|
|
|
*/
|
2011-10-18 22:05:19 +02:00
|
|
|
public BlockVector getMaximumPoint() {
|
|
|
|
return max;
|
|
|
|
}
|
2011-02-24 11:19:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the priority
|
|
|
|
*/
|
|
|
|
public int getPriority() {
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-25 20:58:48 +01:00
|
|
|
* @param priority the priority to setFlag
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public void setPriority(int priority) {
|
|
|
|
this.priority = priority;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2011-02-28 17:19:51 +01:00
|
|
|
* @return the curParent
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public ProtectedRegion getParent() {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-28 17:19:51 +01:00
|
|
|
* Set the curParent. This checks to make sure that it will not result
|
2011-02-24 11:19:35 +01:00
|
|
|
* in circular inheritance.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2011-03-08 19:01:03 +01:00
|
|
|
* @param parent the curParent to setFlag
|
2012-02-21 00:14:55 +01:00
|
|
|
* @throws CircularInheritanceException when circular inheritance is detected
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
|
|
|
|
if (parent == null) {
|
|
|
|
this.parent = null;
|
|
|
|
return;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
if (parent == this) {
|
|
|
|
throw new CircularInheritanceException();
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
ProtectedRegion p = parent.getParent();
|
|
|
|
while (p != null) {
|
|
|
|
if (p == this) {
|
|
|
|
throw new CircularInheritanceException();
|
|
|
|
}
|
|
|
|
p = p.getParent();
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
|
2011-02-28 17:19:51 +01:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* @return the owners
|
|
|
|
*/
|
|
|
|
public DefaultDomain getOwners() {
|
|
|
|
|
|
|
|
return owners;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-25 20:58:48 +01:00
|
|
|
* @param owners the owners to setFlag
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public void setOwners(DefaultDomain owners) {
|
|
|
|
this.owners = owners;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the members
|
|
|
|
*/
|
|
|
|
public DefaultDomain getMembers() {
|
|
|
|
return members;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-08 19:01:03 +01:00
|
|
|
* @param members the members to setFlag
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public void setMembers(DefaultDomain members) {
|
|
|
|
this.members = members;
|
|
|
|
}
|
2011-06-27 19:11:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether a region has members or owners.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2011-06-27 19:11:23 +02:00
|
|
|
* @return whether there are members or owners
|
|
|
|
*/
|
|
|
|
public boolean hasMembersOrOwners() {
|
|
|
|
return owners.size() > 0 || members.size() > 0;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* Checks whether a player is an owner of region or any of its parents.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2011-06-27 19:11:23 +02:00
|
|
|
* @param player player to check
|
|
|
|
* @return whether an owner
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public boolean isOwner(LocalPlayer player) {
|
|
|
|
if (owners.contains(player)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-28 17:19:51 +01:00
|
|
|
ProtectedRegion curParent = getParent();
|
|
|
|
while (curParent != null) {
|
|
|
|
if (curParent.getOwners().contains(player)) {
|
2011-02-24 11:19:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-28 17:19:51 +01:00
|
|
|
curParent = curParent.getParent();
|
2011-02-24 11:19:35 +01:00
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
return false;
|
|
|
|
}
|
2011-02-27 16:24:07 +01:00
|
|
|
|
2012-03-23 14:44:58 +01:00
|
|
|
/**
|
|
|
|
* Checks whether a player is an owner of region or any of its parents.
|
|
|
|
*
|
|
|
|
* @param playerName player name to check
|
|
|
|
* @return whether an owner
|
|
|
|
*/
|
|
|
|
public boolean isOwner(String 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;
|
|
|
|
}
|
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2011-06-27 19:11:23 +02:00
|
|
|
* Checks whether a player is a member OR OWNER of the region
|
|
|
|
* or any of its parents.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2011-06-27 19:11:23 +02:00
|
|
|
* @param player player to check
|
|
|
|
* @return whether an owner or member
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public boolean isMember(LocalPlayer player) {
|
2012-03-23 14:44:58 +01:00
|
|
|
if (isOwner(player)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public boolean isMember(String playerName) {
|
|
|
|
if (isOwner(playerName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (members.contains(playerName)) {
|
2011-02-24 11:19:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-28 17:19:51 +01:00
|
|
|
ProtectedRegion curParent = getParent();
|
|
|
|
while (curParent != null) {
|
2012-03-23 14:44:58 +01:00
|
|
|
if (curParent.getMembers().contains(playerName)) {
|
2011-02-24 11:19:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-28 17:19:51 +01:00
|
|
|
curParent = curParent.getParent();
|
2011-02-24 11:19:35 +01:00
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
return false;
|
|
|
|
}
|
2011-06-27 19:11:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2011-03-27 00:59:06 +01:00
|
|
|
* Get a flag's value.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param <T> The flag type
|
|
|
|
* @param <V> The type of the flag's value
|
|
|
|
* @param flag The flag to check
|
2011-03-27 04:33:29 +02:00
|
|
|
* @return value or null if isn't defined
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
2011-03-27 00:59:06 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public <T extends Flag<V>, V> V getFlag(T flag) {
|
|
|
|
Object obj = flags.get(flag);
|
|
|
|
V val;
|
|
|
|
if (obj != null) {
|
|
|
|
val = (V) obj;
|
|
|
|
} else {
|
2011-03-27 04:33:29 +02:00
|
|
|
return null;
|
2011-02-28 17:19:51 +01:00
|
|
|
}
|
2011-03-27 00:59:06 +01:00
|
|
|
return val;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-03-27 00:59:06 +01:00
|
|
|
/**
|
|
|
|
* Set a flag's value.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param <T> The flag type
|
|
|
|
* @param <V> The type of the flag's value
|
|
|
|
* @param flag The flag to check
|
|
|
|
* @param val The value to set
|
2011-03-27 00:59:06 +01:00
|
|
|
*/
|
|
|
|
public <T extends Flag<V>, V> void setFlag(T flag, V val) {
|
2011-04-01 22:39:29 +02:00
|
|
|
if (val == null) {
|
|
|
|
flags.remove(flag);
|
|
|
|
} else {
|
|
|
|
flags.put(flag, val);
|
|
|
|
}
|
2011-02-24 11:19:35 +01:00
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-04-02 07:11:57 +02:00
|
|
|
/**
|
|
|
|
* Get the map of flags.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @return The map of flags currently used for this region
|
2011-04-02 07:11:57 +02:00
|
|
|
*/
|
|
|
|
public Map<Flag<?>, Object> getFlags() {
|
|
|
|
return flags;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-04-02 09:33:07 +02:00
|
|
|
/**
|
|
|
|
* Get the map of flags.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param flags The flags to set
|
2011-04-02 09:33:07 +02:00
|
|
|
*/
|
|
|
|
public void setFlags(Map<Flag<?>, Object> flags) {
|
|
|
|
this.flags = flags;
|
|
|
|
}
|
2011-02-25 01:36:47 +01:00
|
|
|
|
2011-10-18 22:05:19 +02:00
|
|
|
/**
|
|
|
|
* Gets the 2D points for this region
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @return The points for this region as (x, z) coordinates
|
2011-10-18 22:05:19 +02:00
|
|
|
*/
|
|
|
|
public abstract List<BlockVector2D> getPoints();
|
|
|
|
|
2011-02-25 01:36:47 +01:00
|
|
|
/**
|
2011-03-30 21:01:11 +02:00
|
|
|
* Get the number of blocks in this region
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @return the volume of this region in blocks
|
2011-02-25 01:36:47 +01:00
|
|
|
*/
|
2011-03-30 21:01:11 +02:00
|
|
|
public abstract int volume();
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* Check to see if a point is inside this region.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param pt The point to check
|
|
|
|
* @return Whether {@code pt} is in this region
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public abstract boolean contains(Vector pt);
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-10-18 22:05:19 +02:00
|
|
|
/**
|
|
|
|
* Check to see if a point is inside this region.
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param pt The point to check
|
|
|
|
* @return Whether {@code pt} is in this region
|
2011-10-18 22:05:19 +02:00
|
|
|
*/
|
|
|
|
public boolean contains(BlockVector2D pt) {
|
|
|
|
return contains(new Vector(pt.getBlockX(), min.getBlockY(), pt.getBlockZ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if a point is inside this region.
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param x The x coordinate to check
|
|
|
|
* @param y The y coordinate to check
|
|
|
|
* @param z The z coordinate to check
|
|
|
|
* @return Whether this region contains the points at the given coordinate
|
2011-10-18 22:05:19 +02:00
|
|
|
*/
|
|
|
|
public boolean contains(int x, int y, int z) {
|
|
|
|
return contains(new Vector(x, y, z));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if any of the 2D points are inside this region.
|
|
|
|
*
|
|
|
|
* @param pts
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean containsAny(List<BlockVector2D> pts) {
|
|
|
|
for (BlockVector2D pt : pts) {
|
|
|
|
if (contains(pt)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2012-01-09 14:47:59 +01:00
|
|
|
* Compares to another region.<br>
|
|
|
|
*<br>
|
|
|
|
* Orders primarily by the priority, descending<br>
|
|
|
|
* Orders secondarily by the id, ascending
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param other The region to compare to
|
2011-02-24 11:19:35 +01:00
|
|
|
*/
|
|
|
|
public int compareTo(ProtectedRegion other) {
|
2012-01-09 14:47:59 +01:00
|
|
|
if (priority > other.priority) {
|
2011-02-24 11:19:35 +01:00
|
|
|
return -1;
|
2012-01-09 14:47:59 +01:00
|
|
|
} else if (priority < other.priority) {
|
2011-02-24 11:19:35 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2012-01-09 14:47:59 +01:00
|
|
|
|
|
|
|
return id.compareTo(other.id);
|
2011-02-24 11:19:35 +01:00
|
|
|
}
|
2011-03-27 04:33:29 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
|
|
|
* Return the type of region as a user-friendly, lowercase name.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2011-02-24 11:19:35 +01:00
|
|
|
* @return type of region
|
|
|
|
*/
|
|
|
|
public abstract String getTypeName();
|
2011-02-27 18:16:09 +01:00
|
|
|
|
2011-05-04 09:52:17 +02:00
|
|
|
/**
|
|
|
|
* Get a list of intersecting regions.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param regions The list of regions to source from
|
|
|
|
* @return The elements of {@code regions} that intersect with this region
|
|
|
|
* @throws UnsupportedIntersectionException if an invalid intersection is detected
|
2011-05-04 09:52:17 +02:00
|
|
|
*/
|
2011-03-27 04:33:29 +02:00
|
|
|
public abstract List<ProtectedRegion> getIntersectingRegions(
|
|
|
|
List<ProtectedRegion> regions)
|
|
|
|
throws UnsupportedIntersectionException;
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-10-18 22:05:19 +02:00
|
|
|
/**
|
|
|
|
* Checks if the bounding box of a region intersects with with the bounding
|
|
|
|
* box of this region
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param region The region to check
|
|
|
|
* @return whether the given region intersects
|
2011-10-18 22:05:19 +02:00
|
|
|
*/
|
|
|
|
protected boolean intersectsBoundingBox(ProtectedRegion region) {
|
|
|
|
BlockVector rMaxPoint = region.getMaximumPoint();
|
|
|
|
BlockVector min = getMinimumPoint();
|
|
|
|
|
|
|
|
if (rMaxPoint.getBlockX() < min.getBlockX()) return false;
|
|
|
|
if (rMaxPoint.getBlockY() < min.getBlockY()) return false;
|
|
|
|
if (rMaxPoint.getBlockZ() < min.getBlockZ()) return false;
|
|
|
|
|
|
|
|
BlockVector rMinPoint = region.getMinimumPoint();
|
|
|
|
BlockVector max = getMaximumPoint();
|
|
|
|
|
|
|
|
if (rMinPoint.getBlockX() > max.getBlockX()) return false;
|
|
|
|
if (rMinPoint.getBlockY() > max.getBlockY()) return false;
|
|
|
|
if (rMinPoint.getBlockZ() > max.getBlockZ()) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-19 00:52:25 +02:00
|
|
|
/**
|
|
|
|
* Compares all edges of two regions to see if any of them intersect
|
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param region The region to check
|
|
|
|
* @return whether any edges of a region intersect
|
2011-10-19 00:52:25 +02:00
|
|
|
*/
|
|
|
|
protected boolean intersectsEdges(ProtectedRegion region) {
|
|
|
|
List<BlockVector2D> pts1 = getPoints();
|
|
|
|
List<BlockVector2D> pts2 = region.getPoints();
|
|
|
|
BlockVector2D lastPt1 = pts1.get(pts1.size() - 1);
|
|
|
|
BlockVector2D lastPt2 = pts2.get(pts2.size() - 1);
|
2012-11-03 05:19:20 +01:00
|
|
|
for (BlockVector2D aPts1 : pts1) {
|
|
|
|
for (BlockVector2D aPts2 : pts2) {
|
2011-10-19 00:52:25 +02:00
|
|
|
|
|
|
|
Line2D line1 = new Line2D.Double(
|
|
|
|
lastPt1.getBlockX(),
|
|
|
|
lastPt1.getBlockZ(),
|
2012-11-03 05:19:20 +01:00
|
|
|
aPts1.getBlockX(),
|
|
|
|
aPts1.getBlockZ());
|
2011-10-19 00:52:25 +02:00
|
|
|
|
|
|
|
if (line1.intersectsLine(
|
2012-11-03 05:19:20 +01:00
|
|
|
lastPt2.getBlockX(),
|
|
|
|
lastPt2.getBlockZ(),
|
|
|
|
aPts2.getBlockX(),
|
|
|
|
aPts2.getBlockZ())) {
|
2011-10-19 00:52:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-03 05:19:20 +01:00
|
|
|
lastPt2 = aPts2;
|
2011-10-19 00:52:25 +02:00
|
|
|
}
|
2012-11-03 05:19:20 +01:00
|
|
|
lastPt1 = aPts1;
|
2011-10-19 00:52:25 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-02 11:03:32 +02:00
|
|
|
/**
|
|
|
|
* Checks to see if the given ID is accurate.
|
2011-09-27 12:13:19 +02:00
|
|
|
*
|
2012-02-21 00:14:55 +01:00
|
|
|
* @param id The id to check
|
|
|
|
* @see #idPattern
|
|
|
|
* @return Whether the region id given is valid
|
2011-04-02 11:03:32 +02:00
|
|
|
*/
|
|
|
|
public static boolean isValidId(String id) {
|
|
|
|
return idPattern.matcher(id).matches();
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-05-27 06:55:23 +02:00
|
|
|
@Override
|
|
|
|
public int hashCode(){
|
|
|
|
return id.hashCode();
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-05-27 06:55:23 +02:00
|
|
|
/**
|
|
|
|
* Returns whether this region has the same ID as another region.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (!(obj instanceof ProtectedRegion)) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-05-27 06:55:23 +02:00
|
|
|
ProtectedRegion other = (ProtectedRegion) obj;
|
|
|
|
return other.getId().equals(getId());
|
|
|
|
}
|
2011-09-27 12:13:19 +02:00
|
|
|
|
2011-02-24 11:19:35 +01:00
|
|
|
/**
|
2011-02-28 17:19:51 +01:00
|
|
|
* Thrown when setting a curParent would create a circular inheritance
|
2011-02-24 11:19:35 +01:00
|
|
|
* situation.
|
|
|
|
*/
|
|
|
|
public static class CircularInheritanceException extends Exception {
|
|
|
|
private static final long serialVersionUID = 7479613488496776022L;
|
|
|
|
}
|
|
|
|
}
|