diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RegistryCommandArgument.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RegistryCommandArgument.kt index aaf4058d2..0e4399c3d 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RegistryCommandArgument.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RegistryCommandArgument.kt @@ -18,7 +18,7 @@ class RegistryCommandArgument(private val registry: RebarRegistry) @Suppress("PrivatePropertyName") private val ERROR_UNKNOWN = DynamicCommandExceptionType { - MessageComponentSerializer.message().serialize(Component.text("Unknown key in ${registry.key}: $it")) + MessageComponentSerializer.message().serialize(Component.text("Unknown key: $it")) } override fun convert(nativeType: NamespacedKey): T { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/registry/RebarRegistry.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/registry/RebarRegistry.kt index 6f42596e8..ec9bea950 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/registry/RebarRegistry.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/registry/RebarRegistry.kt @@ -11,7 +11,6 @@ import io.github.pylonmc.rebar.item.ItemTypeWrapper import io.github.pylonmc.rebar.item.RebarItemSchema import io.github.pylonmc.rebar.item.research.Research import io.github.pylonmc.rebar.recipe.RecipeType -import io.github.pylonmc.rebar.util.rebarKey import org.bukkit.Keyed import org.bukkit.NamespacedKey import org.bukkit.Tag @@ -22,9 +21,8 @@ import java.util.stream.Stream * This class is not thread safe and any concurrent access must be synchronized externally. * * @param T the type of the registered values - * @property key the key of this registry */ -class RebarRegistry(val key: NamespacedKey) : Iterable { +class RebarRegistry : Iterable { private val values: MutableMap = LinkedHashMap() @@ -121,53 +119,15 @@ class RebarRegistry(val key: NamespacedKey) : Iterable { fun stream(): Stream = values.values.stream() - override fun equals(other: Any?): Boolean = other is RebarRegistry<*> && key == other.key - override fun hashCode(): Int = key.hashCode() - override fun toString(): String = key.toString() - companion object { - private val registries: MutableMap> = mutableMapOf() - - // @formatter:off - @JvmField val ITEMS_KEY = rebarKey("items") - @JvmField val BLOCKS_KEY = rebarKey("blocks") - @JvmField val ENTITIES_KEY = rebarKey("entities") - @JvmField val FLUIDS_KEY = rebarKey("fluids") - @JvmField val GAMETESTS_KEY = rebarKey("gametests") - @JvmField val ADDONS_KEY = rebarKey("addons") - @JvmField val RECIPE_TYPES_KEY = rebarKey("recipe_types") - @JvmField val RESEARCHES_KEY = rebarKey("researches") - @JvmField val ITEM_TAGS_KEY = rebarKey("tags") - // @formatter:on - - // @formatter:off - @JvmField val ITEMS = RebarRegistry(ITEMS_KEY).also(::addRegistry) - @JvmField val BLOCKS = RebarRegistry(BLOCKS_KEY).also(::addRegistry) - @JvmField val ENTITIES = RebarRegistry(ENTITIES_KEY).also(::addRegistry) - @JvmField val FLUIDS = RebarRegistry(FLUIDS_KEY).also(::addRegistry) - @JvmField val ADDONS = RebarRegistry(ADDONS_KEY).also(::addRegistry) - @JvmField val GAMETESTS = RebarRegistry(GAMETESTS_KEY).also(::addRegistry) - @JvmField val RECIPE_TYPES = RebarRegistry>(RECIPE_TYPES_KEY).also(::addRegistry) - @JvmField val RESEARCHES = RebarRegistry(RESEARCHES_KEY).also(::addRegistry) - @JvmField val ITEM_TAGS = RebarRegistry>(ITEM_TAGS_KEY).also(::addRegistry) - // @formatter:on - - @JvmStatic - fun getRegistry(key: NamespacedKey): RebarRegistry { - return getRegistryOrNull(key) ?: throw IllegalArgumentException("Registry $key not found") - } - - @JvmStatic - fun getRegistryOrNull(key: NamespacedKey): RebarRegistry? { - @Suppress("UNCHECKED_CAST") - return registries[key] as? RebarRegistry - } - - @JvmStatic - fun addRegistry(registry: RebarRegistry<*>) { - val key = registry.key - check(key !in registries) { "Registry $key is already registered" } - registries[key] = registry - } + @JvmField val ITEMS = RebarRegistry() + @JvmField val BLOCKS = RebarRegistry() + @JvmField val ENTITIES = RebarRegistry() + @JvmField val FLUIDS = RebarRegistry() + @JvmField val ADDONS = RebarRegistry() + @JvmField val GAMETESTS = RebarRegistry() + @JvmField val RECIPE_TYPES = RebarRegistry>() + @JvmField val RESEARCHES = RebarRegistry() + @JvmField val ITEM_TAGS = RebarRegistry>() } } \ No newline at end of file