From 4b5ecf301a3eca7463109a88b87fb98251a0ff8b Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 25 Mar 2024 02:09:09 +0100 Subject: [PATCH] add verbose log --- .../kotlin/io/delilaheve/AnvilEventListener.kt | 4 ++++ src/main/kotlin/io/delilaheve/CustomAnvil.kt | 9 +++++++++ .../kotlin/io/delilaheve/util/ConfigOptions.kt | 14 ++++++++++++++ .../kotlin/io/delilaheve/util/EnchantmentUtil.kt | 11 ++++++++--- .../alexcrea/cuanvil/group/EnchantConflictGroup.kt | 2 ++ .../cuanvil/group/EnchantConflictManager.kt | 8 +++++++- src/main/resources/config.yml | 3 +++ 7 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt index 26a27bd..6a72777 100644 --- a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt +++ b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt @@ -64,6 +64,7 @@ class AnvilEventListener : Listener { // Test/stop if nothing changed. if(first == resultItem){ + CustomAnvil.log("no right item, But input is same as output") event.result = null return } @@ -95,6 +96,7 @@ class AnvilEventListener : Listener { // Test/stop if nothing changed. if(first == resultItem){ + CustomAnvil.log("Mergable with second, But input is same as output") event.result = null return } @@ -125,6 +127,7 @@ class AnvilEventListener : Listener { // Test/stop if nothing changed. if(first == resultItem){ + CustomAnvil.log("unit repair, But input is same as output") event.result = null return } @@ -132,6 +135,7 @@ class AnvilEventListener : Listener { handleAnvilXp(inventory, event, anvilCost) }else{ + CustomAnvil.log("no anvil fuse type found") event.result = null } } diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 2f4fe43..28c8dd0 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -49,6 +49,15 @@ class CustomAnvil : JavaPlugin() { instance.logger.info(message) } } + + /** + * Vebose Logging handler + */ + fun verboseLog(message: String) { + if (ConfigOptions.verboseDebugLog) { + instance.logger.info(message) + } + } } /** diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index 7708568..fcbf42a 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -35,6 +35,8 @@ object ConfigOptions { private const val KEY_ITEM = "item" // Debug logging toggle path private const val DEBUG_LOGGING = "debug_log" + // Debug verbose logging toggle path + private const val VERBOSE_DEBUG_LOGGING = "debug_log_verbose" // Default value for enchantment limits private const val DEFAULT_ENCHANT_LIMIT = 5 @@ -71,6 +73,8 @@ object ConfigOptions { private const val DEFAULT_ENCHANT_VALUE = 0 // Default value for debug logging private const val DEFAULT_DEBUG_LOG = false + // Default value for debug logging + private const val DEFAULT_VERBOSE_DEBUG_LOG = false /** * Default enchantment limit @@ -171,6 +175,16 @@ object ConfigOptions { .getBoolean(DEBUG_LOGGING, DEFAULT_DEBUG_LOG) } + /** + * Whether to show verbose debug logging + */ + val verboseDebugLog: Boolean + get() { + return ConfigHolder.DEFAULT_CONFIG + .config + .getBoolean(VERBOSE_DEBUG_LOGGING, DEFAULT_VERBOSE_DEBUG_LOG) + } + /** * Get the given [enchantment]'s limit */ diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index f2f90d6..24a0f97 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -32,10 +32,12 @@ object EnchantmentUtil { other.forEach { (enchantment, level) -> // Enchantment not yet in result list if (!containsKey(enchantment)) { - // Add the enchantment if it doesn't have conflicts, or, if player is allowed to bypass enchantment restrictions + // Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions this[enchantment] = level + val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment); if(!player.hasPermission(CustomAnvil.bypassFusePermission) && - (ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT)){ + (conflictType != ConflictType.NO_CONFLICT)){ + CustomAnvil.verboseLog("Enchantment not yet in result list, but there is conflict (${enchantment.key}, conflict: $conflictType)") this.remove(enchantment) } @@ -43,8 +45,10 @@ object EnchantmentUtil { // Enchantment already in result list else{ // ... and they are conflicting - if((ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment) != ConflictType.NO_CONFLICT) + val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment) + if((conflictType != ConflictType.NO_CONFLICT) && !player.hasPermission(CustomAnvil.bypassFusePermission)){ + CustomAnvil.verboseLog("Enchantment already in result list, and they are conflicting (${enchantment.key}, conflict: $conflictType)") return@forEach } @@ -52,6 +56,7 @@ object EnchantmentUtil { if(this[enchantment] != other[enchantment]){ val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0) // apply the greater of the two if non-zero + if (newLevel > 0) { this[enchantment] = newLevel } } // ... and they're the same level diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt index ab72195..075b0c6 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt @@ -1,5 +1,6 @@ package xyz.alexcrea.cuanvil.group +import io.delilaheve.CustomAnvil import org.bukkit.Material import org.bukkit.enchantments.Enchantment @@ -27,6 +28,7 @@ class EnchantConflictGroup( var enchantAmount = 0 for (enchantment in enchants) { if(enchantment !in enchantments) continue + CustomAnvil.verboseLog("Enchant ${enchantment.key} is in: ${enchantAmount + 1}/$minBeforeBlock ") if(++enchantAmount > minBeforeBlock){ return false } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index aac5ef4..3d6eb29 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -132,13 +132,19 @@ class EnchantConflictManager { } fun isConflicting(base: Set,mat: Material, newEnchant: Enchantment): ConflictType { + CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}") val conflictList = conflictMap[newEnchant] ?: return ConflictType.NO_CONFLICT + CustomAnvil.verboseLog("Did not get skipped") var result = ConflictType.NO_CONFLICT for (conflict in conflictList) { - if(!conflict.allowed(base,mat)) { + CustomAnvil.verboseLog("Is against ${conflict.name}") + val conflicting = conflict.allowed(base,mat) + CustomAnvil.verboseLog("Was against ${conflict.name} and conflicting: $conflicting ") + if(!conflicting) { if(conflict.getEnchants().size <= 1){ result = ConflictType.SMALL_CONFLICT + CustomAnvil.verboseLog("Small conflict, continuing") }else{ return ConflictType.BIG_CONFLICT } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2de074b..61f169b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -220,3 +220,6 @@ enchant_values: # Whether to show debug logging debug_log: false + +# Whether to show verbose debug logging +debug_log_verbose: false