Class RegistriesHolder

java.lang.Object
net.mathias2246.buildmc.util.registry.RegistriesHolder
All Implemented Interfaces:
Iterable<org.bukkit.Registry<? extends org.bukkit.Keyed>>

public class RegistriesHolder extends Object implements Iterable<org.bukkit.Registry<? extends org.bukkit.Keyed>>
A registry-holder stores a collection of Registry instances under a certain key.

BuildMC and Extension plugins should all register static or type instances inside registries of some kind.
Storing certain types in registries allows other plugins to access them and add or remove entries.

Other extension plugins can retrieve the BuildMC registry-holder through the api using api.getRegistriesHolder();

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A Builder class used to create new instances of RegistriesHolders.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends org.bukkit.Keyed>
    @NotNull org.bukkit.Registry<T>
    addRegistry(@NotNull String key, @NotNull org.bukkit.Registry<T> registry)
    Adds a Registry to this holder under a certain key.
    @Nullable org.bukkit.Registry<?>
    get(@NotNull String key)
    Retrieves a Registry instance from this holder by its key.
    <T extends org.bukkit.Keyed>
    @Nullable org.bukkit.Registry<T>
    getAsType(@NotNull String key)
    Retrieves a Registry instance from this holder by its key.
    @NotNull Collection<org.bukkit.Registry<? extends org.bukkit.Keyed>>
     
    <T extends org.bukkit.Keyed>
    @NotNull Optional<org.bukkit.Registry<T>>
    getOptional(@Nullable String key)
    Optionally retrieves a Registry instance from this holder by its key and with a certain type.
    @NotNull Iterator<org.bukkit.Registry<? extends org.bukkit.Keyed>>
     

    Methods inherited from class Object

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

    Methods inherited from interface Iterable

    forEach, spliterator
  • Method Details

    • getCollection

      @NotNull public @NotNull Collection<org.bukkit.Registry<? extends org.bukkit.Keyed>> getCollection()
      Returns:
      A Collection containing all registries in this holder.
    • iterator

      @NotNull public @NotNull Iterator<org.bukkit.Registry<? extends org.bukkit.Keyed>> iterator()
      Specified by:
      iterator in interface Iterable<org.bukkit.Registry<? extends org.bukkit.Keyed>>
    • get

      @Nullable public @Nullable org.bukkit.Registry<?> get(@NotNull @NotNull String key)
      Retrieves a Registry instance from this holder by its key.
      Returns:
      The Registry instance stored under the given key, or null if not existing.
    • getAsType

      @Nullable public <T extends org.bukkit.Keyed> @Nullable org.bukkit.Registry<T> getAsType(@NotNull @NotNull String key)
      Retrieves a Registry instance from this holder by its key.
      Returns:
      The Registry instance stored under the given key, or null if not existing.
    • addRegistry

      @NotNull public <T extends org.bukkit.Keyed> @NotNull org.bukkit.Registry<T> addRegistry(@NotNull @NotNull String key, @NotNull @NotNull org.bukkit.Registry<T> registry)
      Adds a Registry to this holder under a certain key.
      Returns:
      The Registry instance that was passed in as a parameter
    • getOptional

      @NotNull public <T extends org.bukkit.Keyed> @NotNull Optional<org.bukkit.Registry<T>> getOptional(@Nullable @Nullable String key)
      Optionally retrieves a Registry instance from this holder by its key and with a certain type.

      Usage

      This method optionally returns a Registry.
      You could use the returned Optional like this:
       holder.getOptional("some_registry")
            .ifPresent(
                (registry) -> {
                    registry.addEntry(...); // You can do anything here
                }
            );
       
      Returns:
      The Optional that contains the Registry that was found, or null if not