mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
fix permission check
This commit is contained in:
parent
271d173f5f
commit
7ee3a37b13
2 changed files with 23 additions and 8 deletions
|
|
@ -3,6 +3,7 @@ package io.delilaheve
|
||||||
import io.delilaheve.util.ConfigOptions
|
import io.delilaheve.util.ConfigOptions
|
||||||
import io.delilaheve.util.EnchantmentUtil.calculateValue
|
import io.delilaheve.util.EnchantmentUtil.calculateValue
|
||||||
import io.delilaheve.util.EnchantmentUtil.combineWith
|
import io.delilaheve.util.EnchantmentUtil.combineWith
|
||||||
|
import io.delilaheve.util.EnchantmentUtil.hasConflicts
|
||||||
import io.delilaheve.util.ItemUtil.canMergeWith
|
import io.delilaheve.util.ItemUtil.canMergeWith
|
||||||
import io.delilaheve.util.ItemUtil.findEnchantments
|
import io.delilaheve.util.ItemUtil.findEnchantments
|
||||||
import io.delilaheve.util.ItemUtil.isBook
|
import io.delilaheve.util.ItemUtil.isBook
|
||||||
|
|
@ -75,14 +76,13 @@ class AnvilEventListener : Listener {
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
fun anvilExtractionCheck(event: InventoryClickEvent) {
|
fun anvilExtractionCheck(event: InventoryClickEvent) {
|
||||||
val player = event.whoClicked as? Player ?: return
|
val player = event.whoClicked as? Player ?: return
|
||||||
if (player.hasPermission(requirePermission)) {
|
val inventory = event.inventory as? AnvilInventory ?: return
|
||||||
val inventory = event.inventory as? AnvilInventory ?: return
|
val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return
|
||||||
if (event.rawSlot != ANVIL_OUTPUT_SLOT) { return }
|
if (output.findEnchantments().hasConflicts() && !player.hasPermission(requirePermission)) { return }
|
||||||
val output = inventory.getItem(2) ?: return
|
if (event.rawSlot != ANVIL_OUTPUT_SLOT) { return }
|
||||||
if (output.type == Material.AIR) { return }
|
if (output.type == Material.AIR) { return }
|
||||||
if (player.level < inventory.repairCost) { return }
|
if (player.level < inventory.repairCost) { return }
|
||||||
event.result = Event.Result.ALLOW
|
event.result = Event.Result.ALLOW
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,21 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a set of enchantments has any conflicts
|
||||||
|
*/
|
||||||
|
fun Map<Enchantment, Int>.hasConflicts() : Boolean {
|
||||||
|
forEach { (enchantment1, _) ->
|
||||||
|
val hasConflict = any { (enchantment2, _) ->
|
||||||
|
enchantment2.conflictsWith(enchantment1)
|
||||||
|
}
|
||||||
|
if (hasConflict) {
|
||||||
|
return hasConflict
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the value of a set of enchantments
|
* Calculate the value of a set of enchantments
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue