Class DeferredRegistry<T extends org.bukkit.Keyed>
java.lang.Object
net.mathias2246.buildmc.util.registry.DeferredRegistry<T>
- All Implemented Interfaces:
Iterable<T>, net.kyori.adventure.key.Keyed, org.bukkit.Registry<T>
public class DeferredRegistry<T extends org.bukkit.Keyed>
extends Object
implements org.bukkit.Registry<T>, net.kyori.adventure.key.Keyed, Iterable<T>
A
DeferredRegistry is an implementation of Bukkit's Registry interface.
A DeferredRegistry stays mutable before all plugins are loaded.
You can change the contents of the registry while BuildMC-Core is un-initialized.
After initializing using initialize();, the register will be made immutable for safety.
- 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 -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddEntries(T... entries) Registers multiple new entries.Registers a new entry under a certain key.voidaddEntryOrThrow(T entry) Registers a new entry under a certain key.voidAdds aTagto this registry, if not initialized.get(@NotNull org.bukkit.NamespacedKey namespacedKey) Gets an entry from the deferred-registry@Nullable org.bukkit.NamespacedKeyGets theNamespacedKeyof aTgetOptional(@NotNull String keyString) Optionally retrieves an entry from this deferred-registry by itsNamespacedKeyin aStringrepresentation.getOptional(@NotNull org.bukkit.NamespacedKey namespacedKey) Optionally retrieves an entry from this deferred-registry by itsNamespacedKey.getOrThrow(@NotNull org.bukkit.NamespacedKey namespacedKey) Gets an entry from the deferred-registry, or throws an exception@NonNull io.papermc.paper.registry.tag.Tag<T> Gets aTagfrom this registry by its key.@NonNull Collection<io.papermc.paper.registry.tag.Tag<T>> getTags()Gets aCollectioncontaining allTags in this registry.booleanChecks if a certainTagKeyis found for this registry.voidInitializes this deferred-registry.booleanChecks if this deferred-registry is already initialized or not.iterator()@NotNull net.kyori.adventure.key.Keykey()@NotNull Stream<org.bukkit.NamespacedKey> voidremoveEntry(@NotNull org.bukkit.NamespacedKey key) Removes an entry this deferred-registryvoidremoveEntryOrThrow(@NotNull org.bukkit.NamespacedKey key) Removes an entry this deferred-registryvoidRemoves aTagfrom this registry, if not initialized.voidRemoves aTagfrom this registry, if not initialized.intsize()stream()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface org.bukkit.Registry
get, get, getKeyOrThrow, getOrThrow, getOrThrow, getTagValues, match
-
Constructor Details
-
DeferredRegistry
public DeferredRegistry(@NotNull @NotNull net.kyori.adventure.key.Key key)
-
-
Method Details
-
isInitialized
@Contract(pure=true) 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
-
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 givenNamespacedKey.
-
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
Registers multiple new entries.Nothing will change when this deferred-registry is initialized.
- Parameters:
entries- The entries 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
@Contract(pure=true) @Nullable public T get(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey) Gets an entry from the deferred-registry- Specified by:
getin interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>- Parameters:
namespacedKey- TheNamespacedKeyof the entry you are trying to retrieve- Returns:
- The entry under the given
NamespacedKeyor null if not found.
-
getKey
-
addTag
Adds aTagto this registry, if not initialized.- Parameters:
tag- TheTagto add
-
removeTag
Removes aTagfrom this registry, if not initialized.- Parameters:
tag- TheTagKeyof the tag to remove
-
removeTag
Removes aTagfrom this registry, if not initialized.- Parameters:
tag- TheTagto remove
-
hasTag
Checks if a certainTagKeyis found for this registry.- Specified by:
hasTagin interfaceorg.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 aTagfrom this registry by its key.- Specified by:
getTagin interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>- Parameters:
tagKey- The key of the tag- Returns:
- A
Taginstance - Throws:
NullPointerException- Thrown when the registry doesn't contain any tag with the key that was given
-
getTags
Gets aCollectioncontaining allTags in this registry.- Specified by:
getTagsin interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>- Returns:
- A
Collectioncontaining allTags in this registry
-
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:
getOrThrowin interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>- Parameters:
namespacedKey- TheNamespacedKeyof the entry you are trying to retrieve- Returns:
- The entry under the given
NamespacedKey. - Throws:
IllegalArgumentException- when no entry is registered under the givenNamespacedKey
-
getOptional
@NotNull public @NotNull Optional<T> getOptional(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey) Optionally retrieves an entry from this deferred-registry by itsNamespacedKey.Usage
This method optionally returns an entry of this deferred-registry.
You could use the returnedOptionallike this:registry.getOptional(NamespacedKey.fromString("my_plugin:foo_entry")) .ifPresent( (entry) -> { entry.doSomething(); // You can do anything here } );- Parameters:
namespacedKey- TheNamespacedKeyof the entry you are trying to retrieve- Returns:
- The
Optionalthat might contain the entry from the given key
-
getOptional
Optionally retrieves an entry from this deferred-registry by itsNamespacedKeyin aStringrepresentation.When using an invalid
Stringrepresentation of aNamespacedKey, an emptyOptionalwill be returned.Usage
This method optionally returns an entry of this deferred-registry.
You could use the returnedOptionallike this:registry.getOptional("my_plugin:foo_entry") .ifPresent( (entry) -> { entry.doSomething(); // You can do anything here } ); -
stream
-
keyStream
-
size
@Contract(pure=true) public int size()- Specified by:
sizein interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>- Returns:
- The amount of entries in this registry
-
iterator
-
key
@Contract(pure=true) @NotNull public @NotNull net.kyori.adventure.key.Key key()- Specified by:
keyin interfacenet.kyori.adventure.key.Keyed- Returns:
- The
Keyof this registry
-