This commit is contained in:
BuildTools 2023-10-03 21:14:27 +05:00
parent eeef240e49
commit 7e58a21e32
36 changed files with 439 additions and 44 deletions

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -76,32 +76,32 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_17_R1</artifactId> <artifactId>V1_17_R1</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_18_R2</artifactId> <artifactId>V1_18_R2</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R3</artifactId> <artifactId>V1_19_R3</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R1</artifactId> <artifactId>V1_20_R1</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R2</artifactId> <artifactId>V1_20_R2</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -12,7 +12,7 @@ public interface DeathEnchant extends IEnchantment {
boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level); boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level);
boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level); boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level);
@NotNull @NotNull
default EventPriority getDeathPriority() { default EventPriority getDeathPriority() {

View File

@ -77,7 +77,7 @@ public class KamikadzeEnchant extends ExcellentEnchant implements Chanced, Death
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
return false; return false;
} }

View File

@ -37,7 +37,7 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)"); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1); this.getDefaults().setTier(0.1);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -37,7 +37,7 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)"); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1); this.getDefaults().setTier(0.1);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -50,7 +50,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an dragonfire arrow (R=" + PLACEHOLDER_FIRE_RADIUS + ", " + PLACEHOLDER_FIRE_DURATION + "s)."); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an dragonfire arrow (R=" + PLACEHOLDER_FIRE_RADIUS + ", " + PLACEHOLDER_FIRE_DURATION + "s).");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7); this.getDefaults().setTier(0.7);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -41,7 +41,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an electrified arrow."); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an electrified arrow.");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3); this.getDefaults().setTier(0.3);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -33,7 +33,7 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
EnchantBomber.ID, EnchantGhast.ID, EnchantBomber.ID, EnchantGhast.ID,
EnchantExplosiveArrows.ID, EnchantPoisonedArrows.ID, EnchantConfusingArrows.ID, EnchantExplosiveArrows.ID, EnchantPoisonedArrows.ID, EnchantConfusingArrows.ID,
EnchantWitheredArrows.ID, EnchantElectrifiedArrows.ID, EnchantDragonfireArrows.ID, EnchantWitheredArrows.ID, EnchantElectrifiedArrows.ID, EnchantDragonfireArrows.ID,
DarknessArrowsEnchant.ID, DarknessArrowsEnchant.ID, VampiricArrowsEnchant.ID,
EnchantHover.ID, FlareEnchant.ID, EnchantHover.ID, FlareEnchant.ID,
Enchantment.ARROW_FIRE.getKey().getKey(), Enchantment.ARROW_FIRE.getKey().getKey(),
Enchantment.ARROW_KNOCKBACK.getKey().getKey(), Enchantment.ARROW_KNOCKBACK.getKey().getKey(),

View File

@ -45,7 +45,7 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an explosive arrow."); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an explosive arrow.");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7); this.getDefaults().setTier(0.7);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -40,7 +40,7 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
EnchantEnderBow.ID, EnchantBomber.ID, EnchantEnderBow.ID, EnchantBomber.ID,
EnchantExplosiveArrows.ID, EnchantPoisonedArrows.ID, EnchantConfusingArrows.ID, EnchantExplosiveArrows.ID, EnchantPoisonedArrows.ID, EnchantConfusingArrows.ID,
EnchantWitheredArrows.ID, EnchantElectrifiedArrows.ID, EnchantDragonfireArrows.ID, EnchantWitheredArrows.ID, EnchantElectrifiedArrows.ID, EnchantDragonfireArrows.ID,
DarknessArrowsEnchant.ID, DarknessArrowsEnchant.ID, VampiricArrowsEnchant.ID,
EnchantHover.ID, FlareEnchant.ID, EnchantHover.ID, FlareEnchant.ID,
Enchantment.ARROW_FIRE.getKey().getKey(), Enchantment.ARROW_FIRE.getKey().getKey(),
Enchantment.ARROW_KNOCKBACK.getKey().getKey(), Enchantment.ARROW_KNOCKBACK.getKey().getKey(),

View File

@ -37,7 +37,7 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)"); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1); this.getDefaults().setTier(0.1);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -37,7 +37,7 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)"); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1); this.getDefaults().setTier(0.1);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -37,7 +37,7 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)"); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5); this.getDefaults().setTier(0.5);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantHover.ID, EnchantBomber.ID); this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
} }
@Override @Override

