Class Flag<T>

java.lang.Object
com.sk89q.worldguard.protection.flags.Flag<T>
Direct Known Subclasses:
BooleanFlag, CommandStringFlag, EntityTypeFlag, EnumFlag, GameModeTypeFlag, LocationFlag, MapFlag, NumberFlag, RegistryFlag, SetFlag, StateFlag, StringFlag, TimestampFlag, UnknownFlag, UUIDFlag, VectorFlag, WeatherTypeFlag

public abstract class Flag<T> extends Object
A flag carries extra data on a region.

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 Details

    • Flag

      protected Flag(String name, @Nullable RegionGroup defaultGroup)
      Create a new flag.

      Flag names should match the regex ^[:A-Za-z0-9\-]{1,40}$.

      Parameters:
      name - The name of the flag
      defaultGroup - The default group
      Throws:
      IllegalArgumentException - Thrown if the name is invalid
    • Flag

      protected Flag(String name)
      Create a new flag with RegionGroup.ALL as 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

      public final String getName()
      Get the name of the flag.
      Returns:
      The name of the flag
    • getDefault

      @Nullable public T getDefault()
      Get the default value.
      Returns:
      The default value, if one exists, otherwise null may be returned
    • chooseValue

      @Nullable public T chooseValue(Collection<T> values)
      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 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.

      Returns:
      Whether a best value can be chosen
    • implicitlySetWithMembership

      public boolean implicitlySetWithMembership()
      Whether the flag implicitly has a value set as long as Flags.PASSTHROUGH is not set.

      This value is only changed, at least in WorldGuard, for the Flags.BUILD flag.

      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.BUILD flag.

      Returns:
      Whether membership is used
    • requiresSubject

      public boolean requiresSubject()
      Whether the flag requires that a subject is specified in FlagValueCalculator.

      This value is only changed, at least in WorldGuard, for the Flags.BUILD flag.

      Returns:
      Whether a subject is required
    • getRegionGroupFlag

      public final RegionGroupFlag 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

      public abstract T parseInput(FlagContext context) throws InvalidFlagFormat
      Parse a given input to coerce it to a type compatible with the flag.
      Parameters:
      context - the FlagContext
      Returns:
      The coerced type
      Throws:
      InvalidFlagFormat - Raised if the input is invalid
    • unmarshal

      public abstract T unmarshal(@Nullable Object o)
      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

      public abstract Object marshal(T o)
      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

      public String toString()
      Overrides:
      toString in class Object
    • isValidName

      public static boolean isValidName(String name)
      Test whether a flag name is valid.
      Parameters:
      name - The flag name
      Returns:
      Whether the name is valid