Class StateFlag

java.lang.Object
com.sk89q.worldguard.protection.flags.Flag<StateFlag.State>
com.sk89q.worldguard.protection.flags.StateFlag

public class StateFlag extends Flag<StateFlag.State>
Stores a bi-state value.
  • Constructor Details

    • StateFlag

      public StateFlag(String name, boolean def, RegionGroup defaultGroup)
    • StateFlag

      public StateFlag(String name, boolean def)
  • Method Details

    • getDefault

      public StateFlag.State getDefault()
      Description copied from class: Flag
      Get the default value.
      Overrides:
      getDefault in class Flag<StateFlag.State>
      Returns:
      The default value, if one exists, otherwise null may be returned
    • hasConflictStrategy

      public boolean hasConflictStrategy()
      Description copied from class: Flag
      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.

      Overrides:
      hasConflictStrategy in class Flag<StateFlag.State>
      Returns:
      Whether a best value can be chosen
    • chooseValue

      @Nullable public StateFlag.State chooseValue(Collection<StateFlag.State> values)
      Description copied from class: Flag
      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 Flag.hasConflictStrategy() should be overridden too.

      Overrides:
      chooseValue in class Flag<StateFlag.State>
      Parameters:
      values - A collection of values
      Returns:
      The chosen value
    • preventsAllowOnGlobal

      public boolean preventsAllowOnGlobal()
      Whether setting this flag to StateFlag.State.ALLOW is prevented on the global region.

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

      Returns:
      Whether ALLOW is prevented
    • parseInput

      public StateFlag.State parseInput(FlagContext context) throws InvalidFlagFormat
      Description copied from class: Flag
      Parse a given input to coerce it to a type compatible with the flag.
      Specified by:
      parseInput in class Flag<StateFlag.State>
      Parameters:
      context - the FlagContext
      Returns:
      The coerced type
      Throws:
      InvalidFlagFormat - Raised if the input is invalid
    • unmarshal

      public StateFlag.State unmarshal(Object o)
      Description copied from class: Flag
      Convert a raw type that was loaded (from a YAML file, for example) into the type that this flag uses.
      Specified by:
      unmarshal in class Flag<StateFlag.State>
      Parameters:
      o - The object
      Returns:
      The unmarshalled type
    • marshal

      public Object marshal(StateFlag.State o)
      Description copied from class: Flag
      Convert the value stored for this flag into a type that can be serialized into YAML.
      Specified by:
      marshal in class Flag<StateFlag.State>
      Parameters:
      o - The object
      Returns:
      The marshalled type
    • test

      public static boolean test(StateFlag.State... states)
      Test whether at least one of the given states is ALLOW but none are set to DENY.
      Parameters:
      states - zero or more states
      Returns:
      true if the condition is matched
    • combine

      @Nullable public static StateFlag.State combine(StateFlag.State... states)
      Combine states, letting DENY override ALLOW and ALLOW override NONE (or null).
      Parameters:
      states - zero or more states
      Returns:
      the new state
    • combine

      @Nullable public static StateFlag.State combine(Collection<StateFlag.State> states)
      Combine states, letting DENY override ALLOW and ALLOW override NONE (or null).
      Parameters:
      states - zero or more states
      Returns:
      the new state
    • allowOrNone

      @Nullable public static StateFlag.State allowOrNone(boolean flag)
      Turn a boolean into either NONE (null) or ALLOW if the boolean is false or true, respectively.
      Parameters:
      flag - a boolean value
      Returns:
      a state
    • denyToNone

      @Nullable public static StateFlag.State denyToNone(StateFlag.State state)
      Turn DENY into NONE (null).
      Parameters:
      state - a state
      Returns:
      a state