add verbose log

This commit is contained in:
alexcrea 2024-03-25 02:09:09 +01:00
parent 27b949d1e5
commit 4b5ecf301a
7 changed files with 47 additions and 4 deletions

View file

@ -64,6 +64,7 @@ class AnvilEventListener : Listener {
// Test/stop if nothing changed. // Test/stop if nothing changed.
if(first == resultItem){ if(first == resultItem){
CustomAnvil.log("no right item, But input is same as output")
event.result = null event.result = null
return return
} }
@ -95,6 +96,7 @@ class AnvilEventListener : Listener {
// Test/stop if nothing changed. // Test/stop if nothing changed.
if(first == resultItem){ if(first == resultItem){
CustomAnvil.log("Mergable with second, But input is same as output")
event.result = null event.result = null
return return
} }
@ -125,6 +127,7 @@ class AnvilEventListener : Listener {
// Test/stop if nothing changed. // Test/stop if nothing changed.
if(first == resultItem){ if(first == resultItem){
CustomAnvil.log("unit repair, But input is same as output")
event.result = null event.result = null
return return
} }
@ -132,6 +135,7 @@ class AnvilEventListener : Listener {
handleAnvilXp(inventory, event, anvilCost) handleAnvilXp(inventory, event, anvilCost)
}else{ }else{
CustomAnvil.log("no anvil fuse type found")
event.result = null event.result = null
} }
} }

View file

@ -49,6 +49,15 @@ class CustomAnvil : JavaPlugin() {
instance.logger.info(message) instance.logger.info(message)
} }
} }
/**
* Vebose Logging handler
*/
fun verboseLog(message: String) {
if (ConfigOptions.verboseDebugLog) {
instance.logger.info(message)
}
}
} }
/** /**

View file

@ -35,6 +35,8 @@ object ConfigOptions {
private const val KEY_ITEM = "item" private const val KEY_ITEM = "item"
// Debug logging toggle path // Debug logging toggle path
private const val DEBUG_LOGGING = "debug_log" 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 // Default value for enchantment limits
private const val DEFAULT_ENCHANT_LIMIT = 5 private const val DEFAULT_ENCHANT_LIMIT = 5
@ -71,6 +73,8 @@ object ConfigOptions {
private const val DEFAULT_ENCHANT_VALUE = 0 private const val DEFAULT_ENCHANT_VALUE = 0
// Default value for debug logging // Default value for debug logging
private const val DEFAULT_DEBUG_LOG = false private const val DEFAULT_DEBUG_LOG = false
// Default value for debug logging
private const val DEFAULT_VERBOSE_DEBUG_LOG = false
/** /**
* Default enchantment limit * Default enchantment limit
@ -171,6 +175,16 @@ object ConfigOptions {
.getBoolean(DEBUG_LOGGING, DEFAULT_DEBUG_LOG) .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 * Get the given [enchantment]'s limit
*/ */

View file

@ -32,10 +32,12 @@ object EnchantmentUtil {
other.forEach { (enchantment, level) -> other.forEach { (enchantment, level) ->
// Enchantment not yet in result list // Enchantment not yet in result list
if (!containsKey(enchantment)) { 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 this[enchantment] = level
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment);
if(!player.hasPermission(CustomAnvil.bypassFusePermission) && 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) this.remove(enchantment)
} }
@ -43,8 +45,10 @@ object EnchantmentUtil {
// Enchantment already in result list // Enchantment already in result list
else{ else{
// ... and they are conflicting // ... 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)){ && !player.hasPermission(CustomAnvil.bypassFusePermission)){
CustomAnvil.verboseLog("Enchantment already in result list, and they are conflicting (${enchantment.key}, conflict: $conflictType)")
return@forEach return@forEach
} }
@ -52,6 +56,7 @@ object EnchantmentUtil {
if(this[enchantment] != other[enchantment]){ if(this[enchantment] != other[enchantment]){
val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0) val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0)
// apply the greater of the two if non-zero // apply the greater of the two if non-zero
if (newLevel > 0) { this[enchantment] = newLevel } if (newLevel > 0) { this[enchantment] = newLevel }
} }
// ... and they're the same level // ... and they're the same level

View file

@ -1,5 +1,6 @@
package xyz.alexcrea.cuanvil.group package xyz.alexcrea.cuanvil.group
import io.delilaheve.CustomAnvil
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.enchantments.Enchantment import org.bukkit.enchantments.Enchantment
@ -27,6 +28,7 @@ class EnchantConflictGroup(
var enchantAmount = 0 var enchantAmount = 0
for (enchantment in enchants) { for (enchantment in enchants) {
if(enchantment !in enchantments) continue if(enchantment !in enchantments) continue
CustomAnvil.verboseLog("Enchant ${enchantment.key} is in: ${enchantAmount + 1}/$minBeforeBlock ")
if(++enchantAmount > minBeforeBlock){ if(++enchantAmount > minBeforeBlock){
return false return false
} }

View file

@ -132,13 +132,19 @@ class EnchantConflictManager {
} }
fun isConflicting(base: Set<Enchantment>,mat: Material, newEnchant: Enchantment): ConflictType { fun isConflicting(base: Set<Enchantment>,mat: Material, newEnchant: Enchantment): ConflictType {
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
val conflictList = conflictMap[newEnchant] ?: return ConflictType.NO_CONFLICT val conflictList = conflictMap[newEnchant] ?: return ConflictType.NO_CONFLICT
CustomAnvil.verboseLog("Did not get skipped")
var result = ConflictType.NO_CONFLICT var result = ConflictType.NO_CONFLICT
for (conflict in conflictList) { 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){ if(conflict.getEnchants().size <= 1){
result = ConflictType.SMALL_CONFLICT result = ConflictType.SMALL_CONFLICT
CustomAnvil.verboseLog("Small conflict, continuing")
}else{ }else{
return ConflictType.BIG_CONFLICT return ConflictType.BIG_CONFLICT
} }

View file

@ -220,3 +220,6 @@ enchant_values:
# Whether to show debug logging # Whether to show debug logging
debug_log: false debug_log: false
# Whether to show verbose debug logging
debug_log_verbose: false