Merge pull request #1618 from JOO200/piston
Implement new alternative association mode to limit piston movement
This commit is contained in:
commit
58eaf31879
|
@ -160,6 +160,8 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
|
|||
disableExpDrops = getBoolean("protection.disable-xp-orb-drops", false);
|
||||
disableObsidianGenerators = getBoolean("protection.disable-obsidian-generators", false);
|
||||
|
||||
useMaxPriorityAssociation = getBoolean("protection.use-max-priority-association", false);
|
||||
|
||||
blockPotions = new HashSet<>();
|
||||
for (String potionName : getStringList("gameplay.block-potions", null)) {
|
||||
PotionEffectType effect = PotionEffectType.getByName(potionName);
|
||||
|
|
|
@ -31,7 +31,7 @@ import com.sk89q.worldguard.bukkit.cause.Cause;
|
|||
import com.sk89q.worldguard.config.ConfigurationManager;
|
||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.DelayedRegionOverlapAssociation;
|
||||
import com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation;
|
||||
import com.sk89q.worldguard.protection.association.Associables;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
|
@ -127,9 +127,10 @@ class AbstractListener implements Listener {
|
|||
} else if (rootCause instanceof Entity) {
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
final Entity entity = (Entity) rootCause;
|
||||
BukkitWorldConfiguration config =
|
||||
(BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(entity.getWorld()));
|
||||
Location loc;
|
||||
if (PaperLib.isPaper()
|
||||
&& ((BukkitWorldConfiguration) getWorldConfig(BukkitAdapter.adapt(entity.getWorld()))).usePaperEntityOrigin) {
|
||||
if (PaperLib.isPaper() && config.usePaperEntityOrigin) {
|
||||
loc = entity.getOrigin();
|
||||
if (loc == null) {
|
||||
loc = entity.getLocation();
|
||||
|
@ -137,10 +138,13 @@ class AbstractListener implements Listener {
|
|||
} else {
|
||||
loc = entity.getLocation();
|
||||
}
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc));
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc),
|
||||
config.useMaxPriorityAssociation);
|
||||
} else if (rootCause instanceof Block) {
|
||||
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(((Block) rootCause).getLocation()));
|
||||
Location loc = ((Block) rootCause).getLocation();
|
||||
return new DelayedRegionOverlapAssociation(query, BukkitAdapter.adapt(loc),
|
||||
getWorldConfig(BukkitAdapter.adapt(loc.getWorld())).useMaxPriorityAssociation);
|
||||
} else {
|
||||
return Associables.constant(Association.NON_MEMBER);
|
||||
}
|
||||
|
|
|
@ -171,6 +171,7 @@ public abstract class WorldConfiguration {
|
|||
public boolean strictEntitySpawn;
|
||||
public boolean ignoreHopperMoveEvents;
|
||||
public boolean breakDeniedHoppers;
|
||||
public boolean useMaxPriorityAssociation;
|
||||
protected Map<String, Integer> maxRegionCounts;
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,16 +21,8 @@ package com.sk89q.worldguard.protection;
|
|||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Determines that the association to a region is {@code OWNER} if the input
|
||||
|
@ -38,41 +30,18 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
*
|
||||
* <p>This class only performs a spatial query if its
|
||||
* {@link #getAssociation(List)} method is called.</p>
|
||||
*
|
||||
* @deprecated Use {@link com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation} instead. This class is mis-packaged.
|
||||
*/
|
||||
public class DelayedRegionOverlapAssociation implements RegionAssociable {
|
||||
|
||||
private final RegionQuery query;
|
||||
private final Location location;
|
||||
@Nullable
|
||||
private Set<ProtectedRegion> source;
|
||||
|
||||
@Deprecated
|
||||
public class DelayedRegionOverlapAssociation extends com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param query the query
|
||||
* @param location the location
|
||||
*/
|
||||
public DelayedRegionOverlapAssociation(RegionQuery query, Location location) {
|
||||
checkNotNull(query);
|
||||
checkNotNull(location);
|
||||
this.query = query;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
if (source == null) {
|
||||
ApplicableRegionSet result = query.getApplicableRegions(location);
|
||||
source = result.getRegions();
|
||||
}
|
||||
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
super(query, location, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldGuard team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.association;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractRegionOverlapAssociation implements RegionAssociable {
|
||||
|
||||
@Nullable
|
||||
protected Set<ProtectedRegion> source;
|
||||
private boolean useMaxPriorityAssociation;
|
||||
private int maxPriority;
|
||||
|
||||
protected AbstractRegionOverlapAssociation(@Nullable Set<ProtectedRegion> source, boolean useMaxPriorityAssociation) {
|
||||
this.source = source;
|
||||
this.useMaxPriorityAssociation = useMaxPriorityAssociation;
|
||||
}
|
||||
|
||||
protected void calcMaxPriority() {
|
||||
checkNotNull(source);
|
||||
int best = 0;
|
||||
for (ProtectedRegion region : source) {
|
||||
int priority = region.getPriority();
|
||||
if (priority > best) {
|
||||
best = priority;
|
||||
}
|
||||
}
|
||||
this.maxPriority = best;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
checkNotNull(source);
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty())) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
|
||||
if (source.contains(region)) {
|
||||
if (useMaxPriorityAssociation) {
|
||||
int priority = region.getPriority();
|
||||
if (priority == maxPriority) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
} else {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldGuard team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.association;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Determines that the association to a region is {@code OWNER} if the input
|
||||
* region is in a set of source regions.
|
||||
*
|
||||
* <p>This class only performs a spatial query if its
|
||||
* {@link #getAssociation(List)} method is called.</p>
|
||||
*/
|
||||
public class DelayedRegionOverlapAssociation extends AbstractRegionOverlapAssociation {
|
||||
|
||||
private final RegionQuery query;
|
||||
private final Location location;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param query the query
|
||||
* @param location the location
|
||||
*/
|
||||
public DelayedRegionOverlapAssociation(RegionQuery query, Location location) {
|
||||
this(query, location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param query the query
|
||||
* @param location the location
|
||||
* @param useMaxPriorityAssociation whether to use the max priority from regions to determine association
|
||||
*/
|
||||
public DelayedRegionOverlapAssociation(RegionQuery query, Location location, boolean useMaxPriorityAssociation) {
|
||||
super(null, useMaxPriorityAssociation);
|
||||
checkNotNull(query);
|
||||
checkNotNull(location);
|
||||
this.query = query;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
if (source == null) {
|
||||
ApplicableRegionSet result = query.getApplicableRegions(location);
|
||||
source = result.getRegions();
|
||||
calcMaxPriority();
|
||||
}
|
||||
|
||||
return super.getAssociation(regions);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,41 +19,35 @@
|
|||
|
||||
package com.sk89q.worldguard.protection.association;
|
||||
|
||||
import com.sk89q.worldguard.domains.Association;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Determines that the association to a region is {@code OWNER} if the input
|
||||
* region is in a set of source regions.
|
||||
*/
|
||||
public class RegionOverlapAssociation implements RegionAssociable {
|
||||
|
||||
private final Set<ProtectedRegion> source;
|
||||
public class RegionOverlapAssociation extends AbstractRegionOverlapAssociation {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param source set of regions that input regions must be contained within
|
||||
*/
|
||||
public RegionOverlapAssociation(Set<ProtectedRegion> source) {
|
||||
checkNotNull(source);
|
||||
this.source = source;
|
||||
public RegionOverlapAssociation(@Nonnull Set<ProtectedRegion> source) {
|
||||
this(source, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Association getAssociation(List<ProtectedRegion> regions) {
|
||||
for (ProtectedRegion region : regions) {
|
||||
if ((region.getId().equals(ProtectedRegion.GLOBAL_REGION) && source.isEmpty()) || source.contains(region)) {
|
||||
return Association.OWNER;
|
||||
}
|
||||
}
|
||||
|
||||
return Association.NON_MEMBER;
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param source set of regions that input regions must be contained within
|
||||
* @param useMaxPriorityAssociation whether to use the max priority from regions to determine association
|
||||
*/
|
||||
public RegionOverlapAssociation(@Nonnull Set<ProtectedRegion> source, boolean useMaxPriorityAssociation) {
|
||||
super(source, useMaxPriorityAssociation);
|
||||
calcMaxPriority();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,14 @@ import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
|||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public abstract class RegionOverlapTest {
|
||||
static String COURTYARD_ID = "courtyard";
|
||||
static String FOUNTAIN_ID = "fountain";
|
||||
|
@ -60,6 +64,14 @@ public abstract class RegionOverlapTest {
|
|||
TestPlayer player1;
|
||||
TestPlayer player2;
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: useMaxPrio = {0}")
|
||||
public static Iterable<Object[]> params() {
|
||||
return Arrays.asList(new Object[][]{{true}, {false}});
|
||||
}
|
||||
|
||||
@Parameterized.Parameter
|
||||
public boolean useMaxPriorityAssociation;
|
||||
|
||||
protected FlagRegistry getFlagRegistry() {
|
||||
return WorldGuard.getInstance().getFlagRegistry();
|
||||
}
|
||||
|
@ -105,6 +117,7 @@ public abstract class RegionOverlapTest {
|
|||
ProtectedRegion region = new ProtectedPolygonalRegion(COURTYARD_ID, points, 0, 10);
|
||||
|
||||
region.setOwners(domain);
|
||||
region.setPriority(5);
|
||||
manager.addRegion(region);
|
||||
|
||||
courtyard = region;
|
||||
|
@ -117,6 +130,7 @@ public abstract class RegionOverlapTest {
|
|||
ProtectedRegion region = new ProtectedCuboidRegion(FOUNTAIN_ID,
|
||||
BlockVector3.ZERO, BlockVector3.at(5, 5, 5));
|
||||
region.setMembers(domain);
|
||||
region.setPriority(10);
|
||||
manager.addRegion(region);
|
||||
|
||||
fountain = region;
|
||||
|
@ -186,7 +200,7 @@ public abstract class RegionOverlapTest {
|
|||
|
||||
HashSet<ProtectedRegion> source = new HashSet<>();
|
||||
source.add(courtyard);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source, useMaxPriorityAssociation);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
|
@ -206,14 +220,14 @@ public abstract class RegionOverlapTest {
|
|||
HashSet<ProtectedRegion> source = new HashSet<>();
|
||||
source.add(fountain);
|
||||
source.add(courtyard);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source, useMaxPriorityAssociation);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
// Inside courtyard
|
||||
appl = manager.getApplicableRegions(inCourtyard);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
assertTrue(useMaxPriorityAssociation ^ appl.testState(assoc, Flags.BUILD));
|
||||
// Inside fountain
|
||||
appl = manager.getApplicableRegions(inFountain);
|
||||
assertTrue(appl.testState(assoc, Flags.BUILD));
|
||||
|
@ -224,7 +238,7 @@ public abstract class RegionOverlapTest {
|
|||
ApplicableRegionSet appl;
|
||||
|
||||
HashSet<ProtectedRegion> source = new HashSet<>();
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source);
|
||||
RegionOverlapAssociation assoc = new RegionOverlapAssociation(source, useMaxPriorityAssociation);
|
||||
|
||||
// Outside
|
||||
appl = manager.getApplicableRegions(outside);
|
||||
|
|
Loading…
Reference in New Issue