Package com.plotsquared.core.plot.flag
Class FlagContainer
java.lang.Object
com.plotsquared.core.plot.flag.FlagContainer
- Direct Known Subclasses:
GlobalFlagContainer
Container type for
plot flags
.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Handler for update events inflag containers
.static enum
Update event types used inFlagContainer.PlotFlagUpdateHandler
. -
Constructor Summary
ConstructorDescriptionFlagContainer
(@Nullable FlagContainer parentContainer) Construct a new flag container with an optional parent container.FlagContainer
(@Nullable FlagContainer parentContainer, @Nullable FlagContainer.PlotFlagUpdateHandler plotFlagUpdateHandler) Construct a new flag container with an optional parent container and update handler. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAll
(FlagContainer container) void
addAll
(Collection<PlotFlag<?, ?>> flags) Add all flags to the container<V,
T extends PlotFlag<V, ?>>
voidaddFlag
(T flag) Add a flag to the containervoid
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).protected boolean
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.static <V,
T extends PlotFlag<V, ?>>
TcastUnsafe
(PlotFlag<?, ?> flag) Cast a plot flag with wildcard parameters into a parametrized PlotFlag.void
Clears the local flag mapCreates a cleanup hook that is meant to run once this FlagContainer isn't needed anymore.boolean
<V,
T extends PlotFlag<V, ?>>
TQuery all levels of flag containers for a flag.PlotFlag<?,
?> getFlagErased
(Class<?> flagClass) Has the same functionality asgetFlag(Class)
, but with wildcard generic types.Get an immutable view of the underlying flag mapfinal FlagContainer
Recursively seek for the highest order flag container.Return the parent container (if the container has a parent)Collection<PlotFlag<?,
?>> Get a collection of all recognized plot flags.int
hashCode()
queryLocal
(Class<?> flagClass) Check for flag existence in this flag container instance.<V,
T extends PlotFlag<V, ?>>
VremoveFlag
(T flag) Remove a flag from the containervoid
setParentContainer
(FlagContainer parentContainer) void
subscribe
(@NonNull FlagContainer.PlotFlagUpdateHandler plotFlagUpdateHandler) Subscribe to flag updates in this particular flag container instance.
-
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 theGlobalFlagContainer
(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
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 theGlobalFlagContainer
(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
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 typeT
- 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
-
getInternalPlotFlagMap
-
getFlagMap
Get an immutable view of the underlying flag map- Returns:
- Immutable flag map
-
addFlag
Add a flag to the containerUse
addAll(Collection)
to add multiple flags.- Type Parameters:
T
- flag typeV
- flag value type- Parameters:
flag
- Flag to add
-
removeFlag
Remove a flag from the container- Type Parameters:
T
- flag typeV
- flag value type- Parameters:
flag
- Flag to remove- Returns:
- value of flag removed
-
addAll
Add all flags to the containerUse
addFlag(PlotFlag)
to add a single flag.- Parameters:
flags
- Flags to add
-
addAll
-
clearLocal
Clears the local flag map -
getRecognizedPlotFlags
Get a collection of all recognized plot flags. Will by default use the values contained inGlobalFlagContainer
.- Returns:
- All recognized flag types
-
getHighestClassContainer
Recursively seek for the highest order flag container. This will by default returnGlobalFlagContainer
.- Returns:
- Highest order class container.
-
getFlagErased
Has the same functionality asgetFlag(Class)
, but with wildcard generic types.- Parameters:
flagClass
- ThePlotFlag
class.- Returns:
- the plot flag
-
getFlag
Query all levels of flag containers for a flag. This guarantees that a flag instance is returned, as long as it is registered in theglobal flag container
.- Type Parameters:
V
- Flag value typeT
- Flag type- Parameters:
flagClass
- Flag class to query for- Returns:
- Flag instance
-
queryLocal
Check for flag existence in this flag container instance.- Type Parameters:
V
- Flag value typeT
- Flag type- Parameters:
flagClass
- Flag class to query for- Returns:
- The flag instance, if it exists in this container, else null.
-
subscribe
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
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 namevalue
- 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
-
hashCode
-
canEqual
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.
-