From 8c83be123f3ad734a70f697e4521b21ca6cb1044 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 7 May 2021 19:07:16 +0100 Subject: [PATCH 1/9] Fixed formatting --- .../enchantments/ecoenchants/special/Volatile.java | 1 + eco-core/core-plugin/src/main/resources/vanillaenchants.yml | 2 +- .../main/java/com/willfp/ecoenchants/firewand/Firewand.java | 4 ++-- .../xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java | 4 ++-- gradle.properties | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java index 69afafde..b819b5f4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java @@ -1,4 +1,5 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; + import com.willfp.eco.core.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; diff --git a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml index 7b3facb6..0877ad6e 100644 --- a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml +++ b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml @@ -14,4 +14,4 @@ enabled: false # There may be potential conflicts if modifying vanilla enchantme # Currently, it is *not* possible to modify the enchantment levels from enchanting tables. # It will work with anvils however, but since it is still possible to get enchantments at their vanilla # max levels, then it isn't recommended to lower the max level of a vanilla enchantment, only to raise it. -max-levels: [] \ No newline at end of file +max-levels: [ ] \ No newline at end of file diff --git a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java index 3243550a..be98c1bc 100644 --- a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java +++ b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java @@ -19,8 +19,8 @@ public class Firewand extends Spell { @Override public boolean onUse(@NotNull final Player player, - final int level, - @NotNull final PlayerInteractEvent event) { + final int level, + @NotNull final PlayerInteractEvent event) { SmallFireball fireball = player.launchProjectile(SmallFireball.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity"))); fireball.setIsIncendiary(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire")); fireball.setMetadata("eco-damage", this.getPlugin().getMetadataValueFactory().create(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level)); diff --git a/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java b/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java index 248c539b..24ba6e1f 100644 --- a/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java +++ b/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java @@ -32,8 +32,8 @@ public class Xray extends Spell { @Override public boolean onUse(@NotNull final Player player, - final int level, - @NotNull final PlayerInteractEvent event) { + final int level, + @NotNull final PlayerInteractEvent event) { Block block = event.getClickedBlock(); if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { diff --git a/gradle.properties b/gradle.properties index 4eb8946c..d9612af7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 7.3.7 -plugin-name = EcoEnchants \ No newline at end of file +version=7.3.7 +plugin-name=EcoEnchants \ No newline at end of file From 1120f8455bb2c51fd7eac60f6efc90d9b531713e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 7 May 2021 19:07:38 +0100 Subject: [PATCH 2/9] Fixed formatting --- .../enchantments/ecoenchants/special/Volatile.java | 1 - eco-core/core-plugin/src/main/resources/vanillaenchants.yml | 2 +- .../main/java/com/willfp/ecoenchants/firewand/Firewand.java | 4 ++-- .../xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java | 4 ++-- gradle.properties | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java index b819b5f4..69afafde 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java @@ -1,5 +1,4 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.special; - import com.willfp.eco.core.integrations.antigrief.AntigriefManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; diff --git a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml index 0877ad6e..7b3facb6 100644 --- a/eco-core/core-plugin/src/main/resources/vanillaenchants.yml +++ b/eco-core/core-plugin/src/main/resources/vanillaenchants.yml @@ -14,4 +14,4 @@ enabled: false # There may be potential conflicts if modifying vanilla enchantme # Currently, it is *not* possible to modify the enchantment levels from enchanting tables. # It will work with anvils however, but since it is still possible to get enchantments at their vanilla # max levels, then it isn't recommended to lower the max level of a vanilla enchantment, only to raise it. -max-levels: [ ] \ No newline at end of file +max-levels: [] \ No newline at end of file diff --git a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java index be98c1bc..3243550a 100644 --- a/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java +++ b/eco-extensions/firewand/src/main/java/com/willfp/ecoenchants/firewand/Firewand.java @@ -19,8 +19,8 @@ public class Firewand extends Spell { @Override public boolean onUse(@NotNull final Player player, - final int level, - @NotNull final PlayerInteractEvent event) { + final int level, + @NotNull final PlayerInteractEvent event) { SmallFireball fireball = player.launchProjectile(SmallFireball.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity"))); fireball.setIsIncendiary(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire")); fireball.setMetadata("eco-damage", this.getPlugin().getMetadataValueFactory().create(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level)); diff --git a/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java b/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java index 24ba6e1f..248c539b 100644 --- a/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java +++ b/eco-extensions/xray/src/main/java/com/willfp/ecoenchants/xray/Xray.java @@ -32,8 +32,8 @@ public class Xray extends Spell { @Override public boolean onUse(@NotNull final Player player, - final int level, - @NotNull final PlayerInteractEvent event) { + final int level, + @NotNull final PlayerInteractEvent event) { Block block = event.getClickedBlock(); if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { diff --git a/gradle.properties b/gradle.properties index d9612af7..4eb8946c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=7.3.7 -plugin-name=EcoEnchants \ No newline at end of file +version = 7.3.7 +plugin-name = EcoEnchants \ No newline at end of file From 38737de455ec3667328749e432c7085d1245bea5 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 7 May 2021 19:17:26 +0100 Subject: [PATCH 3/9] Added level clamp option --- .../enchantments/util/ItemConversions.java | 54 +++++++++++++++++++ .../core-plugin/src/main/resources/config.yml | 6 +++ .../core-plugin/src/main/resources/plugin.yml | 4 ++ 3 files changed, 64 insertions(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java index a1f4917d..35ca6163 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java @@ -241,4 +241,58 @@ public class ItemConversions extends PluginDependent implements Listener { itemStack.setItemMeta(meta); } + + /** + * On player hold item. + *

