mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-14 03:11:44 +01:00
Add unit test to test global command blacklist with region command whitelist.
This commit is contained in:
parent
cd221ea19c
commit
1581390092
@ -24,7 +24,13 @@
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StringFlag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.util.command.CommandFilter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ApplicableRegionSetTest {
|
||||
@ -481,4 +487,45 @@ public void testGlobalRegionHavingOwnershipBuildFlagDeny() {
|
||||
assertFalse(set.canBuild(nonMember));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalRegionCommandBlacklistWithRegionWhitelist() {
|
||||
MockApplicableRegionSet mock = new MockApplicableRegionSet();
|
||||
ProtectedRegion region;
|
||||
|
||||
LocalPlayer nonMember = mock.createPlayer();
|
||||
|
||||
region = mock.global();
|
||||
Set<String> blocked = new HashSet<String>();
|
||||
blocked.add("/deny");
|
||||
blocked.add("/strange");
|
||||
region.setFlag(DefaultFlag.BLOCKED_CMDS, blocked);
|
||||
|
||||
region = mock.add(0);
|
||||
Set<String> allowed = new HashSet<String>();
|
||||
allowed.add("/permit");
|
||||
allowed.add("/strange");
|
||||
region.setFlag(DefaultFlag.ALLOWED_CMDS, allowed);
|
||||
|
||||
ApplicableRegionSet set;
|
||||
CommandFilter test;
|
||||
|
||||
set = mock.getApplicableSet();
|
||||
test = new CommandFilter(
|
||||
set.getFlag(DefaultFlag.ALLOWED_CMDS, nonMember),
|
||||
set.getFlag(DefaultFlag.BLOCKED_CMDS, nonMember));
|
||||
assertThat(test.apply("/permit"), is(true));
|
||||
assertThat(test.apply("/strange"), is(true));
|
||||
assertThat(test.apply("/other"), is(false));
|
||||
assertThat(test.apply("/deny"), is(false));
|
||||
|
||||
set = mock.getApplicableSetInWilderness();
|
||||
test = new CommandFilter(
|
||||
set.getFlag(DefaultFlag.ALLOWED_CMDS, nonMember),
|
||||
set.getFlag(DefaultFlag.BLOCKED_CMDS, nonMember));
|
||||
assertThat(test.apply("/permit"), is(true));
|
||||
assertThat(test.apply("/strange"), is(false));
|
||||
assertThat(test.apply("/other"), is(true));
|
||||
assertThat(test.apply("/deny"), is(false));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class MockApplicableRegionSet {
|
||||
@ -68,6 +69,10 @@ public ProtectedRegion add(int priority, ProtectedRegion parent)
|
||||
return region;
|
||||
}
|
||||
|
||||
public ApplicableRegionSet getApplicableSetInWilderness() {
|
||||
return new ApplicableRegionSet(Collections.<ProtectedRegion>emptyList(), global);
|
||||
}
|
||||
|
||||
public ApplicableRegionSet getApplicableSet() {
|
||||
return new ApplicableRegionSet(regions, global);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user