Interface MutableJavaRegistry<T>
- Type Parameters:
T- the type of the registry
- All Superinterfaces:
Iterable<T>,JavaRegistry<T>,JavaRegistryLookup<T>
- All Known Implementing Classes:
SimpleJavaRegistry
JavaRegistry that accepts new entries, unless it is frozen.
This registry can be in one of 3 states, in the following order:
- In its initial state, it is mutable. New entries can be registered, but entries cannot be queried, and the registry cannot be iterated over.
JavaRegistry.size()is still available, however. The value of a registry entry does not have to be known at the time of registering: it is fine to register an entry only by itsnetworkIdandKey. This can be useful when needing to refer to other registries during the binding step (see state 3). - Once all entries are registered, the registry must be frozen, by calling
freeze(). After freezing the registry, entries can no longer be registered. Entries can be queried however, and if all entries were "known" at the time of registering, this registry automatically considers itself bound. - If not all entries were "known" at the time of registering, a registry must be bound by calling
bind(IntFunction). After the registry has been bound, it is fully functional. To reset the registry back to its initial, mutable state, callclear().
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidbind(IntFunction<T> binder) Binds this registry, if there were any unbound entries.voidclear()Clears this registry.voidfreeze()Freezes this registry, if it was not frozen already.default voidregister(int id, net.kyori.adventure.key.Key key) Adds a new entry to this registry under the givenidandkey.default <V extends T>
Vregister(int id, net.kyori.adventure.key.Key key, V value) Adds a new entry to this register under the givenidandkey.default voidregister(net.kyori.adventure.key.Key key) Adds a new entry to this registry under the givenkey.default <V extends T>
Vregister(net.kyori.adventure.key.Key key, V value) Adds a new entry to this registry under the givenkey.voidregister(RegistryEntryData<T> entry) Adds a new entry to this registry.Methods inherited from interface org.geysermc.geyser.registry.java.JavaRegistry
forEachEntry, isEmpty, keys, parallelStream, size, spliterator, streamMethods inherited from interface org.geysermc.geyser.registry.java.JavaRegistryLookup
get, get, getById, getByKey, getByValue, getId, getId, getIdOrThrow, getIdOrThrow, getKey, getKey, getKeyOrThrow, getKeyOrThrow, getOrThrow, getOrThrow
-
Method Details
-
register
default void register(net.kyori.adventure.key.Key key) Adds a new entry to this registry under the givenkey. The network ID of this entry is set to the current size of the registry, and the entry will be unbound.- Parameters:
key- the key to register the new entry under- Throws:
IllegalStateException- when an entry with this network ID or key already existsIllegalStateException- when the registry was frozen
-
register
default void register(int id, net.kyori.adventure.key.Key key) Adds a new entry to this registry under the givenidandkey. The entry will be unbound.- Parameters:
id- the network ID to register the new entry underkey- the key to register the new entry under- Throws:
IllegalStateException- when an entry with this network ID or key already existsIllegalStateException- when the registry was frozen
-
register
Adds a new entry to this registry under the givenkey. The network ID of this entry is set to the current size of the registry.- Type Parameters:
V- the type of the new entry- Parameters:
key- the key to register the new entry undervalue- the value of the new entry- Returns:
- the value of the new entry
- Throws:
IllegalStateException- when an entry with this network ID or key already existsIllegalStateException- when the registry was frozen
-
register
Adds a new entry to this register under the givenidandkey.- Type Parameters:
V- the type of the new entry- Parameters:
id- the network ID to register the new entry underkey- the key to register the new entry undervalue- the value of the new entry- Returns:
- the value of the new entry
- Throws:
IllegalStateException- when an entry with this network ID or key already existsIllegalStateException- when the registry was frozenNullPointerException- when thevaluewas null
-
register
Adds a new entry to this registry.- Parameters:
entry- the entry to add- Throws:
IllegalStateException- when an entry with this network ID or key already existsIllegalStateException- when the registry was frozen
-
clear
void clear()Clears this registry. All entries will be wiped, and the registry will be mutable again, if it was frozen. -
freeze
void freeze()Freezes this registry, if it was not frozen already.If all entries were bound at the time of registering, then
bind(IntFunction)is automatically called with a no-op binder, ensuring this registry is bound and fully functional.If the registry was already frozen, this method does nothing.
- See Also:
-
bind
Binds this registry, if there were any unbound entries. The registry must be frozen before binding it.This method uses the given
IntFunctionto bind all unbound registry entries. As a result, after calling this method, all registry entries should be bound.The
IntFunctionis given a network ID, and it is expected to return aMutableJavaRegistryfor that respective network ID. If it returnsnull, aNullPointerExceptionis thrown.If the registry was already bound, this method does nothing. If the binder throws a
RuntimeException, the exception will be caught, and this method will silently return. The registry will be left unbound.- Parameters:
binder- the function used to bind unbound registry entries- Throws:
IllegalStateException- when the registry is not frozenNullPointerException- when the binder returned null for an ID- See Also:
-