View File

@ -0,0 +1,125 @@
package su.nightexpress.excellentenchants.enchantment.impl.bow;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.EntityUtil;
import su.nexmedia.engine.utils.NumberUtil;
import su.nexmedia.engine.utils.values.UniParticle;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
public class VampiricArrowsEnchant extends ExcellentEnchant implements BowEnchant, Arrowed, Chanced {
public static final String ID = "vampiric_arrows";
public static final String PLACEHOLDER_HEAL_AMOUNT = "%heal_amount%";
private ArrowImplementation arrowImplementation;
private ChanceImplementation chanceImplementation;
private EnchantScaler healAmount;
public VampiricArrowsEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to restore " + PLACEHOLDER_HEAL_AMOUNT + "❤ on arrow hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
this.getDefaults().setConflicts(EnchantEnderBow.ID, EnchantGhast.ID, EnchantBomber.ID);
}
@Override
public void loadSettings() {
super.loadSettings();
this.arrowImplementation = ArrowImplementation.create(this, UniParticle.redstone(Color.RED, 1f));
this.chanceImplementation = ChanceImplementation.create(this, "20.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.healAmount = EnchantScaler.read(this, "Settings.Heal_Amount",
Placeholders.ENCHANTMENT_LEVEL,
"Amount of health to be restored on hit.");
this.addPlaceholder(PLACEHOLDER_HEAL_AMOUNT, level -> NumberUtil.format(this.getHealAmount(level)));
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.BOW;
}
@NotNull
@Override
public Arrowed getArrowImplementation() {
return this.arrowImplementation;
}
@NotNull
@Override
public Chanced getChanceImplementation() {
return this.chanceImplementation;
}
public double getHealAmount(int level) {
return this.healAmount.getValue(level);
}
@NotNull
@Override
public EventPriority getDamagePriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
this.addData(arrow);
return true;
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
double healAmount = this.getHealAmount(level);
if (healAmount <= 0D) return false;
double health = shooter.getHealth();
double maxHealth = EntityUtil.getAttribute(shooter, Attribute.GENERIC_MAX_HEALTH);
if (health >= maxHealth) return false;
EntityRegainHealthEvent healthEvent = new EntityRegainHealthEvent(shooter, healAmount, EntityRegainHealthEvent.RegainReason.CUSTOM);
plugin.getPluginManager().callEvent(healthEvent);
if (healthEvent.isCancelled()) return false;
shooter.setHealth(Math.min(maxHealth, health + healAmount));
if (this.hasVisualEffects()) {
UniParticle.of(Particle.HEART).play(shooter.getEyeLocation(), 0.25f, 0.15f, 5);
}
return false;
}
}

View File

