diff --git a/loader/src/main/kotlin/com/willfp/libreforge/loader/configs/RegistrableCategory.kt b/loader/src/main/kotlin/com/willfp/libreforge/loader/configs/RegistrableCategory.kt new file mode 100644 index 000000000..58a828c9a --- /dev/null +++ b/loader/src/main/kotlin/com/willfp/libreforge/loader/configs/RegistrableCategory.kt @@ -0,0 +1,32 @@ +package com.willfp.libreforge.loader.configs + +import com.willfp.eco.core.registry.Registrable +import com.willfp.eco.core.registry.Registry + +/** + * A shorthand way of creating config categories that have their own registries. + */ +abstract class RegistrableCategory( + id: String, + directory: String +) : ConfigCategory(id, directory) { + /** + * The registry. + */ + protected val registry = Registry() + + /** + * Get an element by [id]. + */ + operator fun get(id: String?): T? = getByID(id) + + /** + * Get an element by [id]. + */ + fun getByID(id: String?): T? = id?.let { registry[id] } + + /** + * Get all elements. + */ + fun values(): Set = registry.values() +}