Merge remote-tracking branch 'origin/master'

This commit is contained in:
Auxilor 2021-05-15 17:10:02 +01:00
commit fcb7a45302
5 changed files with 69 additions and 3 deletions

View File

@ -204,7 +204,9 @@ public class EnchantingListeners extends PluginDependent implements Listener {
// Ew
this.getPlugin().getScheduler().runLater(() -> {
ItemStack item0 = event.getInventory().getItem(0);
assert item0 != null;
if (item0 == null) {
return;
}
if (item0.getItemMeta() instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item0.getItemMeta();
for (Enchantment enchantment : meta.getStoredEnchants().keySet()) {

View File

@ -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);
}
}

View File

@ -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
enabled: true
level-clamp:
# Helps reverse players who have illegal above-max-level enchantments.
# When holding an item, 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: false

View File

@ -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:

View File

@ -1,2 +1,2 @@
version = 7.3.7
version = 7.4.2
plugin-name = EcoEnchants