Interface MutableJavaRegistry<T>

Type Parameters:
T - the type of the registry
All Superinterfaces:
Iterable<T>, JavaRegistry<T>, JavaRegistryLookup<T>
All Known Implementing Classes:
SimpleJavaRegistry

public interface MutableJavaRegistry<T> extends JavaRegistry<T>
A JavaRegistry that accepts new entries, unless it is frozen.

This registry can be in one of 3 states, in the following order:

  1. 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 its networkId and Key. This can be useful when needing to refer to other registries during the binding step (see state 3).
  2. 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.
  3. 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, call clear().
See Also:
  • Method Details

    • register

      default void register(net.kyori.adventure.key.Key key)
      Adds a new entry to this registry under the given key. 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
      IllegalStateException - 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 given id and key. The entry will be unbound.
      Parameters:
      id - the network ID to register the new entry under
      key - the key to register the new entry under
      Throws:
      IllegalStateException - when an entry with this network ID or key already exists
      IllegalStateException - when the registry was frozen
    • register

      default <V extends T> V register(net.kyori.adventure.key.Key key, V value)
      Adds a new entry to this registry under the given key. 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 under
      value - 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
      IllegalStateException - when the registry was frozen
    • register

      default <V extends T> V register(int id, net.kyori.adventure.key.Key key, V value)
      Adds a new entry to this register under the given id and key.
      Type Parameters:
      V - the type of the new entry
      Parameters:
      id - the network ID to register the new entry under
      key - the key to register the new entry under
      value - 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
      IllegalStateException - when the registry was frozen
      NullPointerException - when the value was null
    • register

      void register(RegistryEntryData<T> entry)
      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
      IllegalStateException - 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

      void bind(IntFunction<T> binder)
      Binds this registry, if there were any unbound entries. The registry must be frozen before binding it.

      This method uses the given IntFunction to bind all unbound registry entries. As a result, after calling this method, all registry entries should be bound.

      The IntFunction is given a network ID, and it is expected to return a MutableJavaRegistry for that respective network ID. If it returns null, a NullPointerException is 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 frozen
      NullPointerException - when the binder returned null for an ID
      See Also: