mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add permission check for Enchantment² enchantments.
This commit is contained in:
parent
b1ca8bd91c
commit
6553122819
3 changed files with 28 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil;
|
|||
import io.delilaheve.util.ItemUtil;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
|
@ -81,13 +82,22 @@ public abstract class WrappedEnchantment {
|
|||
public final int defaultMaxLevel(){return defaultMaxLevel;}
|
||||
|
||||
/**
|
||||
* If the enchantment have specialised group operation.
|
||||
* Check if the enchantment have specialised group operation.
|
||||
* @return If the enchantment is optimised for group operation.
|
||||
*/
|
||||
protected boolean isOptimised(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player is allowed to use this enchantment.
|
||||
* @param player The player to test.
|
||||
* @return If the player is allowed to use this enchantment.
|
||||
*/
|
||||
public boolean isAllowed(@NotNull HumanEntity player){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current level of the enchantment.
|
||||
* @param item Item to search the level for.
|
||||
|
|
@ -139,7 +149,6 @@ public abstract class WrappedEnchantment {
|
|||
public abstract void removeFrom(@NotNull ItemStack item);
|
||||
|
||||
// Static functions
|
||||
|
||||
/**
|
||||
* Clear every enchantment from this item.
|
||||
* @param item Item to be cleared from enchantments.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package xyz.alexcrea.cuanvil.enchant.wrapped;
|
|||
|
||||
import me.athlaeos.enchantssquared.enchantments.CustomEnchant;
|
||||
import me.athlaeos.enchantssquared.managers.CustomEnchantManager;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -29,6 +31,18 @@ public class EnchantSquaredEnchantment extends WrappedEnchantment {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowed(@NotNull HumanEntity human) {
|
||||
if(human instanceof Player){
|
||||
return this.enchant.hasPermission((Player) human);
|
||||
}
|
||||
// Not really ideal for maintainability but will probably never be executed. (At least I hope)
|
||||
boolean required = CustomEnchantManager.getInstance().isRequirePermissions();
|
||||
if (!required) return true;
|
||||
|
||||
return human.hasPermission("es.enchant.*") || !human.hasPermission(this.enchant.getRequiredPermission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel(@NotNull ItemStack item, @NotNull ItemMeta meta) {
|
||||
return CustomEnchantManager.getInstance().getEnchantStrength(item, this.enchant.getType());
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ object EnchantmentUtil {
|
|||
) = mutableMapOf<WrappedEnchantment, Int>().apply {
|
||||
putAll(this@combineWith)
|
||||
other.forEach { (enchantment, level) ->
|
||||
if(!enchantment.isAllowed(player)) return@forEach
|
||||
|
||||
// Get max level or 255 if player can bypass
|
||||
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission))
|
||||
{ 255 } else
|
||||
|
|
@ -53,7 +55,7 @@ object EnchantmentUtil {
|
|||
}
|
||||
// Enchantment already in result list
|
||||
else {
|
||||
val oldLevel = this[enchantment]!! // should be true, see the comment above
|
||||
val oldLevel = this[enchantment]!! // <- should not be null. see the comment above
|
||||
|
||||
// ... and they are conflicting
|
||||
val conflictType =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue