mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
make sure "all" conflict are always registered
This commit is contained in:
parent
43b4e72c49
commit
92960ca819
1 changed files with 41 additions and 18 deletions
|
|
@ -53,14 +53,17 @@ object DataPackDependency {
|
||||||
val version = LASTEST_VERSION[pack]
|
val version = LASTEST_VERSION[pack]
|
||||||
|
|
||||||
val currentVersion = Version.fromString(defConfig.config.getString("datapack.$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
|
// Add pack value or do update from previous version
|
||||||
// note: update thingy is not yet implemented
|
// note: update thingy is not yet implemented
|
||||||
configureDatapack(pack)
|
configureDatapack(pack)
|
||||||
|
|
||||||
// Finally, set current pack version to config
|
// 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)
|
defConfig.saveToDisk(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +92,7 @@ object DataPackDependency {
|
||||||
val reader = InputStreamReader(enchantConflict.openStream())
|
val reader = InputStreamReader(enchantConflict.openStream())
|
||||||
val yml = YamlConfiguration.loadConfiguration(reader)
|
val yml = YamlConfiguration.loadConfiguration(reader)
|
||||||
|
|
||||||
needSave = needSave || addEnchantConflict(yml, newConflictList)
|
needSave = addEnchantConflict(yml, newConflictList)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (conflict in newConflictList) {
|
for (conflict in newConflictList) {
|
||||||
|
|
@ -146,7 +149,8 @@ object DataPackDependency {
|
||||||
|
|
||||||
val conflict = ConflictBuilder(
|
val conflict = ConflictBuilder(
|
||||||
"restriction_${ench.replace(":", "_")}",
|
"restriction_${ench.replace(":", "_")}",
|
||||||
CustomAnvil.instance)
|
CustomAnvil.instance
|
||||||
|
)
|
||||||
conflict.addEnchantment(NamespacedKey.fromString(ench)!!)
|
conflict.addEnchantment(NamespacedKey.fromString(ench)!!)
|
||||||
for (group in groups) {
|
for (group in groups) {
|
||||||
conflict.addExcludedGroup(group)
|
conflict.addExcludedGroup(group)
|
||||||
|
|
@ -166,7 +170,7 @@ object DataPackDependency {
|
||||||
|
|
||||||
for (group in groups) {
|
for (group in groups) {
|
||||||
if (group.startsWith('#')) {
|
if (group.startsWith('#')) {
|
||||||
needSave = needSave || joinGroup(conflicts, group.substring(1), ench)
|
needSave = joinGroup(conflicts, group.substring(1), ench) || needSave
|
||||||
} else {
|
} else {
|
||||||
createConflict(conflictList, ench, group)
|
createConflict(conflictList, ench, group)
|
||||||
}
|
}
|
||||||
|
|
@ -193,15 +197,18 @@ object DataPackDependency {
|
||||||
conflictList.add(conflict)
|
conflictList.add(conflict)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun joinGroup(conflicts: HashMap<String, ConflictBuilder>, group: String, ench: String): Boolean {
|
private fun setEnchantAsAll(ench: String) {
|
||||||
if ("all".equals(group, ignoreCase = true)) {
|
|
||||||
// We assume current is not null and of type CABukkitEnchantment
|
// We assume current is not null and of type CABukkitEnchantment
|
||||||
val current = EnchantmentApi.getByKey(NamespacedKey.fromString(ench)!!) as CABukkitEnchantment
|
val current = EnchantmentApi.getByKey(NamespacedKey.fromString(ench)!!) as CABukkitEnchantment
|
||||||
|
|
||||||
// We need to replace current wrapped enchantment with the all conflict wrapper
|
// We need to replace current wrapped enchantment with the all conflict wrapper
|
||||||
EnchantmentApi.unregisterEnchantment(current)
|
EnchantmentApi.unregisterEnchantment(current)
|
||||||
EnchantmentApi.registerEnchantment(CAIncompatibleAllEnchant(current.bukkit, current.defaultRarity()))
|
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
|
return false
|
||||||
} else {
|
} else {
|
||||||
val config = ConfigHolder.CONFLICT_HOLDER.config
|
val config = ConfigHolder.CONFLICT_HOLDER.config
|
||||||
|
|
@ -230,4 +237,20 @@ object DataPackDependency {
|
||||||
return true
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue