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

@ -26,7 +26,8 @@ Not yet uploaded. but fell free to compile it yourself.
### Permissions: ### Permissions:
```yml ```yml
ue.unsafe: Allows use of custom restriction rules 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: ### Default Configuration:

View file

@ -41,8 +41,11 @@ class AnvilEventListener : Listener {
val first = inventory.getItem(0) ?: return val first = inventory.getItem(0) ?: return
val second = inventory.getItem(1) ?: return val second = inventory.getItem(1) ?: return
if (first.canMergeWith(second)) { if (first.canMergeWith(second)) {
// Try to find player
val player = event.view.player
val newEnchants = first.findEnchantments() val newEnchants = first.findEnchantments()
.combineWith(second.findEnchantments()) .combineWith(second.findEnchantments(),player)
val resultItem = first.clone() val resultItem = first.clone()
resultItem.itemMeta?.let { resultItem.itemMeta?.let {
it.setDisplayName(inventory.renameText) it.setDisplayName(inventory.renameText)
@ -62,8 +65,6 @@ class AnvilEventListener : Listener {
repairCost = min(repairCost, ConfigOptions.limitRepairValue) repairCost = min(repairCost, ConfigOptions.limitRepairValue)
} }
// Try to find player
val player = event.view.player
// Set object only if allowed // Set object only if allowed
if(itemAllowed(resultItem,player)){ if(itemAllowed(resultItem,player)){
event.result = resultItem event.result = resultItem
@ -108,7 +109,7 @@ class AnvilEventListener : Listener {
private fun itemAllowed(item: ItemStack, player: HumanEntity): Boolean{ 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(player.hasPermission(UnsafeEnchants.unsafePermission)){
if(UnsafeEnchants.conflictManager.isConflicting(item)) if(UnsafeEnchants.conflictManager.isConflicting(item))

View file

@ -19,7 +19,10 @@ class UnsafeEnchants : JavaPlugin() {
// Permission string required to use the plugin's features // Permission string required to use the plugin's features
const val unsafePermission = "ue.unsafe" const val unsafePermission = "ue.unsafe"
// Permission string required to bypass enchantment conflicts test // 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 // Item Grouping Configuration file name
const val itemGroupingConfigName = "item_groups.yml" const val itemGroupingConfigName = "item_groups.yml"
// Conflict Configuration file name // Conflict Configuration file name

View file

@ -2,6 +2,7 @@ package io.delilaheve.util
import io.delilaheve.UnsafeEnchants import io.delilaheve.UnsafeEnchants
import org.bukkit.enchantments.Enchantment import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.HumanEntity
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@ -20,7 +21,7 @@ object EnchantmentUtil {
* Combine 2 sets of enchantments according to our configuration * Combine 2 sets of enchantments according to our configuration
*/ */
fun Map<Enchantment, Int>.combineWith( fun Map<Enchantment, Int>.combineWith(
other: Map<Enchantment, Int> other: Map<Enchantment, Int>, player: HumanEntity
) = mutableMapOf<Enchantment, Int>().apply { ) = mutableMapOf<Enchantment, Int>().apply {
putAll(this@combineWith) putAll(this@combineWith)
other.forEach { (enchantment, level) -> other.forEach { (enchantment, level) ->
@ -44,7 +45,11 @@ object EnchantmentUtil {
else -> { else -> {
// try to increase the enchantment level by 1 // try to increase the enchantment level by 1
var newLevel = this[enchantment]?.plus(1) ?: 0 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) newLevel = min(newLevel, maxLevel)
if (newLevel > 0) { this[enchantment] = newLevel } if (newLevel > 0) { this[enchantment] = newLevel }
} }

View file

@ -15,3 +15,6 @@ permissions:
ue.bypass.fuse: ue.bypass.fuse:
default: false 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