check section exist for group & conflict

This commit is contained in:
alexcrea 2026-04-12 20:39:31 +02:00
parent 1a71086327
commit daa1c6171f
Signed by: alexcrea
GPG key ID: E346CD16413450E3
2 changed files with 18 additions and 4 deletions

View file

@ -48,6 +48,11 @@ class EnchantConflictManager {
lateinit var conflictList: ArrayList<EnchantConflictGroup>
private fun warnBadKey(key: String) {
CustomAnvil.instance.logger.warning("Invalid key $key for conflict: is not a conflict")
}
// Read and prepare all conflict
fun prepareConflicts(config: ConfigurationSection, itemManager: ItemGroupManager) {
conflictList = ArrayList()
@ -59,7 +64,11 @@ class EnchantConflictManager {
val keys = config.getKeys(false)
for (key in keys) {
val section = config.getConfigurationSection(key)!!
val section = config.getConfigurationSection(key)
if(section == null) {
warnBadKey(key)
continue
}
val conflict = createConflict(section, itemManager, key)
addConflict(conflict)

View file

@ -31,6 +31,8 @@ class ItemGroupManager {
for (key in keys) {
if (groupMap.containsKey(key))
continue
if (!config.isConfigurationSection(key))
continue
createGroup(config, keys, key)
}
}
@ -51,6 +53,7 @@ class ItemGroupManager {
key: String
): AbstractMaterialGroup {
val groupSection = config.getConfigurationSection(key)!!
val groupType = groupSection.getString(GROUP_TYPE_PATH, null)
// Create Material group according to the group type
@ -105,11 +108,13 @@ class ItemGroupManager {
continue
}
// Get other group or create it if not yet created
val otherGroup = if (!groupMap.containsKey(groupName)) {
val otherGroup =
if (!groupMap.containsKey(groupName)) {
if(!config.isConfigurationSection(groupName)) continue
createGroup(config, keys, groupName)
} else {
groupMap[groupName]!!
}
else groupMap[groupName]!!
// Avoid self reference or it will create an infinite loop
if (otherGroup.isReferencing(group)) {
CustomAnvil.instance.logger.warning(