mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 13:07:29 +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.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -58,11 +57,7 @@ public boolean testBuild(RegionAssociable subject, StateFlag... flags) {
|
||||
@Nullable
|
||||
@Override
|
||||
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
if (flag instanceof StateFlag) {
|
||||
return ((StateFlag) flag).getDefault() ? (V) State.DENY : (V) State.ALLOW; // Inverse default
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return flag.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -379,10 +379,10 @@ public <V> Collection<V> queryAllValues(@Nullable RegionAssociable subject, Flag
|
||||
|
||||
if (consideredValues.isEmpty()) {
|
||||
if (flag instanceof StateFlag) {
|
||||
//noinspection unchecked
|
||||
return (Collection<V>) (((StateFlag) flag).getDefault()
|
||||
? ImmutableList.of(State.ALLOW)
|
||||
: ImmutableList.of());
|
||||
V fallback = flag.getDefault();
|
||||
return fallback != null
|
||||
? ImmutableList.of(fallback)
|
||||
: (Collection<V>) ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -58,11 +57,7 @@ public boolean testBuild(RegionAssociable subject, StateFlag... flags) {
|
||||
@Nullable
|
||||
@Override
|
||||
public <V> V queryValue(@Nullable RegionAssociable subject, Flag<V> flag) {
|
||||
if (flag instanceof StateFlag) {
|
||||
return ((StateFlag) flag).getDefault() ? (V) State.ALLOW : null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return flag.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,16 @@ public String getName() {
|
||||
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
|
||||
public T chooseValue(Collection<T> values) {
|
||||
if (!values.isEmpty()) {
|
||||
|
@ -38,6 +38,7 @@ public RegionGroupFlag(String name, RegionGroup def) {
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionGroup getDefault() {
|
||||
return def;
|
||||
}
|
||||
|
@ -48,8 +48,9 @@ public StateFlag(String name, boolean def) {
|
||||
this.def = def;
|
||||
}
|
||||
|
||||
public boolean getDefault() {
|
||||
return def;
|
||||
@Override
|
||||
public State getDefault() {
|
||||
return def ? State.ALLOW : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,18 +23,40 @@
|
||||
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class StringFlag extends Flag<String> {
|
||||
|
||||
public StringFlag(String name, RegionGroup defaultGroup) {
|
||||
super(name, defaultGroup);
|
||||
}
|
||||
private final String defaultValue;
|
||||
|
||||
public StringFlag(String 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
|
||||
|
Loading…
Reference in New Issue
Block a user