mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
getAreaFlag() functions now won't throw exceptions, updated /region info, fixed a typo in /region flag, parent regions are no longer required to overlap their children
This commit is contained in:
parent
46e0607a26
commit
3f5d52f901
@ -38,7 +38,6 @@
|
||||
*/
|
||||
public class CommandRegionFlag extends WgRegionCommand {
|
||||
|
||||
// to-do only allow owners to change flags
|
||||
public boolean handle(CommandSender sender, String senderName, String command, String[] args, WorldGuardConfiguration cfg, WorldGuardWorldConfiguration wcfg) throws CommandHandlingException {
|
||||
|
||||
CommandHandler.checkArgs(args, 3, 4, "/region flag <regionid> <name> (<subname>) <value>");
|
||||
@ -153,7 +152,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
if (valueStr.equals("set")) {
|
||||
|
||||
if (region.contains(BukkitUtil.toVector(l))) {
|
||||
region.getFlags().setLocationFlag("spawn", l);
|
||||
region.getFlags().setLocationFlag(nfo.flagName, l);
|
||||
validValue = true;
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " set to current location");
|
||||
|
||||
@ -163,7 +162,7 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
}
|
||||
|
||||
} else if (valueStr.equals("delete")) {
|
||||
region.getFlags().setLocationFlag("spawn", null);
|
||||
region.getFlags().setLocationFlag(nfo.flagName, null);
|
||||
validValue = true;
|
||||
sender.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + nameStr + " removed.");
|
||||
}
|
||||
|
@ -27,6 +27,7 @@
|
||||
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -92,6 +93,14 @@ public boolean handle(CommandSender sender, String senderName, String command, S
|
||||
} else {
|
||||
s.append(fullName + ": -");
|
||||
}
|
||||
} else if ((nfo.subName != null && nfo.subName.equals("*"))) {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : flags.getFlagData(nfo.flagName).entrySet()) {
|
||||
if (Boolean.valueOf(entry.getValue())) {
|
||||
ret.append(entry.getKey() + " ");
|
||||
}
|
||||
}
|
||||
s.append(fullName + ": " + ret);
|
||||
} else {
|
||||
value = flags.getFlag(nfo.flagName, nfo.flagSubName);
|
||||
if (value != null) {
|
||||
|
@ -42,7 +42,7 @@ public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE, L
|
||||
flagList = new ArrayList<FlagInfo>();
|
||||
flagList.add(new FlagInfo("msg", "g", FlagValueType.STRING, "msg", "g"));
|
||||
flagList.add(new FlagInfo("msg", "f", FlagValueType.STRING, "msg", "f"));
|
||||
flagList.add(new FlagInfo("cspawn", "*", FlagValueType.STRING, "creaturespawn", "*"));
|
||||
flagList.add(new FlagInfo("denyspawn", "*", FlagValueType.STRING, "creaturespawn", "*"));
|
||||
flagList.add(new FlagInfo("heal", "delay", FlagValueType.INT, "heal", "delay"));
|
||||
flagList.add(new FlagInfo("heal", "amount", FlagValueType.INT, "heal", "amount"));
|
||||
flagList.add(new FlagInfo("passthrough", null, FlagValueType.STATE, "states", "passthrough"));
|
||||
|
@ -15,8 +15,7 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
@ -29,18 +28,21 @@
|
||||
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
* Represents a set of regions and their rules as applied to one point.
|
||||
* Represents a setFlag of regions and their rules as applied to one point.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ApplicableRegionSet {
|
||||
|
||||
private GlobalFlags global;
|
||||
private Vector pt;
|
||||
private List<ProtectedRegion> applicable;
|
||||
private Map<String, ProtectedRegion> applicable;
|
||||
|
||||
/**
|
||||
* Construct the object.
|
||||
@ -49,7 +51,7 @@ public class ApplicableRegionSet {
|
||||
* @param regions
|
||||
* @param global
|
||||
*/
|
||||
public ApplicableRegionSet(Vector pt, List<ProtectedRegion> applicable,
|
||||
public ApplicableRegionSet(Vector pt, Map<String, ProtectedRegion> applicable,
|
||||
GlobalFlags global) {
|
||||
this.pt = pt;
|
||||
this.applicable = applicable;
|
||||
@ -80,20 +82,24 @@ public boolean allowsFlag(String flag) {
|
||||
} else if (flag.equals(AreaFlags.FLAG_PVP)) {
|
||||
def = global.canPvP;
|
||||
} else if (flag.equals(AreaFlags.FLAG_LIGHTER)) {
|
||||
def = global.canLighter;
|
||||
} else if (flag.equals(AreaFlags.FLAG_TNT)) {
|
||||
def = global.canTnt;
|
||||
} else if (flag.equals(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||
def = global.allowCreeper;
|
||||
} else if (flag.equals(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||
def = global.allowMobDamage;
|
||||
} else if (flag.equals(AreaFlags.FLAG_WATER_FLOW)) {
|
||||
def = global.allowWaterflow;
|
||||
}
|
||||
def = global.canLighter;
|
||||
} else if (flag.equals(AreaFlags.FLAG_TNT)) {
|
||||
def = global.canTnt;
|
||||
} else if (flag.equals(AreaFlags.FLAG_CREEPER_EXPLOSION)) {
|
||||
def = global.allowCreeper;
|
||||
} else if (flag.equals(AreaFlags.FLAG_MOB_DAMAGE)) {
|
||||
def = global.allowMobDamage;
|
||||
} else if (flag.equals(AreaFlags.FLAG_WATER_FLOW)) {
|
||||
def = global.allowWaterflow;
|
||||
}
|
||||
|
||||
return isFlagAllowed(flag, def, null);
|
||||
}
|
||||
|
||||
private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
||||
return getStateAreaFlag("states", flag, def, player) == State.ALLOW;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a flag is permitted.
|
||||
*
|
||||
@ -101,92 +107,89 @@ public boolean allowsFlag(String flag) {
|
||||
* @param player null to not check owners and members
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
||||
boolean found = false;
|
||||
boolean allowed = false; // Used for ALLOW override
|
||||
if (player == null) {
|
||||
allowed = def;
|
||||
}
|
||||
int lastPriority = 0;
|
||||
boolean found = false;
|
||||
boolean allowed = false; // Used for ALLOW override
|
||||
if (player == null) {
|
||||
allowed = def;
|
||||
}
|
||||
int lastPriority = 0;
|
||||
|
||||
// The algorithm is as follows:
|
||||
// While iterating through the list of regions, if an entry disallows
|
||||
// the flag, then put it into the needsClear set. If an entry allows
|
||||
// the flag and it has a parent, then its parent is put into hasCleared.
|
||||
// In the situation that the child is reached before the parent, upon
|
||||
// the parent being reached, even if the parent disallows, because the
|
||||
// parent will be in hasCleared, permission will be allowed. In the
|
||||
// other case, where the parent is reached first, if it does not allow
|
||||
// permissions, it will be placed into needsClear. If a child of
|
||||
// the parent is reached later, the parent will be removed from
|
||||
// needsClear. At the end, if needsClear is not empty, that means that
|
||||
// permission should not be given. If a parent has multiple children
|
||||
// and one child does not allow permissions, then it will be placed into
|
||||
// needsClear just like as if was a parent.
|
||||
// The algorithm is as follows:
|
||||
// While iterating through the list of regions, if an entry disallows
|
||||
// the flag, then put it into the needsClear setFlag. If an entry allows
|
||||
// the flag and it has a parent, then its parent is put into hasCleared.
|
||||
// In the situation that the child is reached before the parent, upon
|
||||
// the parent being reached, even if the parent disallows, because the
|
||||
// parent will be in hasCleared, permission will be allowed. In the
|
||||
// other case, where the parent is reached first, if it does not allow
|
||||
// permissions, it will be placed into needsClear. If a child of
|
||||
// the parent is reached later, the parent will be removed from
|
||||
// needsClear. At the end, if needsClear is not empty, that means that
|
||||
// permission should not be given. If a parent has multiple children
|
||||
// and one child does not allow permissions, then it will be placed into
|
||||
// needsClear just like as if was a parent.
|
||||
|
||||
Set<ProtectedRegion> needsClear = new HashSet<ProtectedRegion>();
|
||||
Set<ProtectedRegion> hasCleared = new HashSet<ProtectedRegion>();
|
||||
Set<ProtectedRegion> needsClear = new HashSet<ProtectedRegion>();
|
||||
Set<ProtectedRegion> hasCleared = new HashSet<ProtectedRegion>();
|
||||
|
||||
Iterator<ProtectedRegion> iter = applicable.iterator();
|
||||
Iterator<Entry<String, ProtectedRegion>> iter = applicable.entrySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ProtectedRegion region = iter.next();
|
||||
while (iter.hasNext()) {
|
||||
ProtectedRegion region = iter.next().getValue();
|
||||
|
||||
// Ignore non-build regions
|
||||
if (player != null && region.getFlags().get(AreaFlags.FLAG_PASSTHROUGH) == State.ALLOW) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* No longer required.
|
||||
* A RegionManager now only supplies regions containing pt.
|
||||
*
|
||||
// Forget about regions that are not covered
|
||||
if (!region.contains(pt)) {
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
|
||||
// Allow DENY to override everything
|
||||
if (region.getFlags().get(flag) == State.DENY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Forget about regions that allow it, although make sure the
|
||||
// default state is now to allow
|
||||
if (region.getFlags().get(flag) == State.ALLOW) {
|
||||
allowed = true;
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore lower priority regions
|
||||
if (found && region.getPriority() < lastPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
if (hasCleared.contains(region)) {
|
||||
// Already cleared, so do nothing
|
||||
} else {
|
||||
if (!region.isMember(player)) {
|
||||
needsClear.add(region);
|
||||
} else {
|
||||
// Need to clear all parents
|
||||
clearParents(needsClear, hasCleared, region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
found = true;
|
||||
lastPriority = region.getPriority();
|
||||
}
|
||||
|
||||
return (found == false ? def : allowed)
|
||||
|| (player != null && needsClear.size() == 0);
|
||||
// Ignore non-build regions
|
||||
if (player != null && region.getFlags().getStateFlag(AreaFlags.FLAG_PASSTHROUGH) == State.ALLOW) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
// Forget about regions that are not covered
|
||||
if (!region.contains(pt)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Allow DENY to override everything
|
||||
if (region.getFlags().getStateFlag(flag) == State.DENY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Forget about regions that allow it, although make sure the
|
||||
// default state is now to allow
|
||||
if (region.getFlags().getStateFlag(flag) == State.ALLOW) {
|
||||
allowed = true;
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore lower priority regions
|
||||
if (found && region.getPriority() < lastPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
if (hasCleared.contains(region)) {
|
||||
// Already cleared, so do nothing
|
||||
} else {
|
||||
if (!region.isMember(player)) {
|
||||
needsClear.add(region);
|
||||
} else {
|
||||
// Need to clear all parents
|
||||
clearParents(needsClear, hasCleared, region);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
found = true;
|
||||
lastPriority = region.getPriority();
|
||||
}
|
||||
|
||||
return (found == false ? def : allowed)
|
||||
|| (player != null && needsClear.size() == 0);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Get an area flag
|
||||
*
|
||||
* @param name flag name
|
||||
@ -198,8 +201,7 @@ private boolean isFlagAllowed(String flag, boolean def, LocalPlayer player) {
|
||||
public String getAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
|
||||
ProtectedRegion childRegion = getChildRegion();
|
||||
if(childRegion == null)
|
||||
{
|
||||
if (childRegion == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -207,26 +209,22 @@ public String getAreaFlag(String name, String subname, Boolean inherit, LocalPla
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!inherit)
|
||||
{
|
||||
if (!inherit) {
|
||||
return childRegion.getFlags().getFlag(name, subname);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
String value;
|
||||
do
|
||||
{
|
||||
do {
|
||||
value = childRegion.getFlags().getFlag(name, subname);
|
||||
childRegion = childRegion.getParent();
|
||||
|
||||
} while(value == null && childRegion != null);
|
||||
} while (value == null && childRegion != null);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the region with the hightest priority that is not a parent.
|
||||
*
|
||||
*/
|
||||
@ -234,42 +232,35 @@ public ProtectedRegion getChildRegion() {
|
||||
|
||||
int appSize = applicable.size();
|
||||
|
||||
if(appSize < 1)
|
||||
{
|
||||
if (appSize < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
else if(appSize < 2)
|
||||
{
|
||||
return applicable.get(0);
|
||||
} else if (appSize < 2) {
|
||||
for (Entry<String, ProtectedRegion> entry : applicable.entrySet()) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
List<String> parents = new ArrayList<String>();
|
||||
Iterator<ProtectedRegion> iter = applicable.iterator();
|
||||
Iterator<Entry<String, ProtectedRegion>> iter = applicable.entrySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ProtectedRegion region = iter.next();
|
||||
ProtectedRegion region = iter.next().getValue();
|
||||
ProtectedRegion parent = region.getParent();
|
||||
|
||||
if(parent == null)
|
||||
{
|
||||
parents.add(region.getId());
|
||||
}
|
||||
else
|
||||
{
|
||||
parents.add(parent.getId());
|
||||
if (parent == null) {
|
||||
parents.add(region.getId());
|
||||
} else {
|
||||
parents.add(parent.getId());
|
||||
}
|
||||
}
|
||||
|
||||
ProtectedRegion childRegion = null;
|
||||
iter = applicable.iterator();
|
||||
iter = applicable.entrySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
ProtectedRegion region = iter.next();
|
||||
if(!parents.contains(region.getId()))
|
||||
{
|
||||
if(childRegion == null || childRegion.getPriority() < region.getPriority())
|
||||
{
|
||||
ProtectedRegion region = iter.next().getValue();
|
||||
if (!parents.contains(region.getId())) {
|
||||
if (childRegion == null || childRegion.getPriority() < region.getPriority()) {
|
||||
childRegion = region;
|
||||
}
|
||||
}
|
||||
@ -278,65 +269,99 @@ else if(appSize < 2)
|
||||
return childRegion;
|
||||
}
|
||||
|
||||
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public String getAreaFlag(String name, String subname, String defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? data : defaultValue;
|
||||
}
|
||||
|
||||
public Boolean getBooleanAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public Boolean getBooleanAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Boolean.valueOf(data) : null;
|
||||
}
|
||||
|
||||
public Boolean getBooleanAreaFlag(String name, String subname, boolean defaultValue, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public Boolean getBooleanAreaFlag(String name, String subname, boolean defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Boolean.valueOf(data) : defaultValue;
|
||||
}
|
||||
|
||||
public Integer getIntAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public Integer getIntAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Integer.valueOf(data) : null;
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getIntAreaFlag(String name, String subname, int defaultValue, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public Integer getIntAreaFlag(String name, String subname, int defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Integer.valueOf(data) : defaultValue;
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public Float getFloatAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Float.valueOf(data) : null;
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatAreaFlag(String name, String subname, float defaultValue, Boolean inherit, LocalPlayer player)
|
||||
{
|
||||
public Float getFloatAreaFlag(String name, String subname, float defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Float.valueOf(data) : defaultValue;
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Double.valueOf(data) : null;
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleAreaFlag(String name, String subname, double defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
return data != null ? Double.valueOf(data) : defaultValue;
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public State getStateAreaFlag(String name, String subname, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
|
||||
try {
|
||||
return data != null ? State.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocationFlag(String name, Server server, Boolean inherit, LocalPlayer player) {
|
||||
public State getStateAreaFlag(String name, String subname, State defaultValue, Boolean inherit, LocalPlayer player) {
|
||||
String data = getAreaFlag(name, subname, inherit, player);
|
||||
|
||||
try {
|
||||
return data != null ? State.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocationAreaFlag(String name, Server server, Boolean inherit, LocalPlayer player) {
|
||||
|
||||
ProtectedRegion childRegion = getChildRegion();
|
||||
if(childRegion == null)
|
||||
{
|
||||
if (childRegion == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -344,26 +369,20 @@ public Location getLocationFlag(String name, Server server, Boolean inherit, Loc
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!inherit)
|
||||
{
|
||||
if (!inherit) {
|
||||
return childRegion.getFlags().getLocationFlag(server, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Location value;
|
||||
do
|
||||
{
|
||||
do {
|
||||
value = childRegion.getFlags().getLocationFlag(server, name);
|
||||
childRegion = childRegion.getParent();
|
||||
|
||||
} while(value == null && childRegion != null);
|
||||
} while (value == null && childRegion != null);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear a region's parents for isFlagAllowed().
|
||||
*
|
||||
@ -371,16 +390,18 @@ public Location getLocationFlag(String name, Server server, Boolean inherit, Loc
|
||||
* @param hasCleared
|
||||
* @param region
|
||||
*/
|
||||
/*
|
||||
private void clearParents(Set<ProtectedRegion> needsClear,
|
||||
Set<ProtectedRegion> hasCleared, ProtectedRegion region) {
|
||||
ProtectedRegion parent = region.getParent();
|
||||
Set<ProtectedRegion> hasCleared, ProtectedRegion region) {
|
||||
ProtectedRegion parent = region.getParent();
|
||||
|
||||
while (parent != null) {
|
||||
if (!needsClear.remove(parent)) {
|
||||
hasCleared.add(parent);
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
while (parent != null) {
|
||||
if (!needsClear.remove(parent)) {
|
||||
hasCleared.add(parent);
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ private AreaFlags parseFlags(String data) {
|
||||
} else {
|
||||
flag = String.valueOf(k);
|
||||
}
|
||||
flags.set(flag, curState);
|
||||
flags.setFlag(flag, curState);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,7 @@ public ProtectedRegion getRegion(String id) {
|
||||
*/
|
||||
public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
||||
|
||||
/* This would only allow parents that overlap with their child
|
||||
List<ProtectedRegion> appRegions = new ArrayList<ProtectedRegion>();
|
||||
|
||||
for (Map.Entry<String,ProtectedRegion> entry : regions.entrySet()) {
|
||||
@ -139,8 +140,11 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
||||
appRegions.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return new ApplicableRegionSet(pt, appRegions, global);
|
||||
// this allows parents not to overlap with their childs
|
||||
|
||||
return new ApplicableRegionSet(pt, this.regions, global);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,6 +146,7 @@ public void removeRegion(String id) {
|
||||
*/
|
||||
public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
||||
|
||||
/* This would only allow parents that overlap with their child
|
||||
List<ProtectedRegion> appRegions = new ArrayList<ProtectedRegion>();
|
||||
|
||||
int x = pt.getBlockX();
|
||||
@ -156,8 +157,11 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) {
|
||||
appRegions.add(region);
|
||||
}
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
return new ApplicableRegionSet(pt, appRegions, global);
|
||||
// this allows parents not to overlap with their childs
|
||||
return new ApplicableRegionSet(pt, this.regions, global);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,7 +119,7 @@ public static String fromAlias(String name) {
|
||||
}
|
||||
private Map<String, Map<String, String>> flags = new HashMap<String, Map<String, String>>();
|
||||
|
||||
private Map<String, String> getFlagData(String name) {
|
||||
public Map<String, String> getFlagData(String name) {
|
||||
Map<String, String> ret = flags.get(name);
|
||||
if (ret == null) {
|
||||
ret = new HashMap<String, String>();
|
||||
@ -129,38 +129,6 @@ private Map<String, String> getFlagData(String name) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @return State
|
||||
*/
|
||||
public State get(String flag) {
|
||||
String value = getFlagData("states").get(flag);
|
||||
if (value == null) {
|
||||
return State.NONE;
|
||||
}
|
||||
State state = State.valueOf(value);
|
||||
if (state == null) {
|
||||
return State.NONE;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @param state
|
||||
*/
|
||||
public void set(String flag, State state) {
|
||||
if (state == State.NONE) {
|
||||
getFlagData("states").remove(flag);
|
||||
} else {
|
||||
getFlagData("states").put(flag, state.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public Set<Map.Entry<String, State>> entrySet() {
|
||||
|
||||
Map<String, State> ret = new HashMap<String, State>();
|
||||
@ -172,6 +140,64 @@ public Set<Map.Entry<String, State>> entrySet() {
|
||||
return ret.entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the State value of a state flag
|
||||
*
|
||||
* @param name
|
||||
* @param subname
|
||||
* @return State
|
||||
*/
|
||||
public State getStateFlag(String name, String subname) {
|
||||
String value = getFlagData(name).get(subname);
|
||||
if (value == null) {
|
||||
return State.NONE;
|
||||
}
|
||||
State state = State.NONE;
|
||||
try {
|
||||
state = State.valueOf(value);
|
||||
if (state == null) {
|
||||
return State.NONE;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return State.NONE;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @return State
|
||||
*/
|
||||
public State getStateFlag(String flag) {
|
||||
return getStateFlag("states", flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @param state
|
||||
*/
|
||||
public void setFlag(String name, String subname, State state) {
|
||||
if (state == State.NONE) {
|
||||
getFlagData(name).remove(subname);
|
||||
} else {
|
||||
getFlagData(name).put(subname, state.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the State value of a state flag
|
||||
*
|
||||
* @param flag
|
||||
* @param state
|
||||
*/
|
||||
public void setFlag(String flag, State state) {
|
||||
setFlag("states", flag, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AreaFlags)) {
|
||||
@ -250,32 +276,56 @@ public Boolean getBooleanFlag(String name, String subname, boolean defaultValue)
|
||||
|
||||
public Integer getIntFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Integer.valueOf(data) : null;
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getIntFlag(String name, String subname, int defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Integer.valueOf(data) : defaultValue;
|
||||
try {
|
||||
return data != null ? Integer.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Float.valueOf(data) : null;
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Float getFloatFlag(String name, String subname, float defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Float.valueOf(data) : defaultValue;
|
||||
try {
|
||||
return data != null ? Float.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleFlag(String name, String subname) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Double.valueOf(data) : null;
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Double getDoubleFlag(String name, String subname, double defaultValue) {
|
||||
String data = getFlagData(name).get(subname);
|
||||
return data != null ? Double.valueOf(data) : defaultValue;
|
||||
try {
|
||||
return data != null ? Double.valueOf(data) : defaultValue;
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Location getLocationFlag(Server server, String name) {
|
||||
|
@ -79,7 +79,7 @@ public String getId() {
|
||||
|
||||
|
||||
/**
|
||||
* @set the parentId. Used for serialization, don't touch it.
|
||||
* @setFlag the parentId. Used for serialization, don't touch it.
|
||||
*/
|
||||
public void setParentId() {
|
||||
|
||||
@ -112,7 +112,7 @@ public int getPriority() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param priority the priority to set
|
||||
* @param priority the priority to setFlag
|
||||
*/
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
@ -129,7 +129,7 @@ public ProtectedRegion getParent() {
|
||||
* Set the parent. This checks to make sure that it will not result
|
||||
* in circular inheritance.
|
||||
*
|
||||
* @param parent the parent to set
|
||||
* @param parent the parent to setFlag
|
||||
* @throws CircularInheritanceException
|
||||
*/
|
||||
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
|
||||
@ -170,7 +170,7 @@ public DefaultDomain getOwners() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param owners the owners to set
|
||||
* @param owners the owners to setFlag
|
||||
*/
|
||||
public void setOwners(DefaultDomain owners) {
|
||||
this.owners = owners;
|
||||
@ -185,7 +185,7 @@ public DefaultDomain getMembers() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param owners the owners to set
|
||||
* @param owners the owners to setFlag
|
||||
*/
|
||||
public void setMembers(DefaultDomain members) {
|
||||
this.members = members;
|
||||
|
@ -87,8 +87,8 @@ void setUpCourtyardRegion() {
|
||||
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.set(AreaFlags.FLAG_BUILD, State.NONE);
|
||||
flags.set(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_BUILD, State.NONE);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
region.setFlags(flags);
|
||||
region.setOwners(domain);
|
||||
manager.addRegion(region);
|
||||
@ -103,7 +103,7 @@ void setUpFountainRegion() throws Exception {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
|
||||
new BlockVector(0, 0, 0), new BlockVector(5, 5, 5));
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.set(AreaFlags.FLAG_FIRE_SPREAD, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.DENY);
|
||||
region.setFlags(flags);
|
||||
region.setMembers(domain);
|
||||
manager.addRegion(region);
|
||||
@ -116,7 +116,7 @@ void setUpNoFireRegion() throws Exception {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(NO_FIRE_ID,
|
||||
new BlockVector(100, 100, 100), new BlockVector(200, 200, 200));
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.set(AreaFlags.FLAG_FIRE_SPREAD, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.DENY);
|
||||
region.setFlags(flags);
|
||||
manager.addRegion(region);
|
||||
}
|
||||
|
@ -68,9 +68,9 @@ public void testLoadSave() throws Exception {
|
||||
|
||||
private void checkTestRegion1(ProtectedRegion region) {
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.set(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.set(AreaFlags.FLAG_PVP, State.DENY);
|
||||
flags.set(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_PVP, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
region.setFlags(flags);
|
||||
|
||||
assertEquals(region.getFlags(), flags);
|
||||
@ -83,9 +83,9 @@ private ProtectedRegion getTestRegion1() {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion("test2", min, max);
|
||||
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.set(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.set(AreaFlags.FLAG_PVP, State.DENY);
|
||||
flags.set(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_PVP, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
region.setFlags(flags);
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
@ -108,9 +108,9 @@ private ProtectedRegion getTestRegion2() {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion("test2", min, max);
|
||||
|
||||
AreaFlags flags = new AreaFlags();
|
||||
flags.set(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.set(AreaFlags.FLAG_PVP, State.ALLOW);
|
||||
flags.set(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
flags.setFlag(AreaFlags.FLAG_FIRE_SPREAD, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_PVP, State.ALLOW);
|
||||
flags.setFlag(AreaFlags.FLAG_LIGHTER, State.DENY);
|
||||
region.setFlags(flags);
|
||||
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
|
Loading…
Reference in New Issue
Block a user