Enchants fixes

This commit is contained in:
nulli0n 2023-02-15 14:50:02 +06:00
parent 6b0f9cdc43
commit 2e4d9b45b7
7 changed files with 11 additions and 8 deletions

View File

@ -433,5 +433,6 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
@Override @Override
public void consumeCharges(@NotNull ItemStack item) { public void consumeCharges(@NotNull ItemStack item) {
EnchantManager.consumeEnchantmentCharges(item, this); EnchantManager.consumeEnchantmentCharges(item, this);
EnchantManager.updateEnchantmentsDisplay(item);
} }
} }

View File

@ -55,7 +55,8 @@ public class Config {
Set.of("enchant_name", "other_enchant"), Set.of("enchant_name", "other_enchant"),
"A list of enchantments, that will be disabled and removed from the game (server).", "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 !", "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<Map<String, Set<String>>> ENCHANTMENTS_DISABLED_IN_WORLDS = new JOption<Map<String, Set<String>>>("Enchantments.Disabled_In_Worlds", public static final JOption<Map<String, Set<String>>> ENCHANTMENTS_DISABLED_IN_WORLDS = new JOption<Map<String, Set<String>>>("Enchantments.Disabled_In_Worlds",
(cfg, path, def) -> cfg.getSection(path).stream().collect(Collectors.toMap(k -> k, worldName -> cfg.getStringSet(path + "." + worldName))), (cfg, path, def) -> cfg.getSection(path).stream().collect(Collectors.toMap(k -> k, worldName -> cfg.getStringSet(path + "." + worldName))),

View File

@ -226,6 +226,7 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
lore.add(0, enchant.getNameFormatted(level, getEnchantmentCharges(meta, enchant))); lore.add(0, enchant.getNameFormatted(level, getEnchantmentCharges(meta, enchant)));
}); });
} }
else sizeReal = 0;
meta.setLore(lore); meta.setLore(lore);
PDCUtil.set(meta, KEY_LORE_SIZE, sizeReal); PDCUtil.set(meta, KEY_LORE_SIZE, sizeReal);

View File

@ -132,6 +132,7 @@ public class EnchantRegrowth extends ExcellentEnchant implements PassiveEnchant,
for (LivingEntity entity : this.getEntities()) { for (LivingEntity entity : this.getEntities()) {
EnchantManager.getEquippedEnchants(entity, EnchantRegrowth.class).forEach((item, enchants) -> { EnchantManager.getEquippedEnchants(entity, EnchantRegrowth.class).forEach((item, enchants) -> {
enchants.forEach((enchant, level) -> { enchants.forEach((enchant, level) -> {
if (enchant.isOutOfCharges(item)) return;
if (enchant.onTrigger(entity, item, level)) { if (enchant.onTrigger(entity, item, level)) {
enchant.consumeCharges(item); enchant.consumeCharges(item);
} }

View File

@ -114,6 +114,7 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan
for (LivingEntity entity : this.getEntities()) { for (LivingEntity entity : this.getEntities()) {
EnchantManager.getEquippedEnchants(entity, EnchantSaturation.class).forEach((item, enchants) -> { EnchantManager.getEquippedEnchants(entity, EnchantSaturation.class).forEach((item, enchants) -> {
enchants.forEach((enchant, level) -> { enchants.forEach((enchant, level) -> {
if (enchant.isOutOfCharges(item)) return;
if (enchant.onTrigger(entity, item, level)) { if (enchant.onTrigger(entity, item, level)) {
enchant.consumeCharges(item); enchant.consumeCharges(item);
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.EffectUtil; import su.nexmedia.engine.utils.EffectUtil;
@ -44,16 +45,13 @@ public class EnchantSurprise extends PotionEnchant implements Chanced, CombatEnc
return EnchantmentTarget.WEAPON; return EnchantmentTarget.WEAPON;
} }
@Override
public PotionEffectType getEffectType() {
return Rnd.get(PotionEffectType.values());
}
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) 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()) { if (this.hasVisualEffects()) {
EffectUtil.playEffect(victim.getEyeLocation(), Particle.SPELL_WITCH, "", 0.25, 0.25, 0.25, 0.1f, 30); EffectUtil.playEffect(victim.getEyeLocation(), Particle.SPELL_WITCH, "", 0.25, 0.25, 0.25, 0.1f, 30);

View File

@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nexmedia</groupId> <groupId>su.nexmedia</groupId>
<artifactId>NexEngine</artifactId> <artifactId>NexEngine</artifactId>
<version>2.2.8</version> <version>2.2.9</version>
</dependency> </dependency>
</dependencies> </dependencies>