-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
loader/src/main/kotlin/com/willfp/libreforge/loader/configs/RegistrableCategory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |