Class Flag<T>
- Direct Known Subclasses:
BooleanFlag,CommandStringFlag,EntityTypeFlag,EnumFlag,GameModeTypeFlag,LocationFlag,MapFlag,NumberFlag,RegistryFlag,SetFlag,StateFlag,StringFlag,TimestampFlag,UnknownFlag,UUIDFlag,VectorFlag,WeatherTypeFlag
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.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a new flag withRegionGroup.ALLas the default group.protectedFlag(String name, RegionGroup defaultGroup)Create a new flag. -
Method Summary
Modifier and TypeMethodDescriptionchooseValue(Collection<T> values)Given a list of values, choose the best one.Get the default value.getName()Get the name of the flag.Get the region group flag.booleanWhether the flag can take a list of values and choose a "best one."booleanWhether the flag implicitly has a value set as long asFlags.PASSTHROUGHis not set.static booleanisValidName(String name)Test whether a flag name is valid.abstract ObjectConvert the value stored for this flag into a type that can be serialized into YAML.abstract TparseInput(FlagContext context)Parse a given input to coerce it to a type compatible with the flag.booleanWhether the flag requires that a subject is specified inFlagValueCalculator.toString()abstract TConvert a raw type that was loaded (from a YAML file, for example) into the type that this flag uses.booleanWhether, if the flag is not set at all, the value should be derived from membership.
-
Constructor Details
-
Flag
Create a new flag.Flag names should match the regex
^[:A-Za-z0-9\-]{1,40}$.- Parameters:
name- The name of the flagdefaultGroup- The default group- Throws:
IllegalArgumentException- Thrown if the name is invalid
-
Flag
Create a new flag withRegionGroup.ALLas the default group.Flag names should match the regex
^[:A-Za-z0-9\-]{1,40}$.- Parameters:
name- The name of the flag- Throws:
IllegalArgumentException- Thrown if the name is invalid
-
-
Method Details
-
getName
Get the name of the flag.- Returns:
- The name of the flag
-
getDefault
Get the default value.- Returns:
- The default value, if one exists, otherwise
nullmay be returned
-
chooseValue
Given a list of values, choose the best one.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.- Parameters:
values- A collection of values- Returns:
- The chosen value
-
hasConflictStrategy
public boolean hasConflictStrategy()Whether the flag can take a list of values and choose a "best one."This is the case with the
StateFlagwhereDENYoverridesALLOW, but most flags just return the first result from a list.This flag is primarily used to optimize flag lookup in
FlagValueCalculator.- Returns:
- Whether a best value can be chosen
-
implicitlySetWithMembership
public boolean implicitlySetWithMembership()Whether the flag implicitly has a value set as long asFlags.PASSTHROUGHis not set.This value is only changed, at least in WorldGuard, for the
Flags.BUILDflag.- Returns:
- Whether the flag is ignored
-
usesMembershipAsDefault
public boolean usesMembershipAsDefault()Whether, if the flag is not set at all, the value should be derived from membership.This value is only changed, at least in WorldGuard, for the
Flags.BUILDflag.- Returns:
- Whether membership is used
-
requiresSubject
public boolean requiresSubject()Whether the flag requires that a subject is specified inFlagValueCalculator.This value is only changed, at least in WorldGuard, for the
Flags.BUILDflag.- Returns:
- Whether a subject is required
-
getRegionGroupFlag
Get the region group flag.Every group has a region group flag except for region group flags themselves.
- Returns:
- The region group flag
-
parseInput
Parse a given input to coerce it to a type compatible with the flag.- Parameters:
context- theFlagContext- Returns:
- The coerced type
- Throws:
InvalidFlagFormat- Raised if the input is invalid
-
unmarshal
Convert a raw type that was loaded (from a YAML file, for example) into the type that this flag uses.- Parameters:
o- The object- Returns:
- The unmarshalled type
-
marshal
Convert the value stored for this flag into a type that can be serialized into YAML.- Parameters:
o- The object- Returns:
- The marshalled type
-
toString
-
isValidName
Test whether a flag name is valid.- Parameters:
name- The flag name- Returns:
- Whether the name is valid
-