@ -88,7 +88,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
event.getDrops().forEach(stack -> { event.getDrops().forEach(stack -> {

View File

@ -95,7 +95,7 @@ public class CurseOfMisfortuneEnchant extends ExcellentEnchant implements Chance
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
event.getDrops().clear(); event.getDrops().clear();

View File

@ -0,0 +1,97 @@
package su.nightexpress.excellentenchants.enchantment.impl.universal;
import org.bukkit.Sound;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.NumberUtil;
import su.nexmedia.engine.utils.values.UniSound;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class RestoreEnchant extends ExcellentEnchant implements GenericEnchant, Chanced, EventListener {
public static final String ID = "restore";
public static final String PLACEHOLDER_DURABILITY_RESTORE = "%durability_restore%";
private ChanceImplementation chanceImplementation;
private EnchantScaler durabilityRestore;
public RestoreEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to save item from breaking back to " + PLACEHOLDER_DURABILITY_RESTORE + "%");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.6);
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this,
"35.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 8");
this.durabilityRestore = EnchantScaler.read(this, "Settings.Durability_Restoration",
"25.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 5",
"Amount of durability (in percent of item max) to be restored.");
this.addPlaceholder(PLACEHOLDER_DURABILITY_RESTORE, level -> NumberUtil.format(this.getDurabilityRestore(level)));
}
@NotNull
@Override
public ChanceImplementation getChanceImplementation() {
return chanceImplementation;
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.BREAKABLE;
}
public double getDurabilityRestore(int level) {
return this.durabilityRestore.getValue(level);
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemDamage(PlayerItemDamageEvent event) {
ItemStack item = event.getItem();
if (!(item.getItemMeta() instanceof Damageable damageable)) return;
int damage = event.getDamage();
int maxDurability = item.getType().getMaxDurability();
if (damageable.getDamage() + damage < maxDurability) return;
int level = EnchantUtils.getLevel(item, this);
if (level <= 0) return;
if (this.isOutOfCharges(item)) return;
if (!this.checkTriggerChance(level)) return;
event.setCancelled(true);
this.consumeChargesNoUpdate(item, level);
double restorePercent = 100D - this.getDurabilityRestore(level);
int restored = (int) (maxDurability * (restorePercent / 100D));
damageable.setDamage(restored);
item.setItemMeta(damageable);
EnchantUtils.remove(item, this);
if (this.hasVisualEffects()) {
UniSound.of(Sound.ITEM_TOTEM_USE).play(event.getPlayer());
}
}
}

View File

@ -0,0 +1,66 @@
package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
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.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
public class CurseOfDeathEnchant extends ExcellentEnchant implements DeathEnchant, Chanced {
public static final String ID = "curse_of_death";
private ChanceImplementation chanceImplementation;
public CurseOfDeathEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("When killing players, you have a chance of dying too.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0D);
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, Placeholders.ENCHANTMENT_LEVEL + " * 0.1");
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public Chanced getChanceImplementation() {
return this.chanceImplementation;
}
@Override
public boolean isCursed() {
return true;
}
@Override
public boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level) {
return false;
}
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
if (!(entity instanceof Player dead)) return false;
if (!this.checkTriggerChance(level)) return false;
killer.setHealth(0D);
return true;
}
}

View File

@ -183,7 +183,7 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
EntityType entityType = entity.getType(); EntityType entityType = entity.getType();
if (this.ignoredEntityTypes.contains(entityType)) return false; if (this.ignoredEntityTypes.contains(entityType)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;

View File

@ -48,7 +48,7 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant {
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
double expModifier = this.getExpModifier(level); double expModifier = this.getExpModifier(level);
double expFinal = Math.ceil((double) event.getDroppedExp() * expModifier); double expFinal = Math.ceil((double) event.getDroppedExp() * expModifier);

View File

@ -52,7 +52,7 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
event.getDrops().forEach(item -> PlayerUtil.addItem(killer, item)); event.getDrops().forEach(item -> PlayerUtil.addItem(killer, item));

View File

@ -98,7 +98,7 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
Map<Material, Pair<int[], Double>> items = this.loot.get(entity.getType()); Map<Material, Pair<int[], Double>> items = this.loot.get(entity.getType());
if (items == null) return false; if (items == null) return false;

View File

@ -80,7 +80,7 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
} }
@Override @Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, ItemStack weapon, int level) {
if (this.ignoredEntityTypes.contains(entity.getType())) return false; if (this.ignoredEntityTypes.contains(entity.getType())) return false;
if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false; if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;

View File

@ -0,0 +1,100 @@
package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
public class SwiperEnchant extends ExcellentEnchant implements CombatEnchant, Chanced {
public static final String ID = "swiper";
public static final String PLACEHOLER_XP_AMOUNT = "%xp_amount%";
private ChanceImplementation chanceImplementation;
private EnchantScaler xpAmount;
public SwiperEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to steal " + PLACEHOLER_XP_AMOUNT + " XP from players.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7);
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this,
"5.0 + " + Placeholders.ENCHANTMENT_LEVEL + " * 2.5");
this.xpAmount = EnchantScaler.read(this, "Settings.XP_Amount",
Placeholders.ENCHANTMENT_LEVEL,
"Amount of XP to be stolen on hit.");
this.addPlaceholder(PLACEHOLER_XP_AMOUNT, level -> NumberUtil.format(this.getXPAmount(level)));
}
@NotNull
@Override
public EnchantmentTarget getItemTarget() {
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public Chanced getChanceImplementation() {
return this.chanceImplementation;
}
public int getXPAmount(int level) {
return (int) this.xpAmount.getValue(level);
}
private int getExpRequired(int level) {
if (level <= 15) return 2 * level + 7;
if (level <= 30) return 5 * level - 38;
return 9 * level - 158;
}
private void addXP(@NotNull Player player, int amount) {
int levelHas = player.getLevel();
int xpHas = player.getTotalExperience();
xpHas = Math.max(0, xpHas - amount);
player.setExp(0F);
player.setTotalExperience(0);
player.setLevel(0);
player.giveExp(xpHas);
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!(damager instanceof Player attacker)) return false;
if (!(victim instanceof Player defender)) return false;
if (defender.getTotalExperience() == 0) return false;
if (!this.checkTriggerChance(level)) return false;
int amount = this.getXPAmount(level);
if (defender.getTotalExperience() < amount) amount = defender.getTotalExperience();
this.addXP(defender, -amount);
this.addXP(attacker, amount);
return true;
}
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false;
}
}

