mirror of
https://github.com/songoda/EpicEnchants.git
synced 2024-12-23 01:27:43 +01:00
Added the permission checks for max enchantments to apply.
New Permission: enchants.maxallowed.# of enchants they can apply New Locale: enchants.maxallowed
This commit is contained in:
parent
a40ddd325b
commit
fc7ffefc2a
@ -9,6 +9,7 @@ import com.songoda.epicenchants.utils.Tuple;
|
||||
import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -37,6 +38,16 @@ public class BookListener extends ItemListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// get total amount of enchantments on item
|
||||
int currentEnchantmentTotal = instance.getEnchantUtils().getEnchants(toApply).size();
|
||||
int maxAllowedApply = instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
|
||||
|
||||
// item is at max enchantments
|
||||
if (currentEnchantmentTotal >= maxAllowedApply) {
|
||||
instance.getLocale().getMessage("enchants.maxallowed").processPlaceholder("max_enchants", maxAllowedApply).sendPrefixedMessage(event.getWhoClicked());
|
||||
return;
|
||||
}
|
||||
|
||||
int level = cursor.getInteger("level");
|
||||
int successRate = cursor.getInteger("success-rate");
|
||||
int destroyRate = cursor.getInteger("destroy-rate");
|
||||
|
@ -11,11 +11,13 @@ import com.songoda.epicenchants.utils.itemnbtapi.NBTItem;
|
||||
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
||||
import com.songoda.epicenchants.utils.settings.Settings;
|
||||
import com.songoda.epicenchants.utils.single.GeneralUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -141,4 +143,20 @@ public class EnchantUtils {
|
||||
output.removeLore(TextUtils.formatText(text));
|
||||
return output.build();
|
||||
}
|
||||
|
||||
public int getMaximumEnchantsCanApply(Player p) {
|
||||
int max = 0;
|
||||
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
|
||||
for (PermissionAttachmentInfo effectivePermission : p.getEffectivePermissions()) {
|
||||
if (!effectivePermission.getPermission().startsWith("epicenchants.maxapply.")) continue;
|
||||
|
||||
String node[] = effectivePermission.getPermission().split("\\.");
|
||||
|
||||
if (Methods.isInt(node[node.length - 1])) {
|
||||
int num = Integer.parseInt(node[node.length - 1]);
|
||||
if (num > max) max = num;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
@ -63,5 +63,6 @@ enchants:
|
||||
alreadyapplied: '&cYou already have that enchant applied on this item.'
|
||||
protected: '&7This book would have broken your item, luckily it was protected!'
|
||||
success: '&7You have successfully applied &6{enchant}&r&7.'
|
||||
maxallowed: '&cYou cannot apply more than &4{max_enchants} &cenchants!'
|
||||
book:
|
||||
discover: '&7You examine the &6{group_color}{group_name} &7Enchantment Book, and discover &6{enchant_format}&7!'
|
||||
|
Loading…
Reference in New Issue
Block a user