mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Added level clamp option
This commit is contained in:
parent
1120f8455b
commit
38737de455
@ -241,4 +241,58 @@ public class ItemConversions extends PluginDependent implements Listener {
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* On player hold item.
|
||||
* <p>
|
||||
* Listener for hide fixer.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void levelClamp(@NotNull final PlayerItemHeldEvent event) {
|
||||
if (!this.getPlugin().getConfigYml().getBool("advanced.level-clamp.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlayer().hasPermission("ecoenchants.bypasslevelclamp")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = event.getPlayer().getInventory().getItem(event.getNewSlot());
|
||||
|
||||
clampItemLevels(itemStack);
|
||||
}
|
||||
|
||||
private void clampItemLevels(@Nullable final ItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
new HashMap<>(((EnchantmentStorageMeta) meta).getStoredEnchants()).forEach((enchantment, integer) -> {
|
||||
if (integer > enchantment.getMaxLevel()) {
|
||||
((EnchantmentStorageMeta) meta).removeStoredEnchant(enchantment);
|
||||
((EnchantmentStorageMeta) meta).addStoredEnchant(enchantment, enchantment.getMaxLevel(), true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
new HashMap<>(meta.getEnchants()).forEach((enchantment, integer) -> {
|
||||
if (integer > enchantment.getMaxLevel()) {
|
||||
meta.removeEnchant(enchantment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
@ -135,4 +135,10 @@ advanced:
|
||||
# Fixes potential plugin conflicts/serialization issues when updating from a version before 7.3.0.
|
||||
# Registers byName both the internal enchantment name (new method) and the display name (old method).
|
||||
# There may be potential bugs with having duplicate enchantments, so enable this only if you need it.
|
||||
enabled: true
|
||||
level-clamp:
|
||||
# Helps reverse players who have illegal above-max-level enchantments.
|
||||
# Any enchantments above their max level will be set to the max level in order to prevent illegal items.
|
||||
# Players with ecoenchants.bypasslevelclamp permission will be ignored.
|
||||
# This may impact performance.
|
||||
enabled: true
|
@ -53,6 +53,7 @@ permissions:
|
||||
ecoenchants.randomenchant: true
|
||||
ecoenchants.randomenchant.bypasshardcap: true
|
||||
ecoenchants.randombook: true
|
||||
ecoenchants.bypasslevelclamp: true
|
||||
ecoenchants.anvil.*: true
|
||||
ecoenchants.anvil.*:
|
||||
description: Allows all anvil permissions
|
||||
@ -94,6 +95,9 @@ permissions:
|
||||
ecoenchants.anvil.color:
|
||||
description: Allows color from anvil renames
|
||||
default: op
|
||||
ecoenchants.bypasslevelclamp:
|
||||
description: Allows bypassing the advanced level clamp option
|
||||
default: op
|
||||
|
||||
# Perks
|
||||
ecoenchants.cooldowntime.half:
|
||||
|
Loading…
Reference in New Issue
Block a user