From 2e4d9b45b709b419b6dd24b73775393a1d01d1d5 Mon Sep 17 00:00:00 2001 From: nulli0n Date: Wed, 15 Feb 2023 14:50:02 +0600 Subject: [PATCH] Enchants fixes --- .../api/enchantment/ExcellentEnchant.java | 1 + .../nightexpress/excellentenchants/config/Config.java | 3 ++- .../excellentenchants/enchantment/EnchantManager.java | 1 + .../enchantment/impl/armor/EnchantRegrowth.java | 1 + .../enchantment/impl/armor/EnchantSaturation.java | 1 + .../enchantment/impl/weapon/EnchantSurprise.java | 10 ++++------ pom.xml | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java index c1adcc2..0b6f982 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/ExcellentEnchant.java @@ -433,5 +433,6 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme @Override public void consumeCharges(@NotNull ItemStack item) { EnchantManager.consumeEnchantmentCharges(item, this); + EnchantManager.updateEnchantmentsDisplay(item); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java index 69c26f5..4e2b866 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/config/Config.java @@ -55,7 +55,8 @@ public class Config { Set.of("enchant_name", "other_enchant"), "A list of enchantments, that will be disabled and removed from the game (server).", "Enchantment names are the same as enchantment file name in /enchants/ folder. ! Must be in lower_case !", - "Example: To disable 'Explosive Arrows' you need to add 'explosive_arrows' here."); + "Example: To disable 'Explosive Arrows' you need to add 'explosive_arrows' here.") + .mapReader(set -> set.stream().map(String::toLowerCase).collect(Collectors.toSet())); public static final JOption>> ENCHANTMENTS_DISABLED_IN_WORLDS = new JOption>>("Enchantments.Disabled_In_Worlds", (cfg, path, def) -> cfg.getSection(path).stream().collect(Collectors.toMap(k -> k, worldName -> cfg.getStringSet(path + "." + worldName))), diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java index e50b469..b37052d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java @@ -226,6 +226,7 @@ public class EnchantManager extends AbstractManager { lore.add(0, enchant.getNameFormatted(level, getEnchantmentCharges(meta, enchant))); }); } + else sizeReal = 0; meta.setLore(lore); PDCUtil.set(meta, KEY_LORE_SIZE, sizeReal); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java index 95cebf0..6a4c363 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java @@ -132,6 +132,7 @@ public class EnchantRegrowth extends ExcellentEnchant implements PassiveEnchant, for (LivingEntity entity : this.getEntities()) { EnchantManager.getEquippedEnchants(entity, EnchantRegrowth.class).forEach((item, enchants) -> { enchants.forEach((enchant, level) -> { + if (enchant.isOutOfCharges(item)) return; if (enchant.onTrigger(entity, item, level)) { enchant.consumeCharges(item); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java index a446ee9..47a898b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java @@ -114,6 +114,7 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan for (LivingEntity entity : this.getEntities()) { EnchantManager.getEquippedEnchants(entity, EnchantSaturation.class).forEach((item, enchants) -> { enchants.forEach((enchant, level) -> { + if (enchant.isOutOfCharges(item)) return; if (enchant.onTrigger(entity, item, level)) { enchant.consumeCharges(item); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java index 53b2ccc..1805410 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantSurprise.java @@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.EffectUtil; @@ -44,16 +45,13 @@ public class EnchantSurprise extends PotionEnchant implements Chanced, CombatEnc return EnchantmentTarget.WEAPON; } - @Override - public PotionEffectType getEffectType() { - return Rnd.get(PotionEffectType.values()); - } - @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (!this.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; - if (!this.addEffect(victim, level)) return false; + + PotionEffect effect = new PotionEffect(Rnd.get(PotionEffectType.values()), this.getEffectDuration(level), Math.max(0, this.getEffectAmplifier(level) - 1), false, false); + if (!victim.addPotionEffect(effect)) return false; if (this.hasVisualEffects()) { EffectUtil.playEffect(victim.getEyeLocation(), Particle.SPELL_WITCH, "", 0.25, 0.25, 0.25, 0.1f, 30); diff --git a/pom.xml b/pom.xml index 49c6380..0a5669b 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ su.nexmedia NexEngine - 2.2.8 + 2.2.9