add bypass level check permission and update README.md

This commit is contained in:
alexcrea 2024-02-03 00:23:03 +01:00
parent 181dbbb1e4
commit 737d955e9f
5 changed files with 22 additions and 9 deletions

View file

@ -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))

View file

@ -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

View file

@ -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<Enchantment, Int>.combineWith(
other: Map<Enchantment, Int>
other: Map<Enchantment, Int>, player: HumanEntity
) = mutableMapOf<Enchantment, Int>().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 }
}

View file

@ -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
description: Allow player to combine every "unsafe" enchants
ue.bypass.level:
default: false
description: Allow player to bypass max level limit