Class BaseRegistry<T extends org.bukkit.Keyed>
java.lang.Object
net.mathias2246.buildmc.util.registry.BaseRegistry<T>
- All Implemented Interfaces:
Iterable<T>,org.bukkit.Registry<T>
-
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, GAME_RULE, 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, ZOMBIE_NAUTILUS_VARIANT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddEntries(T... entries) Registers multiple new entries.Registers a new entry under a certain key.voidclear()Removes all the entries from this registry.booleancontains(@NotNull org.bukkit.NamespacedKey namespacedKey) get(@NotNull org.bukkit.NamespacedKey namespacedKey) getOptional(@NotNull String keyString) Optionally retrieves an entry from this registry by itsNamespacedKeyin aStringrepresentation.getOptional(@NotNull org.bukkit.NamespacedKey namespacedKey) Optionally retrieves an entry from this registry by itsNamespacedKey.getOrThrow(@NotNull org.bukkit.NamespacedKey namespacedKey) Gets an entry from this registry, or throws an exceptioniterator()Set<org.bukkit.NamespacedKey> keySet()@NotNull Stream<org.bukkit.NamespacedKey> voidremoveEntry(@NotNull org.bukkit.NamespacedKey key) Removes an entry from the registry.intsize()stream()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
BaseRegistry
public BaseRegistry()
-
-
Method Details
-
removeEntry
public void removeEntry(@NotNull @NotNull org.bukkit.NamespacedKey key) Removes an entry from the registry.- Parameters:
key- TheNamespacedKeyof the entry to remove
-
clear
public void clear()Removes all the entries from this registry. The registry will be empty after this. -
addEntry
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 isnull
-
addEntries
Registers multiple new entries.- Parameters:
entries- The entry to add
-
contains
public boolean contains(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey) -
keySet
-
size
public int size() -
get
- Specified by:
getin interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>
-
getOrThrow
Gets an entry from this 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
-
stream
-
keyStream
- Returns:
- A
Streamcontaining all keys in this registry.
-
iterator
-
match
- Specified by:
matchin interfaceorg.bukkit.Registry<T extends org.bukkit.Keyed>
-
getOptional
@NotNull public @NotNull Optional<T> getOptional(@NotNull @NotNull org.bukkit.NamespacedKey namespacedKey) Optionally retrieves an entry from this registry by itsNamespacedKey.Usage
This method optionally returns an entry of this 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 registry by itsNamespacedKeyin aStringrepresentation.When using an invalid
Stringrepresentation of aNamespacedKey, an emptyOptionalwill be returned.Usage
This method optionally returns an entry of this registry.
You could use the returnedOptionallike this:registry.getOptional("my_plugin:foo_entry") .ifPresent( (entry) -> { entry.doSomething(); // You can do anything here } );
-