Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c75b9c2328 | ||
|
|
0863db8cf0 | ||
|
|
53d6a272e6 | ||
|
|
71467a7ae7 | ||
|
|
56fa3458ab | ||
|
|
82e04ac4e5 | ||
|
|
564d4442fc | ||
|
|
df8fdd086b | ||
|
|
a31476251e | ||
|
|
360a655627 | ||
|
|
3b871b9c00 | ||
|
|
65834a2087 | ||
|
|
e9d85da691 | ||
|
|
cfa78af654 | ||
|
|
69af41f1e5 | ||
|
|
7074963fb1 |
No files matched your search
@@ -1,3 +1,16 @@
|
||||
5.2.2:
|
||||
- Changed configuration saving so empty lists will be added to
|
||||
the configuration files.
|
||||
|
||||
5.2.1:
|
||||
- Add region bounds to /region info
|
||||
- Added the ability to add owners/members to the global region for
|
||||
handling guest groups. Now if there's owners or members on the global
|
||||
region, then those that are not on the list cannot build.
|
||||
- Fixed some flag algorithm issues.
|
||||
- API: Fixed DefaultDomain.size() not counting players.
|
||||
- API: Undeprecated ApplicableRegionSet.allows(StateFlag).
|
||||
|
||||
5.2:
|
||||
- Gave the ability to use color colors and macros in greeting
|
||||
and farewell messages.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>5.2</version>
|
||||
<version>5.2.2</version>
|
||||
<name>WorldGuard</name>
|
||||
<description>WorldGuard protects your Minecraft servers</description>
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.sk89q.worldguard.chest.SignChestProtection;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -201,19 +202,35 @@ public class WorldConfiguration {
|
||||
}
|
||||
|
||||
private List<Integer> getIntList(String node, List<Integer> def) {
|
||||
List<Integer> res;
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getIntList(node, def);
|
||||
res = config.getIntList(node, def);
|
||||
} else {
|
||||
return parentConfig.getIntList(node, def);
|
||||
res = parentConfig.getIntList(node, def);
|
||||
}
|
||||
|
||||
if (res == null || res.size() == 0) {
|
||||
parentConfig.setProperty(node, new ArrayList<Integer>());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private List<String> getStringList(String node, List<String> def) {
|
||||
List<String> res;
|
||||
|
||||
if (config.getProperty(node) != null) {
|
||||
return config.getStringList(node, def);
|
||||
res = config.getStringList(node, def);
|
||||
} else {
|
||||
return parentConfig.getStringList(node, def);
|
||||
res = parentConfig.getStringList(node, def);
|
||||
}
|
||||
|
||||
if (res == null || res.size() == 0) {
|
||||
parentConfig.setProperty(node, new ArrayList<String>());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -438,6 +438,11 @@ public class RegionCommands {
|
||||
+ owners.toUserFriendlyString());
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Members: "
|
||||
+ members.toUserFriendlyString());
|
||||
BlockVector min = region.getMinimumPoint();
|
||||
BlockVector max = region.getMaximumPoint();
|
||||
String c = "(" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")";
|
||||
c += " (" +max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")";
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "Bounds: " + c);
|
||||
}
|
||||
|
||||
@Command(aliases = {"list"},
|
||||
|
||||
@@ -49,10 +49,6 @@ public class RegionMemberCommands {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
@@ -94,10 +90,6 @@ public class RegionMemberCommands {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
@@ -139,10 +131,6 @@ public class RegionMemberCommands {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
@@ -184,10 +172,6 @@ public class RegionMemberCommands {
|
||||
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
||||
|
||||
String id = args.getString(0);
|
||||
|
||||
if (id.equalsIgnoreCase("__global__")) {
|
||||
throw new CommandException("The region cannot be named __global__");
|
||||
}
|
||||
|
||||
RegionManager mgr = plugin.getGlobalRegionManager().get(world);
|
||||
ProtectedRegion region = mgr.getRegion(id);
|
||||
|
||||
@@ -81,7 +81,7 @@ public class DefaultDomain implements Domain {
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return groups.size();
|
||||
return groups.size() + players.size();
|
||||
}
|
||||
|
||||
public String toPlayersString() {
|
||||
|
||||
@@ -81,13 +81,10 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
/**
|
||||
* Gets the state of a state flag. This cannot be used for the build flag.
|
||||
*
|
||||
* @see #allows(com.sk89q.worldguard.protection.flags.StateFlag, com.sk89q.worldguard.LocalPlayer)
|
||||
* @deprecated use the {@link #allows(StateFlag, LocalPlayer)} that takes a player
|
||||
* @param flag flag to check
|
||||
* @return whether it is allowed
|
||||
* @throws IllegalArgumentException if the build flag is given
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean allows(StateFlag flag) {
|
||||
if (flag == DefaultFlag.BUILD) {
|
||||
throw new IllegalArgumentException("Can't use build flag with allows()");
|
||||
@@ -156,16 +153,27 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
RegionGroupFlag groupFlag,
|
||||
LocalPlayer groupPlayer) {
|
||||
boolean found = false;
|
||||
boolean hasFlagDefined = false;
|
||||
boolean allowed = false; // Used for ALLOW override
|
||||
boolean def = flag.getDefault();
|
||||
|
||||
// Handle defaults
|
||||
if (globalRegion != null) {
|
||||
State globalState = globalRegion.getFlag(flag);
|
||||
|
||||
|
||||
// The global region has this flag set
|
||||
if (globalState != null) {
|
||||
def = (globalState == State.ALLOW);
|
||||
// Build flag is very special
|
||||
if (player != null && globalRegion.hasMembersOrOwners()) {
|
||||
def = globalRegion.isMember(player) && (globalState == State.ALLOW);
|
||||
} else {
|
||||
def = (globalState == State.ALLOW);
|
||||
}
|
||||
} else {
|
||||
// Build flag is very special
|
||||
if (player != null && globalRegion.hasMembersOrOwners()) {
|
||||
def = globalRegion.isMember(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +212,7 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
ProtectedRegion region = it.next();
|
||||
|
||||
// Ignore lower priority regions
|
||||
if (found && region.getPriority() < lastPriority) {
|
||||
if (hasFlagDefined && region.getPriority() < lastPriority) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -239,6 +247,7 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
if (v == State.ALLOW) {
|
||||
allowed = true;
|
||||
found = true;
|
||||
hasFlagDefined = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -246,6 +255,8 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
// on membership, so we have to check for parent-child
|
||||
// relationships
|
||||
if (player != null) {
|
||||
hasFlagDefined = true;
|
||||
|
||||
if (hasCleared.contains(region)) {
|
||||
// Already cleared, so do nothing
|
||||
} else {
|
||||
@@ -320,9 +331,10 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
||||
clearParents(needsClear, hasCleared, region);
|
||||
|
||||
needsClear.put(region, region.getFlag(flag));
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
found = true;
|
||||
|
||||
lastPriority = region.getPriority();
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,6 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||
* @return the members
|
||||
*/
|
||||
public DefaultDomain getMembers() {
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
@@ -178,12 +177,21 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||
public void setMembers(DefaultDomain members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a region has members or owners.
|
||||
*
|
||||
* @return whether there are members or owners
|
||||
*/
|
||||
public boolean hasMembersOrOwners() {
|
||||
return owners.size() > 0 || members.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player is an owner of region or any of its parents.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
* @param player player to check
|
||||
* @return whether an owner
|
||||
*/
|
||||
public boolean isOwner(LocalPlayer player) {
|
||||
if (owners.contains(player)) {
|
||||
@@ -202,12 +210,12 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether a player is a member of the region or any of its parents.
|
||||
* Checks whether a player is a member OR OWNER of the region
|
||||
* or any of its parents.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
* @param player player to check
|
||||
* @return whether an owner or member
|
||||
*/
|
||||
public boolean isMember(LocalPlayer player) {
|
||||
if (owners.contains(player) || members.contains(player)) {
|
||||
@@ -226,6 +234,30 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a flag's value.
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
@@ -39,140 +41,459 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ApplicableRegionSetTest {
|
||||
static String COURTYARD_ID = "courtyard";
|
||||
static String FOUNTAIN_ID = "fountain";
|
||||
static String NO_FIRE_ID = "nofire";
|
||||
static String MEMBER_GROUP = "member";
|
||||
static String COURTYARD_GROUP = "courtyard";
|
||||
|
||||
Vector inFountain = new Vector(2, 2, 2);
|
||||
Vector inCourtyard = new Vector(7, 7, 7);
|
||||
Vector outside = new Vector(15, 15, 15);
|
||||
Vector inNoFire = new Vector(150, 150, 150);
|
||||
RegionManager manager;
|
||||
ProtectedRegion globalRegion;
|
||||
ProtectedRegion courtyard;
|
||||
ProtectedRegion fountain;
|
||||
TestPlayer player1;
|
||||
TestPlayer player2;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
setUpGlobalRegion();
|
||||
|
||||
manager = new FlatRegionManager(null);
|
||||
|
||||
setUpPlayers();
|
||||
setUpCourtyardRegion();
|
||||
setUpFountainRegion();
|
||||
setUpNoFireRegion();
|
||||
}
|
||||
|
||||
void setUpPlayers() {
|
||||
player1 = new TestPlayer("tetsu");
|
||||
player1.addGroup(MEMBER_GROUP);
|
||||
player1.addGroup(COURTYARD_GROUP);
|
||||
|
||||
player2 = new TestPlayer("alex");
|
||||
player2.addGroup(MEMBER_GROUP);
|
||||
}
|
||||
|
||||
void setUpGlobalRegion() {
|
||||
globalRegion = new GlobalProtectedRegion("__global__");
|
||||
}
|
||||
|
||||
void setUpCourtyardRegion() {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup(COURTYARD_GROUP);
|
||||
|
||||
ArrayList<BlockVector2D> points = new ArrayList<BlockVector2D>();
|
||||
points.add(new BlockVector2D(0, 0));
|
||||
points.add(new BlockVector2D(10, 0));
|
||||
points.add(new BlockVector2D(10, 10));
|
||||
points.add(new BlockVector2D(0, 10));
|
||||
|
||||
//ProtectedRegion region = new ProtectedCuboidRegion(COURTYARD_ID, new BlockVector(0, 0, 0), new BlockVector(10, 10, 10));
|
||||
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
region.setOwners(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
courtyard = region;
|
||||
}
|
||||
|
||||
void setUpFountainRegion() throws Exception {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup(MEMBER_GROUP);
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
|
||||
new BlockVector(0, 0, 0), new BlockVector(5, 5, 5));
|
||||
region.setMembers(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
fountain = region;
|
||||
fountain.setParent(courtyard);
|
||||
fountain.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
|
||||
}
|
||||
|
||||
void setUpNoFireRegion() throws Exception {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(NO_FIRE_ID,
|
||||
new BlockVector(100, 100, 100), new BlockVector(200, 200, 200));
|
||||
manager.addRegion(region);
|
||||
region.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonBuildFlag() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
public void testStateFlagPriorityFallThrough() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
// Inside no fire zone
|
||||
appl = manager.getApplicableRegions(inNoFire);
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
StateFlag STATE1 = new StateFlag(null, false);
|
||||
StateFlag STATE2 = new StateFlag(null, false);
|
||||
StateFlag STATE3 = new StateFlag(null, false);
|
||||
|
||||
region = mock.add(0);
|
||||
region.setFlag(STATE1, StateFlag.State.ALLOW);
|
||||
region.setFlag(STATE2, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(1);
|
||||
region.setFlag(STATE1, StateFlag.State.DENY);
|
||||
region.setFlag(STATE3, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.allows(STATE1));
|
||||
assertFalse(set.allows(STATE2));
|
||||
assertTrue(set.allows(STATE3));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPlayer1BuildAccess() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
public void testNonStateFlagPriorityFallThrough() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
StringFlag STRING1 = new StringFlag(null);
|
||||
StringFlag STRING2 = new StringFlag(null);
|
||||
StringFlag STRING3 = new StringFlag(null);
|
||||
StringFlag STRING4 = new StringFlag(null);
|
||||
|
||||
region = mock.add(0);
|
||||
region.setFlag(STRING1, "Beans");
|
||||
region.setFlag(STRING2, "Apples");
|
||||
|
||||
region = mock.add(1);
|
||||
region.setFlag(STRING1, "Cats");
|
||||
region.setFlag(STRING3, "Bananas");
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertEquals(set.getFlag(STRING1), "Cats");
|
||||
assertEquals(set.getFlag(STRING2), "Apples");
|
||||
assertEquals(set.getFlag(STRING3), "Bananas");
|
||||
assertEquals(set.getFlag(STRING4), null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPlayer2BuildAccess() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> test = new HashSet<ProtectedRegion>();
|
||||
test.add(courtyard);
|
||||
test.add(fountain);
|
||||
System.out.println(test);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.canBuild(player2));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertFalse(appl.canBuild(player2));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.canBuild(player2));
|
||||
public void testStateFlagMultiplePriorityFallThrough() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
StringFlag STRING1 = new StringFlag(null);
|
||||
StringFlag STRING2 = new StringFlag(null);
|
||||
StringFlag STRING3 = new StringFlag(null);
|
||||
StringFlag STRING4 = new StringFlag(null);
|
||||
|
||||
region = mock.add(0);
|
||||
region.setFlag(STRING1, "Beans");
|
||||
region.setFlag(STRING2, "Apples");
|
||||
region.setFlag(STRING3, "Dogs");
|
||||
|
||||
region = mock.add(1);
|
||||
region.setFlag(STRING1, "Cats");
|
||||
region.setFlag(STRING3, "Bananas");
|
||||
|
||||
region = mock.add(10);
|
||||
region.setFlag(STRING3, "Strings");
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertEquals(set.getFlag(STRING1), "Cats");
|
||||
assertEquals(set.getFlag(STRING2), "Apples");
|
||||
assertEquals(set.getFlag(STRING3), "Strings");
|
||||
assertEquals(set.getFlag(STRING4), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateGlobalDefault() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
StateFlag STATE1 = new StateFlag(null, false);
|
||||
StateFlag STATE2 = new StateFlag(null, false);
|
||||
StateFlag STATE3 = new StateFlag(null, false);
|
||||
StateFlag STATE4 = new StateFlag(null, true);
|
||||
StateFlag STATE5 = new StateFlag(null, true);
|
||||
StateFlag STATE6 = new StateFlag(null, true);
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(STATE1, StateFlag.State.ALLOW);
|
||||
region.setFlag(STATE2, StateFlag.State.DENY);
|
||||
region.setFlag(STATE4, StateFlag.State.ALLOW);
|
||||
region.setFlag(STATE5, StateFlag.State.DENY);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.allows(STATE1));
|
||||
assertFalse(set.allows(STATE2));
|
||||
assertFalse(set.allows(STATE3));
|
||||
assertTrue(set.allows(STATE4));
|
||||
assertFalse(set.allows(STATE5));
|
||||
assertTrue(set.allows(STATE6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateGlobalWithRegionsDefault() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
StateFlag STATE1 = new StateFlag(null, false);
|
||||
StateFlag STATE2 = new StateFlag(null, false);
|
||||
StateFlag STATE3 = new StateFlag(null, false);
|
||||
StateFlag STATE4 = new StateFlag(null, true);
|
||||
StateFlag STATE5 = new StateFlag(null, true);
|
||||
StateFlag STATE6 = new StateFlag(null, true);
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(STATE1, StateFlag.State.ALLOW);
|
||||
region.setFlag(STATE2, StateFlag.State.DENY);
|
||||
region.setFlag(STATE4, StateFlag.State.ALLOW);
|
||||
region.setFlag(STATE5, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(0);
|
||||
region.setFlag(STATE1, StateFlag.State.DENY);
|
||||
region.setFlag(STATE2, StateFlag.State.DENY);
|
||||
region.setFlag(STATE4, StateFlag.State.DENY);
|
||||
region.setFlag(STATE5, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(1);
|
||||
region.setFlag(STATE5, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.allows(STATE1));
|
||||
assertFalse(set.allows(STATE2));
|
||||
assertFalse(set.allows(STATE3));
|
||||
assertFalse(set.allows(STATE4));
|
||||
assertTrue(set.allows(STATE5));
|
||||
assertTrue(set.allows(STATE6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAccess() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildRegionPriorities() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer upperMember = mock.createPlayer();
|
||||
LocalPlayer lowerMember = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(lowerMember);
|
||||
|
||||
region = mock.add(1);
|
||||
region.getOwners().addPlayer(upperMember);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(upperMember));
|
||||
assertFalse(set.canBuild(lowerMember));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildDenyFlag() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAllowFlag() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHigherPriorityOverrideBuildDenyFlag() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(1);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHigherPriorityUnsetBuildDenyFlag() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(1);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorityDisjointBuildDenyFlagAndMembership() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(1);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorityDisjointBuildDenyFlagAndRegion() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(1);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorityDisjointMembershipAndBuildDenyFlag() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
region = mock.add(1);
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoGlobalRegionDefaultBuild() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionDefaultBuild() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
region = mock.global();
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionBuildFlagAllow() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertTrue(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionBuildFlagDeny() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionBuildFlagAllowWithRegion() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionBuildFlagDenyWithRegion() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
|
||||
region = mock.add(0);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionHavingOwnershipBuildFlagUnset() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionHavingOwnershipBuildFlagAllow() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertTrue(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionHavingOwnershipBuildFlagDeny() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer member = mock.createPlayer();
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
region.setFlag(DefaultFlag.BUILD, StateFlag.State.DENY);
|
||||
region.getOwners().addPlayer(member);
|
||||
|
||||
ApplicableRegionSet set = mock.getApplicableSet();
|
||||
assertFalse(set.canBuild(member));
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// $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;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.TestPlayer;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class MockApplicableRegionSet {
|
||||
|
||||
private TreeSet<ProtectedRegion> regions = new TreeSet<ProtectedRegion>();
|
||||
private ProtectedRegion global;
|
||||
private int id = 0;
|
||||
private int playerIndex = 0;
|
||||
|
||||
public void add(ProtectedRegion region) {
|
||||
regions.add(region);
|
||||
}
|
||||
|
||||
public LocalPlayer createPlayer() {
|
||||
playerIndex++;
|
||||
LocalPlayer player = new TestPlayer("#PLAYER_" + playerIndex);
|
||||
return player;
|
||||
}
|
||||
|
||||
public ProtectedRegion global() {
|
||||
global = new GlobalProtectedRegion("__global__");
|
||||
return global;
|
||||
}
|
||||
|
||||
public ProtectedRegion add(int priority) {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(getNextId(),
|
||||
new BlockVector(0, 0, 0), new BlockVector(1, 1, 1));
|
||||
region.setPriority(priority);
|
||||
add(region);
|
||||
return region;
|
||||
}
|
||||
|
||||
public ProtectedRegion add(int priority, ProtectedRegion parent)
|
||||
throws ProtectedRegion.CircularInheritanceException {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(getNextId(),
|
||||
new BlockVector(0, 0, 0), new BlockVector(1, 1, 1));
|
||||
region.setPriority(priority);
|
||||
region.setParent(parent);
|
||||
add(region);
|
||||
return region;
|
||||
}
|
||||
|
||||
public ApplicableRegionSet getApplicableSet() {
|
||||
return new ApplicableRegionSet(regions, global);
|
||||
}
|
||||
|
||||
private String getNextId() {
|
||||
id++;
|
||||
return "#REGION_" + id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// $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;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.TestPlayer;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.managers.FlatRegionManager;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class RegionOverlapTest {
|
||||
static String COURTYARD_ID = "courtyard";
|
||||
static String FOUNTAIN_ID = "fountain";
|
||||
static String NO_FIRE_ID = "nofire";
|
||||
static String MEMBER_GROUP = "member";
|
||||
static String COURTYARD_GROUP = "courtyard";
|
||||
|
||||
Vector inFountain = new Vector(2, 2, 2);
|
||||
Vector inCourtyard = new Vector(7, 7, 7);
|
||||
Vector outside = new Vector(15, 15, 15);
|
||||
Vector inNoFire = new Vector(150, 150, 150);
|
||||
RegionManager manager;
|
||||
ProtectedRegion globalRegion;
|
||||
ProtectedRegion courtyard;
|
||||
ProtectedRegion fountain;
|
||||
TestPlayer player1;
|
||||
TestPlayer player2;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
setUpGlobalRegion();
|
||||
|
||||
manager = new FlatRegionManager(null);
|
||||
|
||||
setUpPlayers();
|
||||
setUpCourtyardRegion();
|
||||
setUpFountainRegion();
|
||||
setUpNoFireRegion();
|
||||
}
|
||||
|
||||
void setUpPlayers() {
|
||||
player1 = new TestPlayer("tetsu");
|
||||
player1.addGroup(MEMBER_GROUP);
|
||||
player1.addGroup(COURTYARD_GROUP);
|
||||
|
||||
player2 = new TestPlayer("alex");
|
||||
player2.addGroup(MEMBER_GROUP);
|
||||
}
|
||||
|
||||
void setUpGlobalRegion() {
|
||||
globalRegion = new GlobalProtectedRegion("__global__");
|
||||
}
|
||||
|
||||
void setUpCourtyardRegion() {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup(COURTYARD_GROUP);
|
||||
|
||||
ArrayList<BlockVector2D> points = new ArrayList<BlockVector2D>();
|
||||
points.add(new BlockVector2D(0, 0));
|
||||
points.add(new BlockVector2D(10, 0));
|
||||
points.add(new BlockVector2D(10, 10));
|
||||
points.add(new BlockVector2D(0, 10));
|
||||
|
||||
//ProtectedRegion region = new ProtectedCuboidRegion(COURTYARD_ID, new BlockVector(0, 0, 0), new BlockVector(10, 10, 10));
|
||||
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
region.setOwners(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
courtyard = region;
|
||||
}
|
||||
|
||||
void setUpFountainRegion() throws Exception {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup(MEMBER_GROUP);
|
||||
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
|
||||
new BlockVector(0, 0, 0), new BlockVector(5, 5, 5));
|
||||
region.setMembers(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
fountain = region;
|
||||
fountain.setParent(courtyard);
|
||||
fountain.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
|
||||
}
|
||||
|
||||
void setUpNoFireRegion() throws Exception {
|
||||
ProtectedRegion region = new ProtectedCuboidRegion(NO_FIRE_ID,
|
||||
new BlockVector(100, 100, 100), new BlockVector(200, 200, 200));
|
||||
manager.addRegion(region);
|
||||
region.setFlag(DefaultFlag.FIRE_SPREAD, StateFlag.State.DENY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonBuildFlag() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
|
||||
// Inside no fire zone
|
||||
appl = manager.getApplicableRegions(inNoFire);
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayer1BuildAccess() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.canBuild(player1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayer2BuildAccess() {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> test = new HashSet<ProtectedRegion>();
|
||||
test.add(courtyard);
|
||||
test.add(fountain);
|
||||
System.out.println(test);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.canBuild(player2));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertFalse(appl.canBuild(player2));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.canBuild(player2));
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public class RegionPriorityTest {
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user