public abstract class Flag<T>
extends java.lang.Object
Each flag implementation is a singleton and must be registered with a
FlagRegistry to be useful. Flag values are stored as their
proper data type, but they are first "loaded" by calling
unmarshal(Object). On save, the objects are fed
through marshal(Object) and then saved.
| Modifier | Constructor and Description |
|---|---|
protected |
Flag(java.lang.String name)
Create a new flag with
RegionGroup.ALL as the default group. |
protected |
Flag(java.lang.String name,
RegionGroup defaultGroup)
Create a new flag.
|
| Modifier and Type | Method and Description |
|---|---|
T |
chooseValue(java.util.Collection<T> values)
Given a list of values, choose the best one.
|
T |
getDefault()
Get the default value.
|
java.lang.String |
getName()
Get the name of the flag.
|
RegionGroupFlag |
getRegionGroupFlag()
Get the region group flag.
|
boolean |
hasConflictStrategy()
Whether the flag can take a list of values and choose a "best one."
|
boolean |
implicitlySetWithMembership()
Whether the flag implicitly has a value set as long as
Flags.PASSTHROUGH is not set. |
static boolean |
isValidName(java.lang.String name)
Test whether a flag name is valid.
|
abstract java.lang.Object |
marshal(T o)
Convert the value stored for this flag into a type that can be
serialized into YAML.
|
abstract T |
parseInput(FlagContext context)
Parse a given input to coerce it to a type compatible with the flag.
|
boolean |
requiresSubject()
Whether the flag requires that a subject is specified in
FlagValueCalculator. |
java.lang.String |
toString() |
abstract T |
unmarshal(java.lang.Object o)
Convert a raw type that was loaded (from a YAML file, for example)
into the type that this flag uses.
|
boolean |
usesMembershipAsDefault()
Whether, if the flag is not set at all, the value should be derived
from membership.
|
protected Flag(java.lang.String name,
@Nullable
RegionGroup defaultGroup)
Flag names should match the regex ^[:A-Za-z0-9\-]{1,40}$.
name - The name of the flagdefaultGroup - The default groupjava.lang.IllegalArgumentException - Thrown if the name is invalidprotected Flag(java.lang.String name)
RegionGroup.ALL as the default group.
Flag names should match the regex ^[:A-Za-z0-9\-]{1,40}$.
name - The name of the flagjava.lang.IllegalArgumentException - Thrown if the name is invalidpublic final java.lang.String getName()
@Nullable public T getDefault()
null may be returned@Nullable public T chooseValue(java.util.Collection<T> values)
If there is no "best value" defined, then the first value should
be returned. The default implementation returns the first value. If
an implementation does have a strategy defined, then
hasConflictStrategy() should be overridden too.
values - A collection of valuespublic boolean hasConflictStrategy()
This is the case with the StateFlag where DENY
overrides ALLOW, but most flags just return the
first result from a list.
This flag is primarily used to optimize flag lookup in
FlagValueCalculator.
public boolean implicitlySetWithMembership()
Flags.PASSTHROUGH is not set.
This value is only changed, at least in WorldGuard, for the
Flags.BUILD flag.
public boolean usesMembershipAsDefault()
This value is only changed, at least in WorldGuard, for the
Flags.BUILD flag.
public boolean requiresSubject()
FlagValueCalculator.
This value is only changed, at least in WorldGuard, for the
Flags.BUILD flag.
public final RegionGroupFlag getRegionGroupFlag()
Every group has a region group flag except for region group flags themselves.
public abstract T parseInput(FlagContext context) throws InvalidFlagFormat
context - the FlagContextInvalidFlagFormat - Raised if the input is invalidpublic abstract T unmarshal(@Nullable java.lang.Object o)
o - The objectpublic abstract java.lang.Object marshal(T o)
o - The objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic static boolean isValidName(java.lang.String name)
name - The flag name