From 737d955e9f700ce8148900eafc307aabee83d917 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sat, 3 Feb 2024 00:23:03 +0100 Subject: [PATCH] add bypass level check permission and update README.md --- README.md | 3 ++- src/main/kotlin/io/delilaheve/AnvilEventListener.kt | 9 +++++---- src/main/kotlin/io/delilaheve/UnsafeEnchants.kt | 5 ++++- src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt | 9 +++++++-- src/main/resources/plugin.yml | 5 ++++- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4a8337e..69fac39 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ Not yet uploaded. but fell free to compile it yourself. ### Permissions: ```yml ue.unsafe: Allows use of custom restriction rules -ue.unsafe_all: bypass every enchantment restriction, including custom restriction +ue.bypass.fuse: Bypass every enchantment restriction check. including custom restriction +ue.bypass.level: Bypass max level check. including custom max level ``` ### Default Configuration: diff --git a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt index f9fe27c..83ff030 100644 --- a/src/main/kotlin/io/delilaheve/AnvilEventListener.kt +++ b/src/main/kotlin/io/delilaheve/AnvilEventListener.kt @@ -41,8 +41,11 @@ class AnvilEventListener : Listener { val first = inventory.getItem(0) ?: return val second = inventory.getItem(1) ?: return if (first.canMergeWith(second)) { + // Try to find player + val player = event.view.player + val newEnchants = first.findEnchantments() - .combineWith(second.findEnchantments()) + .combineWith(second.findEnchantments(),player) val resultItem = first.clone() resultItem.itemMeta?.let { it.setDisplayName(inventory.renameText) @@ -62,8 +65,6 @@ class AnvilEventListener : Listener { repairCost = min(repairCost, ConfigOptions.limitRepairValue) } - // Try to find player - val player = event.view.player // Set object only if allowed if(itemAllowed(resultItem,player)){ event.result = resultItem @@ -108,7 +109,7 @@ class AnvilEventListener : Listener { private fun itemAllowed(item: ItemStack, player: HumanEntity): Boolean{ - if(player.hasPermission(UnsafeEnchants.unsafeBypassPermission)) return true + if(player.hasPermission(UnsafeEnchants.bypassFusePermission)) return true if(player.hasPermission(UnsafeEnchants.unsafePermission)){ if(UnsafeEnchants.conflictManager.isConflicting(item)) diff --git a/src/main/kotlin/io/delilaheve/UnsafeEnchants.kt b/src/main/kotlin/io/delilaheve/UnsafeEnchants.kt index dc5f9bc..f5188b2 100644 --- a/src/main/kotlin/io/delilaheve/UnsafeEnchants.kt +++ b/src/main/kotlin/io/delilaheve/UnsafeEnchants.kt @@ -19,7 +19,10 @@ class UnsafeEnchants : JavaPlugin() { // Permission string required to use the plugin's features const val unsafePermission = "ue.unsafe" // Permission string required to bypass enchantment conflicts test - const val unsafeBypassPermission = "ue.bypass.fuse" + const val bypassFusePermission = "ue.bypass.fuse" + // Permission string required to bypass enchantment conflicts test + const val bypassLevelPermission = "ue.bypass.level" + // Item Grouping Configuration file name const val itemGroupingConfigName = "item_groups.yml" // Conflict Configuration file name diff --git a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt index 55c8c95..fc627bb 100644 --- a/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/EnchantmentUtil.kt @@ -2,6 +2,7 @@ package io.delilaheve.util import io.delilaheve.UnsafeEnchants import org.bukkit.enchantments.Enchantment +import org.bukkit.entity.HumanEntity import kotlin.math.max import kotlin.math.min @@ -20,7 +21,7 @@ object EnchantmentUtil { * Combine 2 sets of enchantments according to our configuration */ fun Map.combineWith( - other: Map + other: Map, player: HumanEntity ) = mutableMapOf().apply { putAll(this@combineWith) other.forEach { (enchantment, level) -> @@ -44,7 +45,11 @@ object EnchantmentUtil { else -> { // try to increase the enchantment level by 1 var newLevel = this[enchantment]?.plus(1) ?: 0 - val maxLevel = ConfigOptions.enchantLimit(enchantment) + val maxLevel = if(player.hasPermission(UnsafeEnchants.bypassLevelPermission)){ + 255 + }else{ + ConfigOptions.enchantLimit(enchantment) + } newLevel = min(newLevel, maxLevel) if (newLevel > 0) { this[enchantment] = newLevel } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index af176c7..3348a47 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,4 +14,7 @@ permissions: description: Allow player to combine allowed "unsafe" enchants ue.bypass.fuse: default: false - description: Allow player to combine every "unsafe" enchants \ No newline at end of file + description: Allow player to combine every "unsafe" enchants + ue.bypass.level: + default: false + description: Allow player to bypass max level limit \ No newline at end of file