View File

@ -44,9 +44,11 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
} }
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR)
public void onEnchantProjectileLand(ProjectileHitEvent event) { public void onEnchantProjectileLand(ProjectileHitEvent event) {
EnchantUtils.removeSourceWeapon(event.getEntity()); this.plugin.runTask(task -> {
EnchantUtils.removeSourceWeapon(event.getEntity());
});
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------

View File

@ -27,6 +27,7 @@ import su.nightexpress.excellentenchants.enchantment.impl.bow.*;
import su.nightexpress.excellentenchants.enchantment.impl.fishing.*; import su.nightexpress.excellentenchants.enchantment.impl.fishing.*;
import su.nightexpress.excellentenchants.enchantment.impl.tool.*; import su.nightexpress.excellentenchants.enchantment.impl.tool.*;
import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant; import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.universal.RestoreEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.universal.SoulboundEnchant; import su.nightexpress.excellentenchants.enchantment.impl.universal.SoulboundEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.weapon.*; import su.nightexpress.excellentenchants.enchantment.impl.weapon.*;
import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGather; import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGather;
@ -106,6 +107,7 @@ public class EnchantRegistry extends AbstractManager<ExcellentEnchants> {
this.register(EnchantBlindness.ID, () -> new EnchantBlindness(plugin)); this.register(EnchantBlindness.ID, () -> new EnchantBlindness(plugin));
this.register(EnchantConfusion.ID, () -> new EnchantConfusion(plugin)); this.register(EnchantConfusion.ID, () -> new EnchantConfusion(plugin));
this.register(EnchantCutter.ID, () -> new EnchantCutter(plugin)); this.register(EnchantCutter.ID, () -> new EnchantCutter(plugin));
this.register(CurseOfDeathEnchant.ID, () -> new CurseOfDeathEnchant(plugin));
this.register(EnchantDecapitator.ID, () -> new EnchantDecapitator(plugin)); this.register(EnchantDecapitator.ID, () -> new EnchantDecapitator(plugin));
this.register(EnchantDoubleStrike.ID, () -> new EnchantDoubleStrike(plugin)); this.register(EnchantDoubleStrike.ID, () -> new EnchantDoubleStrike(plugin));
this.register(EnchantExhaust.ID, () -> new EnchantExhaust(plugin)); this.register(EnchantExhaust.ID, () -> new EnchantExhaust(plugin));
@ -119,6 +121,7 @@ public class EnchantRegistry extends AbstractManager<ExcellentEnchants> {
this.register(EnchantRocket.ID, () -> new EnchantRocket(plugin)); this.register(EnchantRocket.ID, () -> new EnchantRocket(plugin));
this.register(EnchantScavenger.ID, () -> new EnchantScavenger(plugin)); this.register(EnchantScavenger.ID, () -> new EnchantScavenger(plugin));
this.register(EnchantSurprise.ID, () -> new EnchantSurprise(plugin)); this.register(EnchantSurprise.ID, () -> new EnchantSurprise(plugin));
this.register(SwiperEnchant.ID, () -> new SwiperEnchant(plugin));
this.register(EnchantTemper.ID, () -> new EnchantTemper(plugin)); this.register(EnchantTemper.ID, () -> new EnchantTemper(plugin));
this.register(EnchantThrifty.ID, () -> new EnchantThrifty(plugin)); this.register(EnchantThrifty.ID, () -> new EnchantThrifty(plugin));
this.register(EnchantThunder.ID, () -> new EnchantThunder(plugin)); this.register(EnchantThunder.ID, () -> new EnchantThunder(plugin));
@ -155,6 +158,7 @@ public class EnchantRegistry extends AbstractManager<ExcellentEnchants> {
this.register(EnchantHover.ID, () -> new EnchantHover(plugin)); this.register(EnchantHover.ID, () -> new EnchantHover(plugin));
this.register(SniperEnchant.ID, () -> new SniperEnchant(plugin)); this.register(SniperEnchant.ID, () -> new SniperEnchant(plugin));
this.register(EnchantPoisonedArrows.ID, () -> new EnchantPoisonedArrows(plugin)); this.register(EnchantPoisonedArrows.ID, () -> new EnchantPoisonedArrows(plugin));
this.register(VampiricArrowsEnchant.ID, () -> new VampiricArrowsEnchant(plugin));
this.register(EnchantWitheredArrows.ID, () -> new EnchantWitheredArrows(plugin)); this.register(EnchantWitheredArrows.ID, () -> new EnchantWitheredArrows(plugin));
if (Version.isAbove(Version.V1_18_R2)) { if (Version.isAbove(Version.V1_18_R2)) {
this.register(DarknessArrowsEnchant.ID, () -> new DarknessArrowsEnchant(plugin)); this.register(DarknessArrowsEnchant.ID, () -> new DarknessArrowsEnchant(plugin));
@ -165,6 +169,7 @@ public class EnchantRegistry extends AbstractManager<ExcellentEnchants> {
this.register(CurseOfFragilityEnchant.ID, () -> new CurseOfFragilityEnchant(plugin)); this.register(CurseOfFragilityEnchant.ID, () -> new CurseOfFragilityEnchant(plugin));
this.register(CurseOfMediocrityEnchant.ID, () -> new CurseOfMediocrityEnchant(plugin)); this.register(CurseOfMediocrityEnchant.ID, () -> new CurseOfMediocrityEnchant(plugin));
this.register(SoulboundEnchant.ID, () -> new SoulboundEnchant(plugin)); this.register(SoulboundEnchant.ID, () -> new SoulboundEnchant(plugin));
this.register(RestoreEnchant.ID, () -> new RestoreEnchant(plugin));
Enchantment.stopAcceptingRegistrations(); Enchantment.stopAcceptingRegistrations();
this.plugin.info("Enchantments Registered: " + EnchantRegistry.getRegistered().size()); this.plugin.info("Enchantments Registered: " + EnchantRegistry.getRegistered().size());

View File

@ -267,10 +267,9 @@ public class DataGathers {
@Override @Override
public boolean useEnchant(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull DeathEnchant enchant, int level) { public boolean useEnchant(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull DeathEnchant enchant, int level) {
Player killer = entity.getKiller(); if (!(entity instanceof Player killer)) return false;
if (killer == null) return false;
return enchant.onKill(event, entity, killer, level); // TODO item? return enchant.onKill(event, event.getEntity(), killer, item, level);
} }
}; };

View File

@ -1,5 +1,6 @@
package su.nightexpress.excellentenchants.enchantment.registry.wrapper; package su.nightexpress.excellentenchants.enchantment.registry.wrapper;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;

View File

@ -239,7 +239,7 @@ public class EnchantUtils {
public static void consumeCharges(@NotNull ItemStack item, @NotNull ExcellentEnchant enchant, int level) { public static void consumeCharges(@NotNull ItemStack item, @NotNull ExcellentEnchant enchant, int level) {
int has = getCharges(item, enchant); int has = getCharges(item, enchant);
int use = enchant.getChargesConsumeAmount(level); int use = enchant.getChargesConsumeAmount(level);
setCharges(item, enchant, level,has < use ? 0 : has - use); setCharges(item, enchant, level, has < use ? 0 : has - use);
} }
/*public static void restoreCharges(@NotNull ItemStack item, @NotNull ExcellentEnchant enchant) { /*public static void restoreCharges(@NotNull ItemStack item, @NotNull ExcellentEnchant enchant) {

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.9</version> <version>3.6.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId> <artifactId>NMS</artifactId>
<version>3.5.9</version> <version>3.6.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -7,7 +7,7 @@
<groupId>su.nightexpress.excellentenchants</groupId> <groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>ExcellentEnchants</artifactId> <artifactId>ExcellentEnchants</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>3.5.9</version> <version>3.6.0</version>
<modules> <modules>
<module>Core</module> <module>Core</module>
<module>NMS</module> <module>NMS</module>