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 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 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
    • 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
    • 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
    • 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
      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
    • 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(IntFunction<T> binder)
      Freezes this registry. 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.

      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: