Interface WritableRegistry<T>

Type Parameters:
T - the type of the values
All Superinterfaces:
Registry<T>

public interface WritableRegistry<T> extends Registry<T>
A registry plugins can add entries to, on top of the vanilla ones.

Vanilla entries always stay registered: they can be replaced, and come back once the replacement is unregistered. Registries sent to clients should be changed while plugins load: a change once players are connected sends them back to the configuration phase.

Since:
0.1.0
See Also:
  • Method Details

    • register

      T register(TypedKey<T> key, T value, Plugin owner)
      Registers a new entry.
      Parameters:
      key - the key to register it under
      value - the value
      owner - the plugin registering it
      Returns:
      value
      Throws:
      IllegalStateException - if something is already registered under key; use overwrite(TypedKey, Object, Plugin) to replace it
      IllegalArgumentException - if the value is invalid, or carries a key other than key
      Since:
      0.1.0
    • register

      default T register(T value, Plugin owner)
      Registers a new entry under the key the value carries.
      Parameters:
      value - the value, carrying its key
      owner - the plugin registering it
      Returns:
      value
      Throws:
      IllegalArgumentException - if the value does not carry its key, or is invalid
      IllegalStateException - if something is already registered under its key
      Since:
      0.1.0
    • registerFromJson

      T registerFromJson(TypedKey<T> key, String json, Plugin owner)
      Reads an entry from its data pack JSON representation and registers it.
      Parameters:
      key - the key to register it under
      json - the JSON, as found in a data pack
      owner - the plugin registering it
      Returns:
      the registered value
      Throws:
      IllegalArgumentException - if the JSON is malformed or invalid
      IllegalStateException - if something is already registered under key
      Since:
      0.1.0
    • overwrite

      Optional<T> overwrite(TypedKey<T> key, T value, Plugin owner)
      Registers an entry, replacing any existing one under the same key, vanilla ones included.
      Parameters:
      key - the key to register it under
      value - the value
      owner - the plugin registering it
      Returns:
      the value previously registered under that key, if any
      Throws:
      IllegalArgumentException - if the value is invalid, or carries a key other than key
      Since:
      0.1.0
    • unregister

      boolean unregister(TypedKey<T> key)
      Removes an entry added by a plugin, or restores the vanilla value of a replaced one.
      Parameters:
      key - the key
      Returns:
      true if an entry was removed or restored, false if nothing was registered by a plugin under key
      Since:
      0.1.0
    • unregisterAll

      void unregisterAll(Plugin owner)
      Removes every entry a plugin added, and restores every vanilla value it replaced.
      Parameters:
      owner - the plugin
      Since:
      0.1.0
    • addToTag

      boolean addToTag(TagKey<T> tag, TypedKey<T> key, Plugin owner)
      Adds an entry to a tag, creating the tag if needed.
      Parameters:
      tag - the tag
      key - the key of the entry
      owner - the plugin registering it
      Returns:
      true if the entry was added, false if it already belonged to the tag
      Throws:
      IllegalArgumentException - if nothing is registered under key
      Since:
      0.1.0
    • removeFromTag

      boolean removeFromTag(TagKey<T> tag, TypedKey<T> key, Plugin owner)
      Removes an entry from a tag.
      Parameters:
      tag - the tag
      key - the key of the entry
      owner - the plugin
      Returns:
      true if the entry was removed, false if it did not belong to the tag
      Since:
      0.1.0