avoid warn on default config

This commit is contained in:
alexcrea 2024-02-01 20:42:41 +01:00
parent 9f35c1a98d
commit 17bc9073a2
3 changed files with 27 additions and 9 deletions

View file

@ -17,6 +17,9 @@ class EnchantConflictManager {
private const val CONFLICT_GROUP_PATH = "notAffectedGroups" private const val CONFLICT_GROUP_PATH = "notAffectedGroups"
// Path for the maximum number of enchantment before validating the conflict // Path for the maximum number of enchantment before validating the conflict
private const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict" private const val ENCH_MAX_PATH = "maxEnchantmentBeforeConflict"
// Path for a flag: if the enchantment will be used in the last supported version
// TODO maybe replace this system by a list of "future" enchantment.
private const val FUTURE_USE_PATH = "useInFuture"
// Default name for an empty Material group // Default name for an empty Material group
private val DEFAULT_EMPTY_GROUP = IncludeGroup("empty") private val DEFAULT_EMPTY_GROUP = IncludeGroup("empty")
// Default name for a joining group // Default name for a joining group
@ -33,17 +36,19 @@ class EnchantConflictManager {
for (key in keys) { for (key in keys) {
val section = config.getConfigurationSection(key)!! val section = config.getConfigurationSection(key)!!
val conflict = createConflict(section,itemManager,key) val conflict = createConflict(section,itemManager,key)
if(conflict != null){
conflictList.add(conflict) conflictList.add(conflict)
} }
}
} }
// create and read a conflict from a yaml section // create and read a conflict from a yaml section
private fun createConflict(section: ConfigurationSection, private fun createConflict(section: ConfigurationSection,
itemManager: ItemGroupManager, itemManager: ItemGroupManager,
conflictName: String): EnchantConflictGroup { conflictName: String): EnchantConflictGroup? {
// Is it planed for the future
val futureUse = section.getBoolean(FUTURE_USE_PATH,false)
// Create conflict // Create conflict
val conflict = createConflictObject(section,itemManager,conflictName) val conflict = createConflictObject(section,itemManager,conflictName)
// Read and add enchantment to conflict // Read and add enchantment to conflict
@ -52,14 +57,19 @@ class EnchantConflictManager {
val enchantKey = NamespacedKey.minecraft(enchantName) val enchantKey = NamespacedKey.minecraft(enchantName)
val enchant = Enchantment.getByKey(enchantKey) val enchant = Enchantment.getByKey(enchantKey)
if(enchant == null){ if(enchant == null){
if(!futureUse){
UnsafeEnchants.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName") UnsafeEnchants.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
}
continue continue
} }
conflict.addEnchantment(enchant) conflict.addEnchantment(enchant)
} }
if(conflict.isEnchantEmpty()){ if(conflict.isEnchantEmpty()){
if(!futureUse){
UnsafeEnchants.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not work") UnsafeEnchants.instance.logger.warning("Conflict $conflictName do not have valid enchantment, it will not work")
} }
return null
}
return conflict return conflict
} }

View file

@ -16,6 +16,8 @@ class ItemGroupManager {
private const val MATERIAL_LIST_PATH = "items" private const val MATERIAL_LIST_PATH = "items"
// Path for included groups list // Path for included groups list
private const val GROUP_LIST_PATH = "groups" private const val GROUP_LIST_PATH = "groups"
// Temporary list of elements in default config that are use in future
private val FUTURE_MATERIAL = setOf("PIGLIN_HEAD","BRUSH")
} }
private lateinit var groupMap : HashMap<String,MaterialGroup> private lateinit var groupMap : HashMap<String,MaterialGroup>
@ -66,8 +68,12 @@ class ItemGroupManager {
val materialName = materialTemp.uppercase(Locale.getDefault()) val materialName = materialTemp.uppercase(Locale.getDefault())
val material = Material.getMaterial(materialName) val material = Material.getMaterial(materialName)
if(material == null){ if(material == null){
// Check if we should warn the user
if(materialName !in FUTURE_MATERIAL){
UnsafeEnchants.instance.logger.warning( UnsafeEnchants.instance.logger.warning(
"Unknown material $materialTemp on group ${group.getName()}") "Unknown material $materialTemp on group ${group.getName()}")
}
continue continue
} }
group.addToPolicy(material) group.addToPolicy(material)

View file

@ -145,8 +145,10 @@ restriction_sweeping:
enchantments: [sweeping] enchantments: [sweeping]
notAffectedGroups: [swords] notAffectedGroups: [swords]
# Do not exist in 1.18 but future proof # Do not exist in 1.18, that mean useInFuture will be set to true
# useInFuture set to true also mean it will not warn if there is an issue
restriction_swift_sneak: restriction_swift_sneak:
useInFuture: true
enchantments: [swift_sneak] enchantments: [swift_sneak]
notAffectedGroups: [boots] notAffectedGroups: [boots]