Skip to content

Commit

Permalink
Added RegistrableCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 10, 2023
1 parent 0fffc44 commit 5c97d81
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<T : Registrable>(
id: String,
directory: String
) : ConfigCategory(id, directory) {
/**
* The registry.
*/
protected val registry = Registry<T>()

/**
* 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<T> = registry.values()
}

0 comments on commit 5c97d81

Please sign in to comment.