From daa1c6171fc1d9863cb2c3604a99859b94a7e408 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sun, 12 Apr 2026 20:39:31 +0200 Subject: [PATCH] check section exist for group & conflict --- .../alexcrea/cuanvil/group/EnchantConflictManager.kt | 11 ++++++++++- .../xyz/alexcrea/cuanvil/group/ItemGroupManager.kt | 11 ++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index f710f76..670dea8 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -48,6 +48,11 @@ class EnchantConflictManager { lateinit var conflictList: ArrayList + + 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) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt index 65eef34..5c6cc9c 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt @@ -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(