mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add bypass level check permission and update README.md
This commit is contained in:
parent
181dbbb1e4
commit
737d955e9f
5 changed files with 22 additions and 9 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue