mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
get item type via name
This commit is contained in:
parent
b121d314d3
commit
84d4e811e2
2 changed files with 19 additions and 35 deletions
|
|
@ -2,8 +2,9 @@ package xyz.alexcrea.cuanvil.dependency.datapack
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import io.papermc.paper.datapack.Datapack
|
import io.papermc.paper.datapack.Datapack
|
||||||
|
import io.papermc.paper.registry.RegistryAccess
|
||||||
|
import io.papermc.paper.registry.RegistryKey
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.configuration.file.FileConfiguration
|
import org.bukkit.configuration.file.FileConfiguration
|
||||||
import org.bukkit.configuration.file.YamlConfiguration
|
import org.bukkit.configuration.file.YamlConfiguration
|
||||||
|
|
@ -135,8 +136,7 @@ object DataPackDependency {
|
||||||
// Order matter for this file
|
// Order matter for this file
|
||||||
// Could rewrite to not matter but not really important, so I keep it like that
|
// Could rewrite to not matter but not really important, so I keep it like that
|
||||||
private fun handleItemGroups(yml: YamlConfiguration) {
|
private fun handleItemGroups(yml: YamlConfiguration) {
|
||||||
//TODO see below todo
|
val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||||
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
|
||||||
|
|
||||||
for (groupName in yml.getKeys(false)) {
|
for (groupName in yml.getKeys(false)) {
|
||||||
val section = yml.getConfigurationSection(groupName) ?: continue
|
val section = yml.getConfigurationSection(groupName) ?: continue
|
||||||
|
|
@ -147,19 +147,15 @@ object DataPackDependency {
|
||||||
if (group == null) group = IncludeGroup(groupName)
|
if (group == null) group = IncludeGroup(groupName)
|
||||||
|
|
||||||
for (name in section.getStringList("items")) {
|
for (name in section.getStringList("items")) {
|
||||||
//TODO get item key from
|
val key = NamespacedKey.fromString(name.lowercase())
|
||||||
/*val key = NamespacedKey.fromString(name.lowercase())
|
if (key == null) throw IllegalStateException("Invalid item type: $name")
|
||||||
if (key == null) throw IllegalStateException("Invalid item type: " + name)
|
|
||||||
val type = itemRegistry.get(key)*/
|
|
||||||
|
|
||||||
val mat = Material.getMaterial(name.uppercase())
|
val type = itemRegistry.get(key)
|
||||||
|
if (type == null) {
|
||||||
|
throw IllegalStateException("Could not find item type $name for item group $groupName")
|
||||||
if (mat == null) {
|
|
||||||
CustomAnvil.instance.logger.warning("Could not find material $name for item group $groupName")
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
group.addToPolicy(mat.asItemType()!!)
|
|
||||||
|
group.addToPolicy(type)
|
||||||
}
|
}
|
||||||
for (name in section.getStringList("groups")) {
|
for (name in section.getStringList("groups")) {
|
||||||
val otherGroup = MaterialGroupApi.getGroup(name)
|
val otherGroup = MaterialGroupApi.getGroup(name)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
package xyz.alexcrea.cuanvil.group
|
package xyz.alexcrea.cuanvil.group
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.Material
|
import io.papermc.paper.registry.RegistryAccess
|
||||||
|
import io.papermc.paper.registry.RegistryKey
|
||||||
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.configuration.ConfigurationSection
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
class ItemGroupManager {
|
class ItemGroupManager {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -76,14 +79,12 @@ class ItemGroupManager {
|
||||||
config: ConfigurationSection,
|
config: ConfigurationSection,
|
||||||
keys: Set<String>
|
keys: Set<String>
|
||||||
) {
|
) {
|
||||||
//TODO see below todo
|
val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||||
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
|
||||||
|
|
||||||
// Read material to include in this group policy
|
// Read material to include in this group policy
|
||||||
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH)
|
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH)
|
||||||
for (typeName in materialList) {
|
for (typeName in materialList) {
|
||||||
//TODO get item key from
|
val key = NamespacedKey.fromString(typeName.lowercase())
|
||||||
/*val key = NamespacedKey.fromString(typeName.lowercase())
|
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
CustomAnvil.instance.logger.warning(
|
CustomAnvil.instance.logger.warning(
|
||||||
"Malformed item type $typeName on group ${group.getName()}"
|
"Malformed item type $typeName on group ${group.getName()}"
|
||||||
|
|
@ -102,22 +103,9 @@ class ItemGroupManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
val materialName = typeName.uppercase(Locale.getDefault())
|
|
||||||
val material = Material.getMaterial(materialName)
|
|
||||||
if (material == null) {
|
|
||||||
// Check if we should warn the user
|
|
||||||
if (materialName !in FUTURE_MATERIAL) {
|
|
||||||
CustomAnvil.instance.logger.warning(
|
|
||||||
"Unknown material $materialName on group ${group.getName()}"
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
group.addToPolicy(type)
|
||||||
group.addToPolicy(material.asItemType()!!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read group to include in this group policy.
|
// Read group to include in this group policy.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue