Class DeferredRegistry<T extends org.bukkit.Keyed>

java.lang.Object
net.mathias2246.buildmc.util.DeferredRegistry<T>
All Implemented Interfaces:
Iterable<T>, org.bukkit.Registry<T>

public class DeferredRegistry<T extends org.bukkit.Keyed> extends Object implements org.bukkit.Registry<T>
A DeferredRegistry is an implementation of bukkits Registry interface.

A DeferredRegistry allows you to change the contents of the registry while un-initialized. After initializing using initialize();, the register will be made read-only for safety.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.bukkit.Registry

    org.bukkit.Registry.SimpleRegistry<T extends Enum<T> & org.bukkit.Keyed>
  • Field Summary

    Fields inherited from interface org.bukkit.Registry

    ADVANCEMENT, ART, ATTRIBUTE, BANNER_PATTERN, BIOME, BLOCK, BOSS_BARS, CAT_VARIANT, CHICKEN_VARIANT, COW_VARIANT, DAMAGE_TYPE, EFFECT, ENCHANTMENT, ENTITY_TYPE, FLUID, FROG_VARIANT, GAME_EVENT, INSTRUMENT, ITEM, JUKEBOX_SONG, LOOT_TABLES, MAP_DECORATION_TYPE, MATERIAL, MEMORY_MODULE_TYPE, MENU, PARTICLE_TYPE, PIG_VARIANT, POTION, SOUNDS, STATISTIC, STRUCTURE, STRUCTURE_TYPE, TRIM_MATERIAL, TRIM_PATTERN, VILLAGER_PROFESSION, VILLAGER_TYPE, WOLF_VARIANT
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    addEntries(T... entries)
    Registers multiple new entries.
    void
    addEntry(T entry)
    Registers a new entry under a certain key.
    void
    Registers a new entry under a certain key.
    get(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Gets an entry from the deferred-registry
    @NotNull Optional<T>
    getOptional(@NotNull String keyString)
    Optionally retrieves an entry from this deferred-registry by its NamespacedKey in a String representation.
    @NotNull Optional<T>
    getOptional(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Optionally retrieves an entry from this deferred-registry by its NamespacedKey.
    getOrThrow(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Gets an entry from the deferred-registry, or throws an exception
    void
    Initializes this deferred-registry.
    boolean
    Checks if this deferred-registry is already initialized or not.
    @NotNull Iterator<T>
     
    @NotNull Stream<org.bukkit.NamespacedKey>
     
    void
    removeEntry(@NotNull org.bukkit.NamespacedKey key)
    Removes an entry this deferred-registry
    void
    removeEntryOrThrow(@NotNull org.bukkit.NamespacedKey key)
    Removes an entry this deferred-registry
    @NotNull Stream<T>
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface org.bukkit.Registry

    match
  • Constructor Details

    • DeferredRegistry

      public DeferredRegistry()
  • Method Details

    • isInitialized

      public boolean isInitialized()
      Checks if this deferred-registry is already initialized or not.

      Important

      When this deferred-registry is initialized, it will be turned immutable for safety.
      Returns:
      True if this deferred-registry instance is initialized.
    • initialize

      public void initialize()
      Initializes this deferred-registry.

      Important

      When this deferred-registry is initialized, it will be turned immutable for safety.
    • addEntry

      public void addEntry(@NotNull T entry)
      Registers a new entry under a certain key.

      Nothing will change when this deferred-registry is initialized.

      Parameters:
      entry - The entry to add
    • removeEntryOrThrow

      public void removeEntryOrThrow(@NotNull @NotNull org.bukkit.NamespacedKey key) throws IllegalStateException, IllegalArgumentException
      Removes an entry this deferred-registry
      Parameters:
      key - The key of the entry to remove
      Throws:
      IllegalStateException - If this deferred-registry is already initialized.
      IllegalArgumentException - If this deferred-registry does not contain an entry under the given NamespacedKey.
    • removeEntry

      public void removeEntry(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Removes an entry this deferred-registry
      Parameters:
      key - The key of the entry to remove
    • addEntries

      @SafeVarargs public final void addEntries(@NotNull T... entries)
      Registers multiple new entries.

      Nothing will change when this deferred-registry is initialized.

      Parameters:
      entries - The entry to add
    • addEntryOrThrow

      public void addEntryOrThrow(@NotNull T entry) throws IllegalArgumentException, IllegalStateException
      Registers a new entry under a certain key.
      Parameters:
      entry - The entry to add
      Throws:
      IllegalArgumentException - when an entry is already registered under the same key.
      IllegalStateException - when this registry is already initialized
    • get

      @Nullable public T get(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey)
      Gets an entry from the deferred-registry
      Specified by:
      get in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Parameters:
      namespacedKey - The NamespacedKey of the entry you are trying to retrieve
      Returns:
      The entry under the given NamespacedKey or null if not found.
    • getOrThrow

      @NotNull public T getOrThrow(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey) throws IllegalArgumentException
      Gets an entry from the deferred-registry, or throws an exception
      Specified by:
      getOrThrow in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Parameters:
      namespacedKey - The NamespacedKey of the entry you are trying to retrieve
      Returns:
      The entry under the given NamespacedKey.
      Throws:
      IllegalArgumentException - when no entry is registered under the given NamespacedKey
    • getOptional

      @NotNull public @NotNull Optional<T> getOptional(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey)
      Optionally retrieves an entry from this deferred-registry by its NamespacedKey.

      Usage

      This method optionally returns an entry of this deferred-registry.
      You could use the returned Optional like this:
      
       registry.getOptional(NamespacedKey.fromString("my_plugin:foo_entry"))
            .ifPresent(
                (entry) -> {
                    entry.doSomething(); // You can do anything here
                }
            );
       
      Parameters:
      namespacedKey - The NamespacedKey of the entry you are trying to retrieve
      Returns:
      The Optional that might contain the entry from the given key
    • getOptional

      @NotNull public @NotNull Optional<T> getOptional(@NotNull @NotNull String keyString)
      Optionally retrieves an entry from this deferred-registry by its NamespacedKey in a String representation.

      When using an invalid String representation of a NamespacedKey, an empty Optional will be returned.

      Usage

      This method optionally returns an entry of this deferred-registry.
      You could use the returned Optional like this:
      
       registry.getOptional("my_plugin:foo_entry")
            .ifPresent(
                (entry) -> {
                    entry.doSomething(); // You can do anything here
                }
            );
       
      Parameters:
      keyString - The String representation of key of the entry you are trying to retrieve
      Returns:
      The Optional that might contain the entry from the given key
    • stream

      @NotNull public @NotNull Stream<T> stream()
      Specified by:
      stream in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Returns:
      A Stream containing all entries of this deferred-registry.
    • keyStream

      @NotNull public @NotNull Stream<org.bukkit.NamespacedKey> keyStream()
      Returns:
      A Stream containing all keys in this deferred-registry.
    • iterator

      @NotNull public @NotNull Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T extends org.bukkit.Keyed>
      Returns:
      An Iterator for iterating over all entries inside this deferred-registry