Class ConfigKeyRegistry

java.lang.Object
de.Keyle.MyPet.api.config.ConfigKeyRegistry

public final class ConfigKeyRegistry extends Object
Central registry of every ConfigKey declared as a static field on a pet class. Populated as a side effect of each key's factory call (ConfigKey.bool(java.lang.String, java.lang.String, boolean), etc.) which fires during the pet class's <clinit>.

ensurePetsLoaded() force-initializes every registered pet class via Class.forName(true) so the registry is fully populated before writeDefaults(org.bukkit.configuration.Configuration) / loadFromYaml(org.bukkit.configuration.ConfigurationSection) iterate.

Two storage layers:

register(de.Keyle.MyPet.api.config.ConfigKey<?>) is called only by ConfigKey factories — the package-private visibility prevents third-party code from constructing raw ConfigKeys outside the canonical pet-class declarations.

  • Method Details

    • ensurePetsLoaded

      public static void ensurePetsLoaded()
      Force-initializes every registered pet class via Class.forName(true) so each one's static ConfigKey field initializers fire and register with this registry. Idempotent; runs once per JVM.

      Each pet class is the canonical declaration site for its own config keys — this method is what makes those declarations observable to all(), writeDefaults(org.bukkit.configuration.Configuration), and loadFromYaml(org.bukkit.configuration.ConfigurationSection).

    • lookup

      public static ConfigKey<?> lookup(String petType, String key)
      Returns the ConfigKey for (petType, key), or null if none is registered. Used by PetConfigLookup and by migrations that need to call ConfigKey.update(T).
      Parameters:
      petType - the pet type to search
      key - the key's short name
      Returns:
      the registered key, or null if nothing matches
    • readBool

      public static boolean readBool(String petType, String key, boolean fallback)
      Typed-bool convenience wrapper around lookup(java.lang.String, java.lang.String). Returns the current boolean value of the registered key, or fallback if no key is registered for (petType, key) or the registered key's value type isn't Boolean.

      Backs PetSkillFlag.get(de.Keyle.MyPet.api.entity.Pet), and serves any caller reading a dynamically-registered flag (PreventNaturalGrowup, RetainEquipmentOnTame, and the rideable-pet gates such as RequireRideSkill and AllowNonOwnerPrimaryMount) that has no static field accessor on a specific Pet class. Prefer a typed handle where one exists.

      Parameters:
      petType - the pet type to search
      key - the key's short name
      fallback - returned when the key is absent or not a boolean
      Returns:
      the key's value, or fallback
    • all

      public static List<ConfigKey<?>> all()
      Returns a snapshot of every registered key. Iteration order matches registration order (so YAML output is stable across boots given the same declarations).
      Returns:
      every registered key
    • ensureGlobalsLoaded

      public static void ensureGlobalsLoaded()
      Force-initializes MyPetGlobal (and, via its static block, every nested section) so each global ConfigKey field initializer fires and registers. Idempotent; runs once per JVM. The class is referenced by name because it lives in the same api module but is not otherwise a compile dependency of the registry.
    • writeGlobalDefaults

      public static void writeGlobalDefaults(Configuration config)
      Writes every global key's default into config (config.yml).
      Parameters:
      config - the configuration to write plugin-wide defaults into
    • loadGlobalsFromYaml

      public static void loadGlobalsFromYaml(ConfigurationSection config)
      Reads every global key's value from config (config.yml). Hot-reloadable.
      Parameters:
      config - the section to read plugin-wide values from
    • writeDefaults

      public static void writeDefaults(Configuration config)
      Writes ConfigKey.yamlDefault for every registered key into config.
      Parameters:
      config - the configuration to write per-pet defaults into
    • loadFromYaml

      public static void loadFromYaml(ConfigurationSection config)
      Reads each registered key's value from config and publishes via ConfigKey.loadFrom(org.bukkit.configuration.ConfigurationSection). Safe to call concurrently with ConfigKey.get() on hot paths.
      Parameters:
      config - the section to read per-pet values from