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 ClassesModifier and TypeClassDescriptionstatic classA Builder class used to create new instances ofRegistriesHolders. -
Method Summary
Modifier and TypeMethodDescription<T extends org.bukkit.Keyed>
@NotNull org.bukkit.Registry<T> addRegistry(@NotNull String key, @NotNull org.bukkit.Registry<T> registry) Adds aRegistryto this holder under a certain key.@Nullable org.bukkit.Registry<?> Retrieves aRegistryinstance from this holder by its key.<T extends org.bukkit.Keyed>
@Nullable org.bukkit.Registry<T> Retrieves aRegistryinstance 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 aRegistryinstance from this holder by its key and with a certain type.@NotNull Iterator<org.bukkit.Registry<? extends org.bukkit.Keyed>> iterator()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
getCollection
@NotNull public @NotNull Collection<org.bukkit.Registry<? extends org.bukkit.Keyed>> getCollection()- Returns:
- A
Collectioncontaining all registries in this holder.
-
iterator
-
get
Retrieves aRegistryinstance from this holder by its key.- Returns:
- The
Registryinstance 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 aRegistryinstance from this holder by its key.- Returns:
- The
Registryinstance 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 aRegistryto this holder under a certain key.- Returns:
- The
Registryinstance 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 aRegistryinstance from this holder by its key and with a certain type.Usage
This method optionally returns aRegistry.
You could use the returnedOptionallike this:holder.getOptional("some_registry") .ifPresent( (registry) -> { registry.addEntry(...); // You can do anything here } );- Returns:
- The
Optionalthat contains theRegistrythat was found, ornullif not
-