81 lines
2.9 KiB
Java
81 lines
2.9 KiB
Java
package su.nightexpress.excellentenchants.enchantment.impl.weapon;
|
|
|
|
import org.bukkit.Particle;
|
|
import org.bukkit.Sound;
|
|
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.jetbrains.annotations.NotNull;
|
|
import su.nightexpress.excellentenchants.EnchantsPlugin;
|
|
import su.nightexpress.excellentenchants.api.Modifier;
|
|
import su.nightexpress.excellentenchants.api.enchantment.Rarity;
|
|
import su.nightexpress.excellentenchants.api.enchantment.data.ChanceData;
|
|
import su.nightexpress.excellentenchants.api.enchantment.data.ChanceSettings;
|
|
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
|
|
import su.nightexpress.excellentenchants.enchantment.data.AbstractEnchantmentData;
|
|
import su.nightexpress.excellentenchants.enchantment.data.ChanceSettingsImpl;
|
|
import su.nightexpress.nightcore.config.FileConfig;
|
|
import su.nightexpress.nightcore.util.wrapper.UniParticle;
|
|
import su.nightexpress.nightcore.util.wrapper.UniSound;
|
|
|
|
import java.io.File;
|
|
|
|
import static su.nightexpress.excellentenchants.Placeholders.*;
|
|
|
|
public class DoubleStrikeEnchant extends AbstractEnchantmentData implements ChanceData, CombatEnchant {
|
|
|
|
public static final String ID = "double_strike";
|
|
|
|
private ChanceSettingsImpl chanceSettings;
|
|
|
|
public DoubleStrikeEnchant(@NotNull EnchantsPlugin plugin, @NotNull File file) {
|
|
super(plugin, file);
|
|
this.setDescription(ENCHANTMENT_CHANCE + "% chance to inflict double damage.");
|
|
this.setMaxLevel(4);
|
|
this.setRarity(Rarity.VERY_RARE);
|
|
}
|
|
|
|
@Override
|
|
protected void loadAdditional(@NotNull FileConfig config) {
|
|
this.chanceSettings = ChanceSettingsImpl.create(config, Modifier.add(2, 0.5, 1, 100D));
|
|
}
|
|
|
|
@NotNull
|
|
@Override
|
|
public ChanceSettings getChanceSettings() {
|
|
return chanceSettings;
|
|
}
|
|
|
|
@Override
|
|
@NotNull
|
|
public EnchantmentTarget getCategory() {
|
|
return EnchantmentTarget.WEAPON;
|
|
}
|
|
|
|
@NotNull
|
|
@Override
|
|
public EventPriority getAttackPriority() {
|
|
return EventPriority.HIGHEST;
|
|
}
|
|
|
|
@Override
|
|
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
|
|
if (!this.checkTriggerChance(level)) return false;
|
|
|
|
event.setDamage(event.getDamage() * 2D);
|
|
|
|
if (this.hasVisualEffects()) {
|
|
UniParticle.of(Particle.EXPLOSION_NORMAL).play(victim.getEyeLocation(), 0.25, 0.15, 15);
|
|
UniSound.of(Sound.ENTITY_GENERIC_EXPLODE).play(victim.getLocation());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
|
|
return false;
|
|
}
|
|
}
|