mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-16 23:55:23 +01:00
Removed old broken unit tests.
We may look at them in the future once those tests are needed again.
This commit is contained in:
parent
3b985f7eab
commit
061b303faa
@ -1,84 +0,0 @@
|
||||
// $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;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
|
||||
@org.junit.Ignore
|
||||
public class TestPlayer extends LocalPlayer {
|
||||
private String name;
|
||||
private Set<String> groups = new HashSet<String>();
|
||||
|
||||
public TestPlayer(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addGroup(String group) {
|
||||
groups.add(group.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasGroup(String group) {
|
||||
return groups.contains(group.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getPosition() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ban(String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printRaw(String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,486 +0,0 @@
|
||||
// $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.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.region.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.region.Region;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
import com.sk89q.worldguard.region.flags.StringFlag;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ApplicableRegionSetTest {
|
||||
|
||||
@Test
|
||||
public void testStateFlagPriorityFallThrough() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
Region region;
|
||||
|
||||
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 testNonStateFlagPriorityFallThrough() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
Region 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 testStateFlagMultiplePriorityFallThrough() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
|
||||
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();
|
||||
@SuppressWarnings("unused")
|
||||
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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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();
|
||||
Region 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));
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
// $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.region.Region;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
import com.sk89q.worldguard.region.indices.FlatIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
import com.sk89q.worldguard.region.shapes.Cuboid;
|
||||
import com.sk89q.worldguard.region.shapes.ExtrudedPolygon;
|
||||
import com.sk89q.worldguard.region.shapes.GlobalProtectedRegion;
|
||||
|
||||
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 FlatRegionManagerTest extends RegionOverlapTest {
|
||||
protected RegionIndex createRegionManager() throws Exception {
|
||||
return new FlatIndex(null);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// $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.worldguard.region.indices.FlatIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
|
||||
public class FlatRegionOverlapTest extends RegionOverlapTest {
|
||||
protected RegionIndex createRegionManager() throws Exception {
|
||||
return new FlatIndex(null);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// $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.worldguard.region.indices.FlatIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
|
||||
public class FlatRegionPriorityTest extends RegionPriorityTest {
|
||||
protected RegionIndex createRegionManager() throws Exception {
|
||||
return new FlatIndex(null);
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
// $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.region.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.region.Region;
|
||||
import com.sk89q.worldguard.region.shapes.Cuboid;
|
||||
import com.sk89q.worldguard.region.shapes.GlobalProtectedRegion;
|
||||
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class MockApplicableRegionSet {
|
||||
|
||||
private TreeSet<Region> regions = new TreeSet<Region>();
|
||||
private Region global;
|
||||
private int id = 0;
|
||||
private int playerIndex = 0;
|
||||
|
||||
public void add(Region region) {
|
||||
regions.add(region);
|
||||
}
|
||||
|
||||
public LocalPlayer createPlayer() {
|
||||
playerIndex++;
|
||||
LocalPlayer player = new TestPlayer("#PLAYER_" + playerIndex);
|
||||
return player;
|
||||
}
|
||||
|
||||
public Region global() {
|
||||
global = new GlobalProtectedRegion("__global__");
|
||||
return global;
|
||||
}
|
||||
|
||||
public Region add(int priority) {
|
||||
Region region = new Cuboid(getNextId(),
|
||||
new BlockVector(0, 0, 0), new BlockVector(1, 1, 1));
|
||||
region.setPriority(priority);
|
||||
add(region);
|
||||
return region;
|
||||
}
|
||||
|
||||
public Region add(int priority, Region parent)
|
||||
throws Region.CircularInheritanceException {
|
||||
Region region = new Cuboid(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;
|
||||
}
|
||||
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
// $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.region.Region;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
import com.sk89q.worldguard.region.indices.PriorityRTreeIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
import com.sk89q.worldguard.region.shapes.Cuboid;
|
||||
import com.sk89q.worldguard.region.shapes.ExtrudedPolygon;
|
||||
import com.sk89q.worldguard.region.shapes.GlobalProtectedRegion;
|
||||
|
||||
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 PRTreeRegionManagerTest extends RegionOverlapTest {
|
||||
protected RegionIndex createRegionManager() throws Exception {
|
||||
return new PriorityRTreeIndex(null);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// $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.worldguard.region.indices.PriorityRTreeIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
|
||||
public class PRTreeRegionOverlapTest extends RegionOverlapTest {
|
||||
protected RegionIndex createRegionManager() throws Exception {
|
||||
return new PriorityRTreeIndex(null);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// $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.worldguard.region.indices.PriorityRTreeIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
|
||||
public class PRTreeRegionPriorityTest extends RegionPriorityTest {
|
||||
protected RegionIndex createRegionManager() throws Exception {
|
||||
return new PriorityRTreeIndex(null);
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package com.sk89q.worldguard.protection;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.BlockVector2D;
|
||||
import com.sk89q.worldguard.region.Region;
|
||||
import com.sk89q.worldguard.region.shapes.Cuboid;
|
||||
import com.sk89q.worldguard.region.shapes.ExtrudedPolygon;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RegionIntersectTest {
|
||||
|
||||
@Test
|
||||
public void testCuboidGetIntersectingRegions() {
|
||||
Region region = new Cuboid("square",
|
||||
new BlockVector(100, 40, 0), new BlockVector(140, 128, 40));
|
||||
|
||||
assertIntersection(region, new Cuboid("normal",
|
||||
new BlockVector(80, 40, -20), new BlockVector(120, 128, 20)),
|
||||
true);
|
||||
|
||||
assertIntersection(region, new Cuboid("small",
|
||||
new BlockVector(98, 45, 20), new BlockVector(103, 50, 25)),
|
||||
true);
|
||||
|
||||
assertIntersection(region, new Cuboid("large",
|
||||
new BlockVector(-500, 0, -600), new BlockVector(1000, 128, 1000)),
|
||||
true);
|
||||
|
||||
assertIntersection(region, new Cuboid("short",
|
||||
new BlockVector(50, 40, -1), new BlockVector(150, 128, 2)),
|
||||
true);
|
||||
|
||||
assertIntersection(region, new Cuboid("long",
|
||||
new BlockVector(0, 40, 5), new BlockVector(1000, 128, 8)),
|
||||
true);
|
||||
|
||||
List<BlockVector2D> triangle_overlap = new ArrayList<BlockVector2D>();
|
||||
triangle_overlap.add(new BlockVector2D(90, -10));
|
||||
triangle_overlap.add(new BlockVector2D(120, -10));
|
||||
triangle_overlap.add(new BlockVector2D(90, 20));
|
||||
|
||||
assertIntersection(region, new ExtrudedPolygon("triangle_overlap",
|
||||
triangle_overlap, 0, 128),
|
||||
true);
|
||||
|
||||
List<BlockVector2D> triangle_no_overlap = new ArrayList<BlockVector2D>();
|
||||
triangle_no_overlap.add(new BlockVector2D(90, -10));
|
||||
triangle_no_overlap.add(new BlockVector2D(105, -10));
|
||||
triangle_no_overlap.add(new BlockVector2D(90, 5));
|
||||
|
||||
assertIntersection(region, new ExtrudedPolygon("triangle_no_overlap",
|
||||
triangle_no_overlap, 0, 128),
|
||||
false);
|
||||
|
||||
List<BlockVector2D> triangle_overlap_no_points = new ArrayList<BlockVector2D>();
|
||||
triangle_overlap_no_points.add(new BlockVector2D(100, -10));
|
||||
triangle_overlap_no_points.add(new BlockVector2D(120, 50));
|
||||
triangle_overlap_no_points.add(new BlockVector2D(140, -20));
|
||||
|
||||
assertIntersection(region, new ExtrudedPolygon("triangle_overlap_no_points",
|
||||
triangle_overlap_no_points, 60, 80),
|
||||
true);
|
||||
}
|
||||
|
||||
private void assertIntersection(Region region1, Region region2, boolean expected) {
|
||||
boolean actual = false;
|
||||
List<Region> regions = new ArrayList<Region>();
|
||||
regions.add(region2);
|
||||
|
||||
try {
|
||||
actual = (region1.getIntersectingRegions(regions).size() == 1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
assertEquals("Check for '" + region2.getId() + "' region failed.", expected, actual);
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
// $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.region.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.region.Region;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
import com.sk89q.worldguard.region.indices.FlatIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
import com.sk89q.worldguard.region.shapes.Cuboid;
|
||||
import com.sk89q.worldguard.region.shapes.ExtrudedPolygon;
|
||||
import com.sk89q.worldguard.region.shapes.GlobalProtectedRegion;
|
||||
|
||||
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 abstract 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);
|
||||
RegionIndex manager;
|
||||
Region globalRegion;
|
||||
Region courtyard;
|
||||
Region fountain;
|
||||
TestPlayer player1;
|
||||
TestPlayer player2;
|
||||
|
||||
protected abstract RegionIndex createRegionManager() throws Exception;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
setUpGlobalRegion();
|
||||
|
||||
manager = createRegionManager();
|
||||
|
||||
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));
|
||||
Region region = new ExtrudedPolygon(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);
|
||||
|
||||
Region region = new Cuboid(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 {
|
||||
Region region = new Cuboid(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<Region> test = new HashSet<Region>();
|
||||
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));
|
||||
}
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
// $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 java.util.ArrayList;
|
||||
import org.junit.Before;
|
||||
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.region.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.region.Region;
|
||||
import com.sk89q.worldguard.region.flags.DefaultFlag;
|
||||
import com.sk89q.worldguard.region.flags.StateFlag;
|
||||
import com.sk89q.worldguard.region.indices.FlatIndex;
|
||||
import com.sk89q.worldguard.region.indices.RegionIndex;
|
||||
import com.sk89q.worldguard.region.shapes.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class RegionPriorityTest {
|
||||
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);
|
||||
RegionIndex manager;
|
||||
Region globalRegion;
|
||||
Region courtyard;
|
||||
Region fountain;
|
||||
TestPlayer player1;
|
||||
TestPlayer player2;
|
||||
|
||||
protected abstract RegionIndex createRegionManager() throws Exception;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
setUpGlobalRegion();
|
||||
|
||||
manager = createRegionManager();
|
||||
|
||||
setUpPlayers();
|
||||
setUpCourtyardRegion();
|
||||
setUpFountainRegion();
|
||||
}
|
||||
|
||||
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));
|
||||
Region region = new ExtrudedPolygon(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
region.setOwners(domain);
|
||||
manager.addRegion(region);
|
||||
|
||||
courtyard = region;
|
||||
courtyard.setFlag(DefaultFlag.MOB_SPAWNING, StateFlag.State.DENY);
|
||||
}
|
||||
|
||||
void setUpFountainRegion() throws Exception {
|
||||
DefaultDomain domain = new DefaultDomain();
|
||||
domain.addGroup(MEMBER_GROUP);
|
||||
|
||||
Region region = new Cuboid(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);
|
||||
fountain.setFlag(DefaultFlag.MOB_SPAWNING, StateFlag.State.ALLOW);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoPriorities() throws Exception {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
courtyard.setPriority(0);
|
||||
fountain.setPriority(0);
|
||||
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
assertFalse(appl.allows(DefaultFlag.MOB_SPAWNING));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
assertFalse(appl.allows(DefaultFlag.MOB_SPAWNING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorities() throws Exception {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
courtyard.setPriority(5);
|
||||
fountain.setPriority(0);
|
||||
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertFalse(appl.allows(DefaultFlag.FIRE_SPREAD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorities2() throws Exception {
|
||||
ApplicableRegionSet appl;
|
||||
|
||||
fountain.setPriority(0);
|
||||
fountain.setPriority(5);
|
||||
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertFalse(appl.allows(DefaultFlag.MOB_SPAWNING));
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.allows(DefaultFlag.MOB_SPAWNING));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user