make sure "all" conflict are always registered

This commit is contained in:
alexcrea 2025-04-27 19:17:15 +02:00
parent 43b4e72c49
commit 92960ca819
No known key found for this signature in database
GPG key ID: 027DD67D2D3280C5

View file

@ -53,14 +53,17 @@ object DataPackDependency {
val version = LASTEST_VERSION[pack]
val currentVersion = Version.fromString(defConfig.config.getString("datapack.$pack"))
if (currentVersion.greaterEqual(version!!)) return
if (currentVersion.greaterEqual(version!!)) {
handleEnchantAllConflict(pack)
return
}
// Add pack value or do update from previous version
// note: update thingy is not yet implemented
configureDatapack(pack)
// Finally, set current pack version to config
//defConfig.config.set("datapack.$pack", version.toString()) // temporary disabled for easier test
defConfig.config.set("datapack.$pack", version.toString())
defConfig.saveToDisk(true)
}
@ -89,7 +92,7 @@ object DataPackDependency {
val reader = InputStreamReader(enchantConflict.openStream())
val yml = YamlConfiguration.loadConfiguration(reader)
needSave = needSave || addEnchantConflict(yml, newConflictList)
needSave = addEnchantConflict(yml, newConflictList)
}
for (conflict in newConflictList) {
@ -146,7 +149,8 @@ object DataPackDependency {
val conflict = ConflictBuilder(
"restriction_${ench.replace(":", "_")}",
CustomAnvil.instance)
CustomAnvil.instance
)
conflict.addEnchantment(NamespacedKey.fromString(ench)!!)
for (group in groups) {
conflict.addExcludedGroup(group)
@ -166,7 +170,7 @@ object DataPackDependency {
for (group in groups) {
if (group.startsWith('#')) {
needSave = needSave || joinGroup(conflicts, group.substring(1), ench)
needSave = joinGroup(conflicts, group.substring(1), ench) || needSave
} else {
createConflict(conflictList, ench, group)
}
@ -193,15 +197,18 @@ object DataPackDependency {
conflictList.add(conflict)
}
private fun joinGroup(conflicts: HashMap<String, ConflictBuilder>, group: String, ench: String): Boolean {
if ("all".equals(group, ignoreCase = true)) {
private fun setEnchantAsAll(ench: String) {
// We assume current is not null and of type CABukkitEnchantment
val current = EnchantmentApi.getByKey(NamespacedKey.fromString(ench)!!) as CABukkitEnchantment
// We need to replace current wrapped enchantment with the all conflict wrapper
EnchantmentApi.unregisterEnchantment(current)
EnchantmentApi.registerEnchantment(CAIncompatibleAllEnchant(current.bukkit, current.defaultRarity()))
}
private fun joinGroup(conflicts: HashMap<String, ConflictBuilder>, group: String, ench: String): Boolean {
if ("all".equals(group, ignoreCase = true)) {
setEnchantAsAll(ench)
return false
} else {
val config = ConfigHolder.CONFLICT_HOLDER.config
@ -230,4 +237,20 @@ object DataPackDependency {
return true
}
}
private fun handleEnchantAllConflict(pack: String) {
val enchantConflict = javaClass.getResource("/datapack/$pack/enchant_conflict.yml") ?: return
val reader = InputStreamReader(enchantConflict.openStream())
val yml = YamlConfiguration.loadConfiguration(reader)
for (ench in yml.getKeys(false)) {
val groups = yml.getStringList(ench)
if (groups.contains("#all")) {
setEnchantAsAll(ench)
}
}
}
}