Pages: Registries

Registries

Registry is a thread-safe id-to-value map for your content - items, mobs, quests, whatever - with an optional annotation it can scan for.

object ItemRegistry : Registry<Item>(Item::class, RegisterItem::class) {
    override fun idOf(value: Item): String = value.id
}

ItemRegistry.scan(plugin)          // finds everything annotated with @RegisterItem (Paper, import me.clearedSpore.sporeAPI.scan.scan)
ItemRegistry.scan(MyApp::class.java) // same thing outside Paper: pass your main class
ItemRegistry.register(myItem)      // or register by hand

val item = ItemRegistry["magic_sword"]   // null if missing
val same = ItemRegistry.require("magic_sword")   // throws if missing

Registering the same id twice throws DuplicateRegistrationException instead of quietly overwriting. Override onRegister if you need to hook each entry as it comes in.

Every registry is tracked in RegistryIndex, which is what /<label> debug uses to list them and their sizes.