Class BaseRegistry<T extends org.bukkit.Keyed>

java.lang.Object
net.mathias2246.buildmc.util.registry.BaseRegistry<T>
All Implemented Interfaces:
Iterable<T>, net.kyori.adventure.key.Keyed, org.bukkit.Registry<T>

public class BaseRegistry<T extends org.bukkit.Keyed> extends Object implements org.bukkit.Registry<T>, Iterable<T>, net.kyori.adventure.key.Keyed
An implementation of Bukkit's Registry that is permanently mutable.

You have to keep in mind that entries in this registry type can be modified at after plugin initialization.

See Also:
  • Nested Class Summary

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

    org.bukkit.Registry.NotARegistry<A>, org.bukkit.Registry.SimpleRegistry<T>
  • Field Summary

    Fields inherited from interface org.bukkit.Registry

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

    Constructors
    Constructor
    Description
    BaseRegistry(@NotNull net.kyori.adventure.key.Key key)
    Initializes a new empty register
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    addEntries(T... entries)
    Registers multiple new entries.
    addEntry(T entry)
    Registers a new entry under a certain key.
    void
    addTag(@NonNull io.papermc.paper.registry.tag.Tag<T> tag)
    Adds a Tag to this registry.
    void
    Removes all the entries from this registry.
    boolean
    contains(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Checks if the given NamespacedKey is inside this registry or not.
    get(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Gets an entry from the deferred-registry
    org.bukkit.NamespacedKey
    getKey(T t)
    Gets the NamespacedKey of a T
    @NotNull Optional<T>
    getOptional(@NotNull String keyString)
    Optionally retrieves an entry from this registry by its NamespacedKey in a String representation.
    @NotNull Optional<T>
    getOptional(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Optionally retrieves an entry from this registry by its NamespacedKey.
    getOrThrow(@NotNull org.bukkit.NamespacedKey namespacedKey)
    Gets an entry from this registry, or throws an exception
    @NonNull io.papermc.paper.registry.tag.Tag<T>
    getTag(@NonNull io.papermc.paper.registry.tag.TagKey<T> tagKey)
    Gets a Tag from this registry by its key.
    @NonNull Collection<io.papermc.paper.registry.tag.Tag<T>>
    Gets a Collection containing all Tags in this registry.
    boolean
    hasTag(@NonNull io.papermc.paper.registry.tag.TagKey<T> tagKey)
    Checks if a certain TagKey is found for this registry.
    @NotNull Iterator<T>
     
    @NotNull net.kyori.adventure.key.Key
    key()
     
    Set<org.bukkit.NamespacedKey>
     
    @NotNull Stream<org.bukkit.NamespacedKey>
     
    void
    removeEntry(@NotNull org.bukkit.NamespacedKey key)
    Removes an entry from the registry.
    void
    removeTag(@NonNull io.papermc.paper.registry.tag.Tag<T> tag)
    Removes a Tag from this registry.
    void
    removeTag(@NonNull io.papermc.paper.registry.tag.TagKey<T> tag)
    Removes a Tag from this registry.
    int
     
    @NotNull Stream<T>
     

    Methods inherited from class Object

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

    Methods inherited from interface Iterable

    forEach, spliterator

    Methods inherited from interface org.bukkit.Registry

    get, get, getKeyOrThrow, getOrThrow, getOrThrow, getTagValues, match
  • Constructor Details

    • BaseRegistry

      public BaseRegistry(@NotNull @NotNull net.kyori.adventure.key.Key key)
      Initializes a new empty register
  • Method Details

    • removeEntry

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

      public void clear()
      Removes all the entries from this registry. The registry will be empty after this.
    • addEntry

      @NotNull public T addEntry(@NotNull T entry)
      Registers a new entry under a certain key.
      Parameters:
      entry - The entry to add
      Returns:
      The entry you tried to add
      Throws:
      NullPointerException - if the key is null
    • addEntries

      @SafeVarargs public final void addEntries(@NotNull T... entries)
      Registers multiple new entries.
      Parameters:
      entries - The entry to add
    • contains

      @Contract(pure=true) public boolean contains(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey)
      Checks if the given NamespacedKey is inside this registry or not.
      Returns:
      true if, registry contains key; else false
    • keySet

      public Set<org.bukkit.NamespacedKey> keySet()
      Returns:
      Set with all keys in this registry
    • size

      @Contract(pure=true) public int size()
      Specified by:
      size in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Returns:
      The amount of entries in this registry
    • 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.
    • getKey

      @Contract(pure=true) public org.bukkit.NamespacedKey getKey(@NotNull T t)
      Gets the NamespacedKey of a T
      Specified by:
      getKey in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Parameters:
      t - The object to check
      Returns:
      The NamespacedKey of the object, or null if the parameter is null
    • addTag

      public void addTag(@NonNull io.papermc.paper.registry.tag.Tag<T> tag)
      Adds a Tag to this registry.
      Parameters:
      tag - The Tag to add
    • removeTag

      public void removeTag(@NonNull io.papermc.paper.registry.tag.TagKey<T> tag)
      Removes a Tag from this registry.
      Parameters:
      tag - The TagKey of the tag to remove
    • removeTag

      public void removeTag(@NonNull io.papermc.paper.registry.tag.Tag<T> tag)
      Removes a Tag from this registry.
      Parameters:
      tag - The Tag to remove
    • hasTag

      @Contract(pure=true) public boolean hasTag(@NonNull io.papermc.paper.registry.tag.TagKey<T> tagKey)
      Checks if a certain TagKey is found for this registry.
      Specified by:
      hasTag in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Parameters:
      tagKey - The key to check for
      Returns:
      True if the tag key was found; Otherwise false
    • getTag

      public @NonNull io.papermc.paper.registry.tag.Tag<T> getTag(@NonNull io.papermc.paper.registry.tag.TagKey<T> tagKey)
      Gets a Tag from this registry by its key.
      Specified by:
      getTag in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Parameters:
      tagKey - The key of the tag
      Returns:
      A Tag instance
      Throws:
      NullPointerException - Thrown when the registry doesn't contain any tag with the key that was given
    • getTags

      public @NonNull Collection<io.papermc.paper.registry.tag.Tag<T>> getTags()
      Gets a Collection containing all Tags in this registry.
      Specified by:
      getTags in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Returns:
      A Collection containing all Tags in this registry
    • getOrThrow

      @NotNull public T getOrThrow(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey)
      Gets an entry from this 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
    • 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 registry.
    • keyStream

      @NotNull public @NotNull Stream<org.bukkit.NamespacedKey> keyStream()
      Specified by:
      keyStream in interface org.bukkit.Registry<T extends org.bukkit.Keyed>
      Returns:
      A Stream containing all keys in this 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 registry
    • getOptional

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

      Usage

      This method optionally returns an entry of this 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 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 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
    • key

      @Contract(pure=true) @NotNull public @NotNull net.kyori.adventure.key.Key key()
      Specified by:
      key in interface net.kyori.adventure.key.Keyed
      Returns:
      The Key of this registry