+ * 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); + } } diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 3bd446ce..a3f5eb91 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -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 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index f77ed52e..c80a8791 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -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: From 62a05a3c211716ed45f85906c81ddabd80f339a8 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 7 May 2021 19:17:43 +0100 Subject: [PATCH 4/9] Added level clamp option --- eco-core/core-plugin/src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index a3f5eb91..0ce6c2b9 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -138,7 +138,7 @@ advanced: 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. + # 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: true \ No newline at end of file From 265a52c8015d32214ba431cce48c1770aecdf8f6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 7 May 2021 19:17:53 +0100 Subject: [PATCH 5/9] Updated to 7.4.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4eb8946c..49941794 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 7.3.7 +version = 7.4.0 plugin-name = EcoEnchants \ No newline at end of file From b556980bc074f84326f7efe5ce4ea9f175f8fbbd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 9 May 2021 12:22:13 +0100 Subject: [PATCH 6/9] Disabled level-clamp by default --- eco-core/core-plugin/src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 0ce6c2b9..19751835 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -141,4 +141,4 @@ advanced: # 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: true \ No newline at end of file + enabled: false \ No newline at end of file From 7303c6b2de14f22b04513ccf42414a4d60dd5fa1 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 9 May 2021 12:22:32 +0100 Subject: [PATCH 7/9] Updated to 7.4.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 49941794..5f1c2148 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 7.4.0 +version = 7.4.1 plugin-name = EcoEnchants \ No newline at end of file From bb3f89731247b17e9fafd8198f6b323c89f3f513 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 11 May 2021 21:14:09 +0100 Subject: [PATCH 8/9] Fixed rare NPE --- .../enchantments/support/obtaining/EnchantingListeners.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index 58f6b2bb..27986283 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -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()) { From 6cf042c3adf5a2f6e63ae21f61a4aa1e7c4881f4 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 11 May 2021 21:14:18 +0100 Subject: [PATCH 9/9] Updated to 7.4.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5f1c2148..89354aa2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 7.4.1 +version = 7.4.2 plugin-name = EcoEnchants \ No newline at end of file