package su.nightexpress.excellentenchants.enchantment.impl.armor; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; public class HardenedEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { public static final String ID = "hardened"; private ChanceImplementation chanceImplementation; private PotionImplementation potionImplementation; public HardenedEnchant(@NotNull ExcellentEnchants plugin) { super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) when damaged."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.4); } @Override public void loadSettings() { super.loadSettings(); this.chanceImplementation = ChanceImplementation.create(this, "30.0 * " + Placeholders.ENCHANTMENT_LEVEL); this.potionImplementation = PotionImplementation.create(this, PotionEffectType.DAMAGE_RESISTANCE, false, "3.0" + Placeholders.ENCHANTMENT_LEVEL, Placeholders.ENCHANTMENT_LEVEL); } @NotNull @Override public ChanceImplementation getChanceImplementation() { return chanceImplementation; } @NotNull @Override public PotionImplementation getPotionImplementation() { return potionImplementation; } @Override @NotNull public EnchantmentTarget getCategory() { return EnchantmentTarget.ARMOR_TORSO; } @NotNull @Override public EventPriority getProtectPriority() { return EventPriority.HIGHEST; } @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { return false; } @Override public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (!this.checkTriggerChance(level)) return false; return this.addEffect(victim, level); } }