Do not check conflict if player can bypass & log it

This commit is contained in:
alexcrea 2024-10-25 15:23:37 +02:00
parent c0af35fa0b
commit 36e26d762d
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F

View file

@ -30,13 +30,15 @@ object EnchantmentUtil {
) = mutableMapOf<CAEnchantment, Int>().apply { ) = mutableMapOf<CAEnchantment, Int>().apply {
putAll(this@combineWith) putAll(this@combineWith)
val bypassFuse = player.hasPermission(CustomAnvil.bypassFusePermission)
val bypassLevel = player.hasPermission(CustomAnvil.bypassLevelPermission)
other.forEach { (enchantment, level) -> other.forEach { (enchantment, level) ->
if(!enchantment.isAllowed(player)) return@forEach if(!enchantment.isAllowed(player)) return@forEach
// Get max level or 255 if player can bypass // Get max level or 255 if player can bypass
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission)) val maxLevel = if (bypassLevel) { 255 }
{ 255 } else else { ConfigOptions.enchantLimit(enchantment) }
{ ConfigOptions.enchantLimit(enchantment) }
val cappedLevel = min(level, maxLevel) val cappedLevel = min(level, maxLevel)
@ -44,11 +46,15 @@ object EnchantmentUtil {
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] = cappedLevel this[enchantment] = cappedLevel
val conflictType = if(bypassFuse){
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this, item, enchantment) CustomAnvil.verboseLog("Bypassed conflict check for ${enchantment.key}")
if (!player.hasPermission(CustomAnvil.bypassFusePermission) && return@forEach
(conflictType != ConflictType.NO_CONFLICT) }
) {
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager
.isConflicting(this, item, enchantment)
if (conflictType != ConflictType.NO_CONFLICT) {
CustomAnvil.verboseLog("Enchantment not yet in result list, but there is conflict (${enchantment.key}, conflict: $conflictType)") CustomAnvil.verboseLog("Enchantment not yet in result list, but there is conflict (${enchantment.key}, conflict: $conflictType)")
this.remove(enchantment) this.remove(enchantment)
} }
@ -58,14 +64,17 @@ object EnchantmentUtil {
else { else {
val oldLevel = this[enchantment]!! // <- should not be null. (enchantment already in result list) val oldLevel = this[enchantment]!! // <- should not be null. (enchantment already in result list)
if(bypassFuse){
CustomAnvil.verboseLog("Bypassed conflict check for ${enchantment.key}")
} else {
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager
.isConflicting(this, item, enchantment)
// ... and they are conflicting // ... and they are conflicting
val conflictType = if(conflictType != ConflictType.NO_CONFLICT){
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this, item, enchantment) CustomAnvil.verboseLog(
if ((conflictType != ConflictType.NO_CONFLICT) "Enchantment already in result list, and they are conflicting (${enchantment.key}, conflict: $conflictType)")
&& !player.hasPermission(CustomAnvil.bypassFusePermission) }
) {
CustomAnvil.verboseLog("Enchantment already in result list, and they are conflicting (${enchantment.key}, conflict: $conflictType)")
return@forEach
} }
// ... and they're not the same level // ... and they're not the same level