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 2 states: either it is mutable (the initial state), or it is frozen. In its mutable state,
registry entries cannot be queried, and this registry cannot be iterated over, though the JavaRegistry.size() method is still available.
New entries can be registered though, using one of the register methods.
When registering entries, the value of the entry does not have to be known at the time of registering. Registry entries whose value is unknown at the mutable stage are "unbound".
You can freeze a registry by using freeze(IntFunction). When freezing a registry, all unbound entries have
to be bound by the IntFunction passed to the freeze method. During the binding process, you can access registry entries,
but trying to access their value will result in an exception when they're unbound.
Calling clear() will clear this registry and reset it back to its initial state.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears this registry.default voidfreeze()Freezes this registry.voidfreeze(IntFunction<T> binder) Freezes this registry.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 exists
-
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 exists
-
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 exists
-
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 existsNullPointerException- 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 exists
-
clear
void clear()Clears this registry. All entries will be wiped, and the registry will be mutable again, if it was frozen. -
freeze
Freezes this registry. This method uses the givenIntFunctionto 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.- Parameters:
binder- the function used to bind unbound registry entries- Throws:
NullPointerException- when the binder returned null for an ID- See Also:
-
freeze
default void freeze()Freezes this registry. This method will throw when the registry contains unbound registry entries.- Throws:
IllegalStateException- when this registry contains unbound registry entries- See Also:
-