Class WorldFlagContainer

    • Constructor Detail

      • WorldFlagContainer

        @Inject
        public WorldFlagContainer​(GlobalWorldFlagContainer parentContainer,
                                  FlagContainer.WorldFlagUpdateHandler worldFlagUpdateHandler)
        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 GlobalWorldFlagContainer (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.
        worldFlagUpdateHandler - Event handler that will be called whenever a world flag is added, removed or updated in this flag container.
    • Method Detail

      • castUnsafe

        public static <V,​T extends WorldFlag<V,​?>> T castUnsafe​(WorldFlag<?,​?> flag)
        Cast a world flag with wildcard parameters into a parametrisized 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

        @Nullable
        public @Nullable FlagContainer getParentContainer()
        Description copied from interface: FlagContainer
        Return the parent container (if the container has a parent)
        Specified by:
        getParentContainer in interface FlagContainer
        Returns:
        Parent container, if it exists
      • removeFlag

        public <V,​T extends WorldFlag<V,​?>> V removeFlag​(T flag)
        Description copied from interface: FlagContainer
        Remove a flag from the container
        Specified by:
        removeFlag in interface FlagContainer
        Parameters:
        flag - Flag to remove
      • getFlag

        public <V,​T extends WorldFlag<V,​?>> T getFlag​(Class<? extends T> flagClass)
        Description copied from interface: FlagContainer
        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.
        Specified by:
        getFlag in interface FlagContainer
        Type Parameters:
        V - Flag value type
        T - Flag type
        Parameters:
        flagClass - Flag class to query for
        Returns:
        Flag instance
      • queryLocal

        @Nullable
        public <V,​T extends WorldFlag<V,​?>> T queryLocal​(Class<?> flagClass)
        Description copied from interface: FlagContainer
        Check for flag existence in this flag container instance.
        Specified by:
        queryLocal in interface FlagContainer
        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​(@NotNull
                              FlagContainer.WorldFlagUpdateHandler worldFlagUpdateHandler)
        Description copied from interface: FlagContainer
        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.
        Specified by:
        subscribe in interface FlagContainer
        Parameters:
        worldFlagUpdateHandler - The update handler which will react to changes.
        See Also:
        World flag update types
      • addUnknownFlag

        public void addUnknownFlag​(String flagName,
                                   String value)
        Description copied from interface: FlagContainer
        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.

        Specified by:
        addUnknownFlag in interface FlagContainer
        Parameters:
        flagName - Flag name
        value - Flag value