Class ConfigKeyRegistry
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:
KEYS_BY_PATH—(petType, key)→ConfigKeylookup forlookup(java.lang.String, java.lang.String)and duplicate detection. Concurrent hashmap; safe for hot-path reads.ALL_KEYS— iteration order preserved for YAML I/O. Copy-on-write sowriteDefaults(org.bukkit.configuration.Configuration)andloadFromYaml(org.bukkit.configuration.ConfigurationSection)don't lock.
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 Summary
Modifier and TypeMethodDescriptionall()Returns a snapshot of every registered key.static voidForce-initializesMyPetGlobal(and, via its static block, every nested section) so each globalConfigKeyfield initializer fires and registers.static voidForce-initializes every registered pet class viaClass.forName(true)so each one's staticConfigKeyfield initializers fire and register with this registry.static voidloadFromYaml(ConfigurationSection config) Reads each registered key's value fromconfigand publishes viaConfigKey.loadFrom(org.bukkit.configuration.ConfigurationSection).static voidReads every global key's value fromconfig(config.yml).static ConfigKey<?> static booleanTyped-bool convenience wrapper aroundlookup(java.lang.String, java.lang.String).static voidwriteDefaults(Configuration config) WritesConfigKey.yamlDefaultfor every registered key intoconfig.static voidwriteGlobalDefaults(Configuration config) Writes every global key's default intoconfig(config.yml).
-
Method Details
-
ensurePetsLoaded
public static void ensurePetsLoaded()Force-initializes every registered pet class viaClass.forName(true)so each one's staticConfigKeyfield 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), andloadFromYaml(org.bukkit.configuration.ConfigurationSection). -
lookup
Returns theConfigKeyfor(petType, key), ornullif none is registered. Used byPetConfigLookupand by migrations that need to callConfigKey.update(T).- Parameters:
petType- the pet type to searchkey- the key's short name- Returns:
- the registered key, or
nullif nothing matches
-
readBool
Typed-bool convenience wrapper aroundlookup(java.lang.String, java.lang.String). Returns the current boolean value of the registered key, orfallbackif no key is registered for(petType, key)or the registered key's value type isn'tBoolean.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 asRequireRideSkillandAllowNonOwnerPrimaryMount) that has no static field accessor on a specific Pet class. Prefer a typed handle where one exists.- Parameters:
petType- the pet type to searchkey- the key's short namefallback- returned when the key is absent or not a boolean- Returns:
- the key's value, or
fallback
-
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-initializesMyPetGlobal(and, via its static block, every nested section) so each globalConfigKeyfield initializer fires and registers. Idempotent; runs once per JVM. The class is referenced by name because it lives in the sameapimodule but is not otherwise a compile dependency of the registry. -
writeGlobalDefaults
Writes every global key's default intoconfig(config.yml).- Parameters:
config- the configuration to write plugin-wide defaults into
-
loadGlobalsFromYaml
Reads every global key's value fromconfig(config.yml). Hot-reloadable.- Parameters:
config- the section to read plugin-wide values from
-
writeDefaults
WritesConfigKey.yamlDefaultfor every registered key intoconfig.- Parameters:
config- the configuration to write per-pet defaults into
-
loadFromYaml
Reads each registered key's value fromconfigand publishes viaConfigKey.loadFrom(org.bukkit.configuration.ConfigurationSection). Safe to call concurrently withConfigKey.get()on hot paths.- Parameters:
config- the section to read per-pet values from
-