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 - the Key of this registry

public record JavaRegistryKey<T>(net.kyori.adventure.key.Key registryKey) extends Record
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 Details

    • JavaRegistryKey

      public JavaRegistryKey(net.kyori.adventure.key.Key registryKey)
      Creates an instance of a JavaRegistryKey record class.
      Parameters:
      registryKey - the value for the registryKey record component
  • Method Details

    • getIdOrThrow

      public int getIdOrThrow(JavaRegistryProvider registries, T object)
      Gets the network ID for the given object in this registry, or throws if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to look up
      Returns:
      the network ID correlating to the object
      Throws:
      IllegalStateException - when the object was not present in this registry
    • getId

      public OptionalInt getId(JavaRegistryProvider registries, T object)
      Gets the network ID for the given object in this registry, or returns an empty optional if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to look up
      Returns:
      the network ID correlating to the object, or an empty optional if it didn't exist
    • getIdOrThrow

      public int getIdOrThrow(JavaRegistryProvider registries, net.kyori.adventure.key.Key key)
      Gets the network ID for the given key in this registry, or throws if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      key - the key to look up
      Returns:
      the network ID correlating to the key
      Throws:
      IllegalStateException - when the key was not present in this registry
    • getId

      public OptionalInt getId(JavaRegistryProvider registries, net.kyori.adventure.key.Key key)
      Gets the network ID for the given key in this registry, or returns an empty optional if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      key - the key to look up
      Returns:
      the network ID correlating to the key, or an empty optional if it didn't exist
    • getKeyOrThrow

      public net.kyori.adventure.key.Key getKeyOrThrow(JavaRegistryProvider registries, T object)
      Gets the Key for the given object in this registry, or throws if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to look up
      Returns:
      the Key correlating to the object
      Throws:
      IllegalStateException - when the object was not present in this registry
    • getKey

      public Optional<net.kyori.adventure.key.Key> getKey(JavaRegistryProvider registries, T object)
      Gets the Key for the given object in this registry, or returns an empty optional if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to look up
      Returns:
      the Key correlating to the object, or an empty optional if it didn't exist
    • getKeyOrThrow

      public net.kyori.adventure.key.Key getKeyOrThrow(JavaRegistryProvider registries, int networkId)
      Gets the Key for the given networkId in this registry, or throws if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      networkId - the network ID to look up
      Returns:
      the Key correlating to the network ID
      Throws:
      IllegalStateException - when the networkId was not present in this registry
    • getKey

      public Optional<net.kyori.adventure.key.Key> getKey(JavaRegistryProvider registries, int networkId)
      Gets the Key for the given networkId in this registry, or returns an empty optional if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      networkId - the network ID to look up
      Returns:
      the Key correlating to the network ID, or an empty optional if it didn't exist
    • getOrThrow

      public T getOrThrow(JavaRegistryProvider registries, int networkId)
      Gets the JavaRegistryKey for the given networkId in this registry, or throws if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      networkId - the network ID to look up
      Returns:
      the JavaRegistryKey correlating to the network ID
      Throws:
      IllegalStateException - when the networkId was not present in this registry
    • get

      public Optional<T> get(JavaRegistryProvider registries, int networkId)
      Gets the JavaRegistryKey for the given networkId in this registry, or returns an empty optional if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      networkId - the network ID to look up
      Returns:
      the JavaRegistryKey correlating to the network ID, or an empty optional if it didn't exist
    • getOrThrow

      public T getOrThrow(JavaRegistryProvider registries, net.kyori.adventure.key.Key key)
      Gets the JavaRegistryKey for the given key in this registry, or throws if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      key - the key to look up
      Returns:
      the JavaRegistryKey correlating to the key
      Throws:
      IllegalStateException - when the key was not present in this registry
    • get

      public Optional<T> get(JavaRegistryProvider registries, net.kyori.adventure.key.Key key)
      Gets the JavaRegistryKey for the given key in this registry, or returns an empty optional if it didn't exist.
      Parameters:
      registries - the JavaRegistryProvider
      key - the key to look up
      Returns:
      the JavaRegistryKey correlating to the key, or an empty optional if it didn't exist
    • resolver

      public IntFunction<T> resolver(GeyserSession session)
      Shorthand method for resolver(JavaRegistryProvider).
      Parameters:
      session - the GeyserSession
      Returns:
      an IntFunction that turns a network ID of this registry into a JavaRegistryKey
      See Also:
    • resolver

      public IntFunction<T> resolver(JavaRegistryProvider registries)
      Returns an IntFunction that turns a network ID of this registry into a JavaRegistryKey. Useful to combine with Holder.getOrCompute(IntFunction).

      Note that the returned function will use getOrThrow(JavaRegistryProvider, int) and as such throw an IllegalStateException on missing IDs.

      Parameters:
      registries - the JavaRegistryProvider
      Returns:
      an IntFunction that turns a network ID of this registry into a JavaRegistryKey
    • wrapOrThrow

      public <H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(GeyserSession session, net.kyori.adventure.key.Key key)
      Type Parameters:
      H - the type of the holder
      Parameters:
      session - the GeyserSession
      key - the key to wrap into a Holder
      Returns:
      a holder representing the key
      Throws:
      IllegalStateException - when the key was 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 given key, and wraps it into a Holder using Holder.ofId(int).
      Type Parameters:
      H - the type of the holder
      Parameters:
      registries - the JavaRegistryProvider
      key - the key to wrap into a Holder
      Returns:
      a holder representing the key
      Throws:
      IllegalStateException - when the key was not present in this registry
      See Also:
    • wrapOrThrow

      public <H> org.geysermc.mcprotocollib.protocol.data.game.Holder<H> wrapOrThrow(GeyserSession session, T object)
      Type Parameters:
      H - the type of the holder
      Parameters:
      session - the GeyserSession
      object - the object to wrap into a Holder
      Returns:
      a holder representing the object
      Throws:
      IllegalStateException - when the object was 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 given object, and wraps it into a Holder using Holder.ofId(int).
      Type Parameters:
      H - the type of the holder
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to wrap into a Holder
      Returns:
      a holder representing the object
      Throws:
      IllegalStateException - when the object was not present in this registry
      See Also:
    • wrap

      public org.geysermc.mcprotocollib.protocol.data.game.Holder<T> wrap(GeyserSession session, T object)
      Parameters:
      session - the GeyserSession
      object - the object to wrap into a Holder
      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 given object, wrapping it into a Holder using Holder.ofId(int). If the object was not present in this registry, then it is wrapped into a Holder using Holder.ofCustom(Object).
      Parameters:
      registries - the JavaRegistryProvider
      object - the object to wrap into a Holder
      Returns:
      a holder representing the object
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • registryKey

      public net.kyori.adventure.key.Key registryKey()
      Returns the value of the registryKey record component.
      Returns:
      the value of the registryKey record component