Record Class JavaRegistryKey<T>
java.lang.Object
java.lang.Record
org.geysermc.geyser.registry.java.JavaRegistryKey<T>
- Type Parameters:
T- the type of this registry- Record Components:
registryKey- theKeyof this registry
This record is essentially a wrapper around a
Key for a Java registry, be it built-in or networked, as defined in JavaRegistries.
The purpose of this record is to provide a static reference to a registry, as well as to add a generic JavaRegistryKey-variable to the Key,
though this record also provides shorthand methods for accessing a registry's contents using a JavaRegistryProvider.
All instances of this record must be kept in JavaRegistries.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionJavaRegistryKey(net.kyori.adventure.key.Key registryKey) Creates an instance of aJavaRegistryKeyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.get(JavaRegistryProvider registries, int networkId) Gets theJavaRegistryKeyfor the givennetworkIdin this registry, or returns an empty optional if it didn't exist.get(JavaRegistryProvider registries, net.kyori.adventure.key.Key key) Gets theJavaRegistryKeyfor the givenkeyin this registry, or returns an empty optional if it didn't exist.getId(JavaRegistryProvider registries, net.kyori.adventure.key.Key key) Gets the network ID for the givenkeyin this registry, or returns an empty optional if it didn't exist.getId(JavaRegistryProvider registries, T object) Gets the network ID for the givenobjectin this registry, or returns an empty optional if it didn't exist.intgetIdOrThrow(JavaRegistryProvider registries, net.kyori.adventure.key.Key key) Gets the network ID for the givenkeyin this registry, or throws if it didn't exist.intgetIdOrThrow(JavaRegistryProvider registries, T object) Gets the network ID for the givenobjectin this registry, or throws if it didn't exist.Optional<net.kyori.adventure.key.Key> getKey(JavaRegistryProvider registries, int networkId) Gets theKeyfor the givennetworkIdin this registry, or returns an empty optional if it didn't exist.Optional<net.kyori.adventure.key.Key> getKey(JavaRegistryProvider registries, T object) Gets theKeyfor the givenobjectin this registry, or returns an empty optional if it didn't exist.net.kyori.adventure.key.KeygetKeyOrThrow(JavaRegistryProvider registries, int networkId) Gets theKeyfor the givennetworkIdin this registry, or throws if it didn't exist.net.kyori.adventure.key.KeygetKeyOrThrow(JavaRegistryProvider registries, T object) Gets theKeyfor the givenobjectin this registry, or throws if it didn't exist.getOrThrow(JavaRegistryProvider registries, int networkId) Gets theJavaRegistryKeyfor the givennetworkIdin this registry, or throws if it didn't exist.getOrThrow(JavaRegistryProvider registries, net.kyori.adventure.key.Key key) Gets theJavaRegistryKeyfor the givenkeyin this registry, or throws if it didn't exist.final inthashCode()Returns a hash code value for this object.net.kyori.adventure.key.KeyReturns the value of theregistryKeyrecord component.resolver(JavaRegistryProvider registries) Returns anIntFunctionthat turns a network ID of this registry into aJavaRegistryKey.resolver(GeyserSession session) Shorthand method forresolver(JavaRegistryProvider).toString()Returns a string representation of this record class.org.geysermc.mcprotocollib.protocol.data.game.Holder<T> wrap(JavaRegistryProvider registries, T object) Tries to get the network ID of the givenobject, wrapping it into aHolderusingHolder.ofId(int).org.geysermc.mcprotocollib.protocol.data.game.Holder<T> wrap(GeyserSession session, T object) Shorthand method forwrap(JavaRegistryProvider, Object).<H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(JavaRegistryProvider registries, net.kyori.adventure.key.Key key) Gets the network ID of the givenkey, and wraps it into aHolderusingHolder.ofId(int).<H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(JavaRegistryProvider registries, T object) Gets the network ID of the givenobject, and wraps it into aHolderusingHolder.ofId(int).<H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(GeyserSession session, net.kyori.adventure.key.Key key) Shorthand method forwrapOrThrow(JavaRegistryProvider, Key).<H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(GeyserSession session, T object) Shorthand method forwrapOrThrow(JavaRegistryProvider, Object).
-
Constructor Details
-
JavaRegistryKey
public JavaRegistryKey(net.kyori.adventure.key.Key registryKey) Creates an instance of aJavaRegistryKeyrecord class.- Parameters:
registryKey- the value for theregistryKeyrecord component
-
-
Method Details
-
getIdOrThrow
Gets the network ID for the givenobjectin this registry, or throws if it didn't exist.- Parameters:
registries- theJavaRegistryProviderobject- the object to look up- Returns:
- the network ID correlating to the object
- Throws:
IllegalStateException- when theobjectwas not present in this registry
-
getId
Gets the network ID for the givenobjectin this registry, or returns an empty optional if it didn't exist.- Parameters:
registries- theJavaRegistryProviderobject- the object to look up- Returns:
- the network ID correlating to the object, or an empty optional if it didn't exist
-
getIdOrThrow
Gets the network ID for the givenkeyin this registry, or throws if it didn't exist.- Parameters:
registries- theJavaRegistryProviderkey- the key to look up- Returns:
- the network ID correlating to the key
- Throws:
IllegalStateException- when thekeywas not present in this registry
-
getId
Gets the network ID for the givenkeyin this registry, or returns an empty optional if it didn't exist.- Parameters:
registries- theJavaRegistryProviderkey- the key to look up- Returns:
- the network ID correlating to the key, or an empty optional if it didn't exist
-
getKeyOrThrow
Gets theKeyfor the givenobjectin this registry, or throws if it didn't exist.- Parameters:
registries- theJavaRegistryProviderobject- the object to look up- Returns:
- the
Keycorrelating to the object - Throws:
IllegalStateException- when theobjectwas not present in this registry
-
getKey
Gets theKeyfor the givenobjectin this registry, or returns an empty optional if it didn't exist.- Parameters:
registries- theJavaRegistryProviderobject- the object to look up- Returns:
- the
Keycorrelating to the object, or an empty optional if it didn't exist
-
getKeyOrThrow
Gets theKeyfor the givennetworkIdin this registry, or throws if it didn't exist.- Parameters:
registries- theJavaRegistryProvidernetworkId- the network ID to look up- Returns:
- the
Keycorrelating to the network ID - Throws:
IllegalStateException- when thenetworkIdwas not present in this registry
-
getKey
Gets theKeyfor the givennetworkIdin this registry, or returns an empty optional if it didn't exist.- Parameters:
registries- theJavaRegistryProvidernetworkId- the network ID to look up- Returns:
- the
Keycorrelating to the network ID, or an empty optional if it didn't exist
-
getOrThrow
Gets theJavaRegistryKeyfor the givennetworkIdin this registry, or throws if it didn't exist.- Parameters:
registries- theJavaRegistryProvidernetworkId- the network ID to look up- Returns:
- the
JavaRegistryKeycorrelating to the network ID - Throws:
IllegalStateException- when thenetworkIdwas not present in this registry
-
get
Gets theJavaRegistryKeyfor the givennetworkIdin this registry, or returns an empty optional if it didn't exist.- Parameters:
registries- theJavaRegistryProvidernetworkId- the network ID to look up- Returns:
- the
JavaRegistryKeycorrelating to the network ID, or an empty optional if it didn't exist
-
getOrThrow
Gets theJavaRegistryKeyfor the givenkeyin this registry, or throws if it didn't exist.- Parameters:
registries- theJavaRegistryProviderkey- the key to look up- Returns:
- the
JavaRegistryKeycorrelating to the key - Throws:
IllegalStateException- when thekeywas not present in this registry
-
get
Gets theJavaRegistryKeyfor the givenkeyin this registry, or returns an empty optional if it didn't exist.- Parameters:
registries- theJavaRegistryProviderkey- the key to look up- Returns:
- the
JavaRegistryKeycorrelating to the key, or an empty optional if it didn't exist
-
resolver
Shorthand method forresolver(JavaRegistryProvider).- Parameters:
session- theGeyserSession- Returns:
- an
IntFunctionthat turns a network ID of this registry into aJavaRegistryKey - See Also:
-
resolver
Returns anIntFunctionthat turns a network ID of this registry into aJavaRegistryKey. Useful to combine withHolder.getOrCompute(IntFunction).Note that the returned function will use
getOrThrow(JavaRegistryProvider, int)and as such throw anIllegalStateExceptionon missing IDs.- Parameters:
registries- theJavaRegistryProvider- Returns:
- an
IntFunctionthat turns a network ID of this registry into aJavaRegistryKey
-
wrapOrThrow
public <H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(GeyserSession session, net.kyori.adventure.key.Key key) Shorthand method forwrapOrThrow(JavaRegistryProvider, Key).- Type Parameters:
H- the type of the holder- Parameters:
session- theGeyserSessionkey- the key to wrap into aHolder- Returns:
- a holder representing the key
- Throws:
IllegalStateException- when thekeywas not present in this registry- See Also:
-
wrapOrThrow
public <H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(JavaRegistryProvider registries, net.kyori.adventure.key.Key key) Gets the network ID of the givenkey, and wraps it into aHolderusingHolder.ofId(int).- Type Parameters:
H- the type of the holder- Parameters:
registries- theJavaRegistryProviderkey- the key to wrap into aHolder- Returns:
- a holder representing the key
- Throws:
IllegalStateException- when thekeywas not present in this registry- See Also:
-
wrapOrThrow
public <H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(GeyserSession session, T object) Shorthand method forwrapOrThrow(JavaRegistryProvider, Object).- Type Parameters:
H- the type of the holder- Parameters:
session- theGeyserSessionobject- the object to wrap into aHolder- Returns:
- a holder representing the object
- Throws:
IllegalStateException- when theobjectwas not present in this registry- See Also:
-
wrapOrThrow
public <H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(JavaRegistryProvider registries, T object) Gets the network ID of the givenobject, and wraps it into aHolderusingHolder.ofId(int).- Type Parameters:
H- the type of the holder- Parameters:
registries- theJavaRegistryProviderobject- the object to wrap into aHolder- Returns:
- a holder representing the object
- Throws:
IllegalStateException- when theobjectwas not present in this registry- See Also:
-
wrap
public org.geysermc.mcprotocollib.protocol.data.game.Holder<T> wrap(GeyserSession session, T object) Shorthand method forwrap(JavaRegistryProvider, Object).- Parameters:
session- theGeyserSessionobject- the object to wrap into aHolder- Returns:
- a holder representing the object
-
wrap
public org.geysermc.mcprotocollib.protocol.data.game.Holder<T> wrap(JavaRegistryProvider registries, T object) Tries to get the network ID of the givenobject, wrapping it into aHolderusingHolder.ofId(int). If theobjectwas not present in this registry, then it is wrapped into aHolderusingHolder.ofCustom(Object).- Parameters:
registries- theJavaRegistryProviderobject- the object to wrap into aHolder- Returns:
- a holder representing the object
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
registryKey
public net.kyori.adventure.key.Key registryKey()Returns the value of theregistryKeyrecord component.- Returns:
- the value of the
registryKeyrecord component
-