Class FlagContainer

java.lang.Object
com.plotsquared.core.plot.flag.FlagContainer
Direct Known Subclasses:
GlobalFlagContainer

public class FlagContainer extends Object
Container type for plot flags.
  • Constructor Details

    • FlagContainer

      public FlagContainer(@Nullable FlagContainer parentContainer, @Nullable FlagContainer.PlotFlagUpdateHandler plotFlagUpdateHandler)
      Construct a new flag container with an optional parent container and update handler. Default values are inherited from the parent container. At the top of the parent-child hierarchy must be the GlobalFlagContainer (or an equivalent top level flag container).
      Parameters:
      parentContainer - Parent container. The top level flag container should not have a parent, and can set this parameter to null. If this is not a top level flag container, the parent should not be null.
      plotFlagUpdateHandler - Event handler that will be called whenever a plot flag is added, removed or updated in this flag container.
    • FlagContainer

      public FlagContainer(@Nullable FlagContainer parentContainer)
      Construct a new flag container with an optional parent container. Default values are inherited from the parent container. At the top of the parent-child hierarchy must be the GlobalFlagContainer (or an equivalent top level flag container).
      Parameters:
      parentContainer - Parent container. The top level flag container should not have a parent, and can set this parameter to null. If this is not a top level flag container, the parent should not be null.
  • Method Details

    • castUnsafe

      public static <V, T extends PlotFlag<V, ?>> T castUnsafe(PlotFlag<?,?> flag)
      Cast a plot flag with wildcard parameters into a parametrized PlotFlag. This is an unsafe operation, and should only be performed if the generic parameters are known beforehand.
      Type Parameters:
      V - Flag value type
      T - Flag type
      Parameters:
      flag - Flag instance
      Returns:
      Casted flag
    • getParentContainer

      Return the parent container (if the container has a parent)
      Returns:
      Parent container, if it exists
    • setParentContainer

      public void setParentContainer(FlagContainer parentContainer)
    • getInternalPlotFlagMap

      protected Map<Class<?>,PlotFlag<?,?>> getInternalPlotFlagMap()
    • getFlagMap

      public Map<Class<?>,PlotFlag<?,?>> getFlagMap()
      Get an immutable view of the underlying flag map
      Returns:
      Immutable flag map
    • addFlag

      public <V, T extends PlotFlag<V, ?>> void addFlag(T flag)
      Add a flag to the container

      Use addAll(Collection) to add multiple flags.

      Type Parameters:
      T - flag type
      V - flag value type
      Parameters:
      flag - Flag to add
    • removeFlag

      public <V, T extends PlotFlag<V, ?>> V removeFlag(T flag)
      Remove a flag from the container
      Type Parameters:
      T - flag type
      V - flag value type
      Parameters:
      flag - Flag to remove
      Returns:
      value of flag removed
    • addAll

      public void addAll(Collection<PlotFlag<?,?>> flags)
      Add all flags to the container

      Use addFlag(PlotFlag) to add a single flag.

      Parameters:
      flags - Flags to add
    • addAll

      public void addAll(FlagContainer container)
    • clearLocal

      public void clearLocal()
      Clears the local flag map
    • getRecognizedPlotFlags

      Get a collection of all recognized plot flags. Will by default use the values contained in GlobalFlagContainer.
      Returns:
      All recognized flag types
    • getHighestClassContainer

      Recursively seek for the highest order flag container. This will by default return GlobalFlagContainer.
      Returns:
      Highest order class container.
    • getFlagErased

      public PlotFlag<?,?> getFlagErased(Class<?> flagClass)
      Has the same functionality as getFlag(Class), but with wildcard generic types.
      Parameters:
      flagClass - The PlotFlag class.
      Returns:
      the plot flag
    • getFlag

      public <V, T extends PlotFlag<V, ?>> T getFlag(Class<? extends T> flagClass)
      Query all levels of flag containers for a flag. This guarantees that a flag instance is returned, as long as it is registered in the global flag container.
      Type Parameters:
      V - Flag value type
      T - Flag type
      Parameters:
      flagClass - Flag class to query for
      Returns:
      Flag instance
    • queryLocal

      public <V, T extends PlotFlag<V, ?>> @Nullable T queryLocal(Class<?> flagClass)
      Check for flag existence in this flag container instance.
      Type Parameters:
      V - Flag value type
      T - Flag type
      Parameters:
      flagClass - Flag class to query for
      Returns:
      The flag instance, if it exists in this container, else null.
    • subscribe

      public void subscribe(@NonNull FlagContainer.PlotFlagUpdateHandler plotFlagUpdateHandler)
      Subscribe to flag updates in this particular flag container instance. Updates are: a flag being removed, a flag being added or a flag being updated.

      Use FlagContainer.PlotFlagUpdateType to see the update types available.

      Parameters:
      plotFlagUpdateHandler - The update handler which will react to changes.
    • addUnknownFlag

      public void addUnknownFlag(String flagName, String value)
      Register a flag key-value pair which cannot yet be associated with an existing flag instance (such as when third party flag values are loaded before the flag type has been registered).

      These values will be registered in the flag container if the associated flag type is registered in the top level flag container.

      Parameters:
      flagName - Flag name
      value - Flag value
    • createCleanupHook

      Creates a cleanup hook that is meant to run once this FlagContainer isn't needed anymore. This is to prevent memory leaks. This method is not part of the API.
      Returns:
      a new Runnable that cleans up once the FlagContainer isn't needed anymore.
      Since:
      6.0.10
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • canEqual

      @Deprecated(forRemoval=true, since="6.6.0") protected boolean canEqual(Object other)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method is not meant to be invoked or overridden, with no replacement.