mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-24 16:21:19 +01:00
Add Flag.getDefault(). Breaks StateFlag.getDefault() calls.
This commit is contained in:
parent
83c95bbb8c
commit
8098211d01
@ -24,7 +24,6 @@
|
|||||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -58,11 +57,7 @@ public boolean testBuild(RegionAssociable subject, StateFlag... flags) {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||||
if (flag instanceof StateFlag) {
|
return flag.getDefault();
|
||||||
return ((StateFlag) flag).getDefault() ? (V) State.DENY : (V) State.ALLOW; // Inverse default
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -379,10 +379,10 @@ public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag
|
|||||||
|
|
||||||
if (consideredValues.isEmpty()) {
|
if (consideredValues.isEmpty()) {
|
||||||
if (flag instanceof StateFlag) {
|
if (flag instanceof StateFlag) {
|
||||||
//noinspection unchecked
|
V fallback = flag.getDefault();
|
||||||
return (Collection<V>) (((StateFlag) flag).getDefault()
|
return fallback != null
|
||||||
? ImmutableList.of(State.ALLOW)
|
? ImmutableList.of(fallback)
|
||||||
: ImmutableList.of());
|
: (Collection<V>) ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -58,11 +57,7 @@ public boolean testBuild(RegionAssociable subject, StateFlag... flags) {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||||
if (flag instanceof StateFlag) {
|
return flag.getDefault();
|
||||||
return ((StateFlag) flag).getDefault() ? (V) State.ALLOW : null;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,6 +51,16 @@ public String getName() {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default value.
|
||||||
|
*
|
||||||
|
* @return the default value, if one exists, otherwise {@code null} may be returned
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public T getDefault() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public T chooseValue(Collection<T> values) {
|
public T chooseValue(Collection<T> values) {
|
||||||
if (!values.isEmpty()) {
|
if (!values.isEmpty()) {
|
||||||
|
@ -38,6 +38,7 @@ public RegionGroupFlag(String name, RegionGroup def) {
|
|||||||
this.def = def;
|
this.def = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public RegionGroup getDefault() {
|
public RegionGroup getDefault() {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,9 @@ public StateFlag(String name, boolean def) {
|
|||||||
this.def = def;
|
this.def = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getDefault() {
|
@Override
|
||||||
return def;
|
public State getDefault() {
|
||||||
|
return def ? State.ALLOW : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,18 +23,40 @@
|
|||||||
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class StringFlag extends Flag<String> {
|
public class StringFlag extends Flag<String> {
|
||||||
|
|
||||||
public StringFlag(String name, RegionGroup defaultGroup) {
|
private final String defaultValue;
|
||||||
super(name, defaultGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringFlag(String name) {
|
public StringFlag(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
this.defaultValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringFlag(String name, String defaultValue) {
|
||||||
|
super(name);
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringFlag(String name, RegionGroup defaultGroup) {
|
||||||
|
super(name, defaultGroup);
|
||||||
|
this.defaultValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringFlag(String name, RegionGroup defaultGroup, String defaultValue) {
|
||||||
|
super(name, defaultGroup);
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getDefault() {
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user