From eeef240e4940ab3484a797ae08c9711eb43c7f17 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 3 Oct 2023 18:07:42 +0500 Subject: [PATCH] v3.5.9 --- Core/pom.xml | 14 +- .../excellentenchants/ExcellentEnchants.java | 22 +- .../api/enchantment/IEnchantment.java | 12 +- .../enchantment/type/BlockBreakEnchant.java | 10 +- .../enchantment/type/BlockDropEnchant.java | 10 +- .../api/enchantment/type/BowEnchant.java | 18 +- .../api/enchantment/type/CombatEnchant.java | 11 + .../api/enchantment/type/DamageEnchant.java | 6 + .../api/enchantment/type/DeathEnchant.java | 11 + .../api/enchantment/type/FishingEnchant.java | 6 + .../api/enchantment/type/GenericEnchant.java | 7 + .../api/enchantment/type/InteractEnchant.java | 10 +- .../command/TierbookCommand.java | 2 +- .../excellentenchants/config/Lang.java | 2 +- .../enchantment/EnchantManager.java | 3 +- .../enchantment/EnchantPopulator.java | 185 +++++++-- .../enchantment/impl/ExcellentEnchant.java | 28 +- ...nchantAquaman.java => AquamanEnchant.java} | 11 +- ...ntColdSteel.java => ColdSteelEnchant.java} | 17 +- .../impl/armor/DarknessCloakEnchant.java | 11 +- ...n.java => ElementalProtectionEnchant.java} | 19 +- ...FireShield.java => FireShieldEnchant.java} | 15 +- ...ameWalker.java => FlameWalkerEnchant.java} | 25 +- ...hantHardened.java => HardenedEnchant.java} | 15 +- ...ntIceShield.java => IceShieldEnchant.java} | 15 +- ...chantBunnyHop.java => JumpingEnchant.java} | 11 +- ...Destruction.java => KamikadzeEnchant.java} | 26 +- ...ghtVision.java => NightVisionEnchant.java} | 11 +- ...hantRegrowth.java => RegrowthEnchant.java} | 10 +- ...Saturation.java => SaturationEnchant.java} | 11 +- .../{EnchantSonic.java => SpeedyEnchant.java} | 11 +- .../impl/armor/StoppingForceEnchant.java | 11 +- .../impl/bow/DarknessArrowsEnchant.java | 10 +- .../enchantment/impl/bow/EnchantBomber.java | 13 +- .../impl/bow/EnchantConfusingArrows.java | 10 +- .../impl/bow/EnchantDragonfireArrows.java | 11 +- .../impl/bow/EnchantElectrifiedArrows.java | 11 +- .../enchantment/impl/bow/EnchantEnderBow.java | 15 +- .../impl/bow/EnchantExplosiveArrows.java | 34 +- .../enchantment/impl/bow/EnchantGhast.java | 15 +- .../enchantment/impl/bow/EnchantHover.java | 10 +- .../impl/bow/EnchantPoisonedArrows.java | 10 +- .../impl/bow/EnchantWitheredArrows.java | 10 +- .../enchantment/impl/bow/FlareEnchant.java | 15 +- .../enchantment/impl/bow/SniperEnchant.java | 17 +- .../impl/fishing/AutoReelEnchant.java | 4 +- .../impl/fishing/CurseOfDrownedEnchant.java | 4 +- .../impl/fishing/DoubleCatchEnchant.java | 11 +- .../impl/fishing/RiverMasterEnchant.java | 8 +- .../impl/fishing/SeasonedAnglerEnchant.java | 4 +- .../impl/fishing/SurvivalistEnchant.java | 11 +- .../impl/meta/ChanceImplementation.java | 2 +- .../impl/meta/PotionImplementation.java | 2 +- ...astMining.java => BlastMiningEnchant.java} | 15 +- ...aking.java => CurseOfBreakingEnchant.java} | 17 +- .../impl/tool/CurseOfMediocrityEnchant.java | 14 +- ...une.java => CurseOfMisfortuneEnchant.java} | 26 +- ...vineTouch.java => DivineTouchEnchant.java} | 53 ++- .../{EnchantHaste.java => HasteEnchant.java} | 11 +- ...LuckyMiner.java => LuckyMinerEnchant.java} | 12 +- ...ntReplanter.java => ReplanterEnchant.java} | 23 +- ...ntSilkChest.java => SilkChestEnchant.java} | 18 +- ...nchantSmelter.java => SmelterEnchant.java} | 21 +- ...lekinesis.java => TelekinesisEnchant.java} | 32 +- ...ntTreasures.java => TreasuresEnchant.java} | 44 +-- ...{EnchantTunnel.java => TunnelEnchant.java} | 15 +- ...ntVeinminer.java => VeinminerEnchant.java} | 14 +- ...lity.java => CurseOfFragilityEnchant.java} | 9 +- .../impl/universal/SoulboundEnchant.java | 7 +- .../impl/weapon/EnchantBaneOfNetherspawn.java | 4 +- .../impl/weapon/EnchantBlindness.java | 11 +- .../impl/weapon/EnchantConfusion.java | 11 +- .../enchantment/impl/weapon/EnchantCure.java | 11 +- .../impl/weapon/EnchantCutter.java | 12 +- .../impl/weapon/EnchantDecapitator.java | 5 +- .../impl/weapon/EnchantDoubleStrike.java | 11 +- .../impl/weapon/EnchantExhaust.java | 11 +- .../impl/weapon/EnchantExpHunter.java | 5 +- .../impl/weapon/EnchantIceAspect.java | 11 +- .../impl/weapon/EnchantInfernus.java | 7 +- .../impl/weapon/EnchantNimble.java | 13 +- .../impl/weapon/EnchantParalyze.java | 11 +- .../enchantment/impl/weapon/EnchantRage.java | 11 +- .../impl/weapon/EnchantRocket.java | 11 +- .../impl/weapon/EnchantScavenger.java | 5 +- .../impl/weapon/EnchantSurprise.java | 11 +- .../impl/weapon/EnchantTemper.java | 12 +- .../impl/weapon/EnchantThrifty.java | 5 +- .../impl/weapon/EnchantThunder.java | 12 +- .../impl/weapon/EnchantVampire.java | 14 +- .../enchantment/impl/weapon/EnchantVenom.java | 11 +- .../impl/weapon/EnchantVillageDefender.java | 4 +- .../impl/weapon/EnchantWither.java | 11 +- .../listener/EnchantAnvilListener.java | 32 +- .../listener/EnchantGenericListener.java | 69 ++-- .../listener/EnchantHandlerListener.java | 116 ++---- .../menu/EnchantmentsListMenu.java | 2 +- .../{ => registry}/EnchantRegistry.java | 168 ++++++--- .../registry/wrapper/DataGather.java | 31 ++ .../registry/wrapper/DataGathers.java | 351 ++++++++++++++++++ .../registry/wrapper/WrappedEvent.java | 56 +++ .../enchantment/util/EnchantPriority.java | 6 - .../enchantment/util/EnchantUtils.java | 150 ++------ .../hook/impl/PlaceholderHook.java | 2 +- .../hook/impl/ProtocolHook.java | 2 +- NMS/pom.xml | 2 +- V1_17_R1/pom.xml | 4 +- V1_18_R2/pom.xml | 4 +- V1_19_R3/pom.xml | 4 +- V1_20_R1/pom.xml | 4 +- V1_20_R2/pom.xml | 4 +- pom.xml | 2 +- 112 files changed, 1550 insertions(+), 823 deletions(-) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantAquaman.java => AquamanEnchant.java} (84%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantColdSteel.java => ColdSteelEnchant.java} (89%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantElementalProtection.java => ElementalProtectionEnchant.java} (85%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantFireShield.java => FireShieldEnchant.java} (91%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantFlameWalker.java => FlameWalkerEnchant.java} (90%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantHardened.java => HardenedEnchant.java} (89%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantIceShield.java => IceShieldEnchant.java} (90%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantBunnyHop.java => JumpingEnchant.java} (83%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantSelfDestruction.java => KamikadzeEnchant.java} (78%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantNightVision.java => NightVisionEnchant.java} (84%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantRegrowth.java => RegrowthEnchant.java} (93%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantSaturation.java => SaturationEnchant.java} (90%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/{EnchantSonic.java => SpeedyEnchant.java} (83%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantBlastMining.java => BlastMiningEnchant.java} (91%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantCurseOfBreaking.java => CurseOfBreakingEnchant.java} (83%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantCurseOfMisfortune.java => CurseOfMisfortuneEnchant.java} (86%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantDivineTouch.java => DivineTouchEnchant.java} (80%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantHaste.java => HasteEnchant.java} (84%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantLuckyMiner.java => LuckyMinerEnchant.java} (87%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantReplanter.java => ReplanterEnchant.java} (92%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantSilkChest.java => SilkChestEnchant.java} (93%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantSmelter.java => SmelterEnchant.java} (91%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantTelekinesis.java => TelekinesisEnchant.java} (71%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantTreasures.java => TreasuresEnchant.java} (85%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantTunnel.java => TunnelEnchant.java} (90%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/{EnchantVeinminer.java => VeinminerEnchant.java} (91%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/{EnchantCurseOfFragility.java => CurseOfFragilityEnchant.java} (89%) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/{ => registry}/EnchantRegistry.java (50%) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java delete mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPriority.java diff --git a/Core/pom.xml b/Core/pom.xml index ec12f26..611fd6a 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 @@ -76,32 +76,32 @@ su.nightexpress.excellentenchants NMS - 3.5.8 + 3.5.9 su.nightexpress.excellentenchants V1_17_R1 - 3.5.8 + 3.5.9 su.nightexpress.excellentenchants V1_18_R2 - 3.5.8 + 3.5.9 su.nightexpress.excellentenchants V1_19_R3 - 3.5.8 + 3.5.9 su.nightexpress.excellentenchants V1_20_R1 - 3.5.8 + 3.5.9 su.nightexpress.excellentenchants V1_20_R2 - 3.5.8 + 3.5.9 diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java b/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java index 34c0b84..6e733a0 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java @@ -1,5 +1,6 @@ package su.nightexpress.excellentenchants; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.NexPlugin; import su.nexmedia.engine.Version; @@ -13,8 +14,10 @@ import su.nightexpress.excellentenchants.command.TierbookCommand; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Lang; import su.nightexpress.excellentenchants.enchantment.EnchantManager; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; +import su.nightexpress.excellentenchants.enchantment.EnchantPopulator; +import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; +import su.nightexpress.excellentenchants.enchantment.type.ObtainType; import su.nightexpress.excellentenchants.hook.HookId; import su.nightexpress.excellentenchants.hook.impl.PlaceholderHook; import su.nightexpress.excellentenchants.hook.impl.ProtocolHook; @@ -28,7 +31,7 @@ import su.nightexpress.excellentenchants.tier.TierManager; public class ExcellentEnchants extends NexPlugin { - private EnchantRegistry enchantRegistry; + private EnchantRegistry registry; private EnchantManager enchantManager; private EnchantNMS enchantNMS; private TierManager tierManager; @@ -42,7 +45,7 @@ public class ExcellentEnchants extends NexPlugin { @Override public void onLoad() { super.onLoad(); - this.enchantRegistry = new EnchantRegistry(this); + this.registry = new EnchantRegistry(this); } @Override @@ -52,7 +55,7 @@ public class ExcellentEnchants extends NexPlugin { this.tierManager = new TierManager(this); this.tierManager.setup(); - this.enchantRegistry.setup(); + this.registry.setup(); this.enchantManager = new EnchantManager(this); this.enchantManager.setup(); @@ -79,7 +82,7 @@ public class ExcellentEnchants extends NexPlugin { this.tierManager = null; } PlaceholderHook.shutdown(); - //this.enchantRegistry.shutdown(); Do we ever need this at all? + this.registry.shutdown(); } private void setNMS() { @@ -126,14 +129,19 @@ public class ExcellentEnchants extends NexPlugin { this.registerPermissions(Perms.class); } + @NotNull + public EnchantPopulator createPopulator(@NotNull ItemStack item, @NotNull ObtainType obtainType) { + return new EnchantPopulator(this, item, obtainType); + } + @NotNull public TierManager getTierManager() { return tierManager; } @NotNull - public EnchantRegistry getEnchantRegistry() { - return this.enchantRegistry; + public EnchantRegistry getRegistry() { + return registry; } @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/IEnchantment.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/IEnchantment.java index 4d1fefc..b5c3e8b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/IEnchantment.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/IEnchantment.java @@ -1,25 +1,27 @@ package su.nightexpress.excellentenchants.api.enchantment; +import org.bukkit.Keyed; import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.api.config.JYML; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import su.nightexpress.excellentenchants.tier.Tier; import su.nightexpress.excellentenchants.enchantment.type.ObtainType; +import su.nightexpress.excellentenchants.tier.Tier; import java.util.List; import java.util.Set; -public interface IEnchantment { +public interface IEnchantment extends Keyed { + + boolean isAvailableToUse(@NotNull LivingEntity entity); @NotNull JYML getConfig(); @NotNull String getId(); - @NotNull EnchantPriority getPriority(); - @NotNull String getDisplayName(); @NotNull String getNameFormatted(int level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java index 6cce6ad..32de3aa 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockBreakEnchant.java @@ -1,6 +1,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -8,5 +9,10 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; public interface BlockBreakEnchant extends IEnchantment { - boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level); + boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level); + + @NotNull + default EventPriority getBreakPriority() { + return EventPriority.HIGH; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java index fbccb78..e8c3268 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BlockDropEnchant.java @@ -1,6 +1,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -8,5 +9,10 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; public interface BlockDropEnchant extends IEnchantment { - boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level); + boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level); + + @NotNull + default EventPriority getDropPriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java index 8b4df42..4653606 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/BowEnchant.java @@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; 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.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; @@ -13,9 +14,24 @@ public interface BowEnchant extends IEnchantment { boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level); - boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level); + boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level); boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level); + + @NotNull + default EventPriority getShootPriority() { + return EventPriority.NORMAL; + } + + @NotNull + default EventPriority getHitPriority() { + return EventPriority.NORMAL; + } + + @NotNull + default EventPriority getDamagePriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java index 32d0fe8..54e9535 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/CombatEnchant.java @@ -1,6 +1,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; 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; @@ -15,4 +16,14 @@ public interface CombatEnchant extends IEnchantment { boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level); + + @NotNull + default EventPriority getAttackPriority() { + return EventPriority.NORMAL; + } + + @NotNull + default EventPriority getProtectPriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java index 12448ad..8099f3f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DamageEnchant.java @@ -1,6 +1,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -9,4 +10,9 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; public interface DamageEnchant extends IEnchantment { boolean onDamage(@NotNull EntityDamageEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level); + + @NotNull + default EventPriority getDamagePriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java index 78e3387..e42468e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/DeathEnchant.java @@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -12,4 +13,14 @@ public interface DeathEnchant extends IEnchantment { 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); + + @NotNull + default EventPriority getDeathPriority() { + return EventPriority.NORMAL; + } + + @NotNull + default EventPriority getKillPriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java index 1665720..cc45db4 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/FishingEnchant.java @@ -1,5 +1,6 @@ package su.nightexpress.excellentenchants.api.enchantment.type; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -8,4 +9,9 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; public interface FishingEnchant extends IEnchantment { boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level); + + @NotNull + default EventPriority getFishingPriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java new file mode 100644 index 0000000..f7aa000 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/GenericEnchant.java @@ -0,0 +1,7 @@ +package su.nightexpress.excellentenchants.api.enchantment.type; + +import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; + +public interface GenericEnchant extends IEnchantment { + +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java index 2193876..e4e526c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/api/enchantment/type/InteractEnchant.java @@ -1,6 +1,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -8,5 +9,10 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; public interface InteractEnchant extends IEnchantment { - boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull ItemStack item, int level); + boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level); + + @NotNull + default EventPriority getInteractPriority() { + return EventPriority.NORMAL; + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/command/TierbookCommand.java b/Core/src/main/java/su/nightexpress/excellentenchants/command/TierbookCommand.java index f0d9950..a7bddce 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/command/TierbookCommand.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/command/TierbookCommand.java @@ -14,8 +14,8 @@ import su.nexmedia.engine.utils.random.Rnd; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Perms; import su.nightexpress.excellentenchants.config.Lang; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.tier.Tier; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java b/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java index 301e437..eaff27a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/config/Lang.java @@ -4,7 +4,7 @@ import su.nexmedia.engine.api.lang.LangKey; import su.nexmedia.engine.lang.EngineLang; import su.nightexpress.excellentenchants.Placeholders; -import static su.nexmedia.engine.utils.Colors.*; +import static su.nexmedia.engine.utils.Colors.RED; public class Lang extends EngineLang { 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 6e46f73..3e3dabe 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantManager.java @@ -5,7 +5,6 @@ import su.nexmedia.engine.api.manager.AbstractManager; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.enchantment.listener.EnchantAnvilListener; import su.nightexpress.excellentenchants.enchantment.listener.EnchantGenericListener; -import su.nightexpress.excellentenchants.enchantment.listener.EnchantHandlerListener; import su.nightexpress.excellentenchants.enchantment.menu.EnchantmentsListMenu; import su.nightexpress.excellentenchants.enchantment.task.ArrowTrailsTask; import su.nightexpress.excellentenchants.enchantment.task.PotionEffectsTask; @@ -26,7 +25,7 @@ public class EnchantManager extends AbstractManager { @Override protected void onLoad() { this.enchantmentsListMenu = new EnchantmentsListMenu(this.plugin); - this.addListener(new EnchantHandlerListener(this)); + //this.addListener(new EnchantHandlerListener(this)); this.addListener(new EnchantGenericListener(this)); this.addListener(new EnchantAnvilListener(this.plugin)); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java index 63fa0d8..d093c32 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantPopulator.java @@ -1,11 +1,17 @@ package su.nightexpress.excellentenchants.enchantment; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.utils.random.Rnd; -import su.nightexpress.excellentenchants.ExcellentEnchantsAPI; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.config.ObtainSettings; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.type.ObtainType; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.tier.Tier; @@ -14,45 +20,80 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; import java.util.stream.Collectors; public class EnchantPopulator { + private final ExcellentEnchants plugin; private final ObtainType obtainType; private final ItemStack item; - private final Map> enchants; + private final Map> candidates; + private final Map population; - public EnchantPopulator(@NotNull ObtainType obtainType, @NotNull ItemStack item) { - this.obtainType = obtainType; + private World world; + private Function levelGenerator; + + public EnchantPopulator(@NotNull ExcellentEnchants plugin, @NotNull ItemStack item, @NotNull ObtainType obtainType) { + this.plugin = plugin; this.item = item; - this.enchants = new HashMap<>(); + this.obtainType = obtainType; + this.candidates = new HashMap<>(); + this.population = new HashMap<>(); + this.withLevelGenerator(enchant -> enchant.generateLevel(this.getObtainType())); - ExcellentEnchantsAPI.getTierManager().getTiers().forEach(tier -> { + this.fillDefaultCandidates(); + } + + @NotNull + public EnchantPopulator withWorld(@NotNull World world) { + this.world = world; + return this; + } + + @NotNull + public EnchantPopulator withLevelGenerator(@NotNull Function levelGenerator) { + this.levelGenerator = levelGenerator; + return this; + } + + @NotNull + public EnchantPopulator withDefaultPopulation(@NotNull Map population) { + this.getPopulation().putAll(population); + return this; + } + + private void fillDefaultCandidates() { + this.plugin.getTierManager().getTiers().forEach(tier -> { Set enchants = EnchantRegistry.getOfTier(tier); - this.enchants.put(tier, EnchantUtils.populateFilter(enchants, obtainType, item)); + + enchants.removeIf(enchant -> { + if (enchant.getObtainChance(this.getObtainType()) <= 0D) return true; + if (!enchant.canEnchantItem(this.getItem())) return true; + + return this.getObtainType() == ObtainType.ENCHANTING && (enchant.isTreasure() || enchant.isCursed()); + }); + + this.candidates.put(tier, enchants); }); } public boolean isEmpty() { - return this.getEnchants().isEmpty() || this.getEnchants().values().stream().allMatch(Set::isEmpty); + return this.getCandidates().isEmpty() || this.getCandidates().values().stream().allMatch(Set::isEmpty); } public boolean isEmpty(@NotNull Tier tier) { - return this.getEnchants(tier).isEmpty(); + return this.getCandidates(tier).isEmpty(); } public void purge(@NotNull Tier tier) { - this.getEnchants().remove(tier); + this.getCandidates().remove(tier); } public void purge(@NotNull Tier tier, @NotNull ExcellentEnchant enchant) { - this.getEnchants(tier).remove(enchant); - this.getEnchants().keySet().removeIf(this::isEmpty); - } - - @NotNull - public ObtainType getObtainType() { - return obtainType; + this.getCandidates(tier).remove(enchant); + this.getCandidates().keySet().removeIf(this::isEmpty); } @NotNull @@ -61,18 +102,38 @@ public class EnchantPopulator { } @NotNull - public Map> getEnchants() { - return this.enchants; + public ObtainType getObtainType() { + return obtainType; + } + + @Nullable + public World getWorld() { + return world; } @NotNull - public Set getEnchants(@NotNull Tier tier) { - return this.getEnchants().getOrDefault(tier, new HashSet<>()); + public Function getLevelGenerator() { + return levelGenerator; + } + + @NotNull + public Map> getCandidates() { + return this.candidates; + } + + @NotNull + public Set getCandidates(@NotNull Tier tier) { + return this.getCandidates().getOrDefault(tier, new HashSet<>()); + } + + @NotNull + public Map getPopulation() { + return this.population; } @Nullable public Tier getTierByChance() { - Map map = this.getEnchants().keySet().stream() + Map map = this.getCandidates().keySet().stream() .filter(tier -> tier.getChance(this.getObtainType()) > 0D) .collect(Collectors.toMap(k -> k, v -> v.getChance(this.getObtainType()), (o, n) -> n, HashMap::new)); if (map.isEmpty()) return null; @@ -82,8 +143,86 @@ public class EnchantPopulator { @Nullable public ExcellentEnchant getEnchantByChance(@NotNull Tier tier) { - Map map = this.getEnchants(tier).stream() + Map map = this.getCandidates(tier).stream() .collect(Collectors.toMap(k -> k, v -> v.getObtainChance(this.getObtainType()))); return map.isEmpty() ? null : Rnd.getByWeight(map); } + + @NotNull + public Map createPopulation() { + Map population = this.getPopulation(); + + ObtainSettings settings = Config.getObtainSettings(this.getObtainType()).orElse(null); + if (settings == null || !Rnd.chance(settings.getEnchantsCustomGenerationChance())) return population; + + int enchantsLimit = settings.getEnchantsTotalMax(); + int enchantsRolled = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax()); + + // Try to populate as many as possible. + while (!this.isEmpty() && enchantsRolled > 0) { + // Limit reached. + if (population.size() >= enchantsLimit) break; + + Tier tier = this.getTierByChance(); + if (tier == null) break; // no tiers left. + + ExcellentEnchant enchant = this.getEnchantByChance(tier); + // Remove entire tier if no enchants can be selected. + if (enchant == null) { + this.purge(tier); + continue; + } + + // Remove disabled world enchants. + if (world != null && enchant.isDisabledInWorld(world)) { + this.purge(tier, enchant); + continue; + } + + // Remove conflicting enchants. + if (population.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) { + this.purge(tier, enchant); + continue; + } + + // Level generation failed. + int level = this.getLevelGenerator().apply(enchant); + if (level < enchant.getStartLevel()) { + this.purge(tier, enchant); + continue; + } + + // All good! + this.purge(tier, enchant); + population.put(enchant, level); + enchantsRolled--; + } + + return population; + } + + public boolean populate() { + ItemStack item = this.getItem(); + AtomicBoolean status = new AtomicBoolean(false); + + var population = this.getPopulation().isEmpty() ? this.createPopulation() : this.getPopulation(); + + if (this.getObtainType() == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK) { + if (Config.ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS.get() && !population.isEmpty()) { + EnchantUtils.getAll(item).keySet().forEach(enchantment -> EnchantUtils.remove(item, enchantment)); + } + } + + population.forEach((enchantment, level) -> { + if (EnchantUtils.add(item, enchantment, level, false)) { + status.set(true); + } + }); + + if (status.get()) { + EnchantUtils.updateDisplay(item); + } + + return status.get(); + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java index 28ebee4..bf95036 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java @@ -25,7 +25,6 @@ import su.nightexpress.excellentenchants.enchantment.EnchantManager; import su.nightexpress.excellentenchants.enchantment.config.EnchantDefaults; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.ObtainType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.tier.Tier; @@ -33,22 +32,20 @@ import java.util.*; import java.util.function.Function; import java.util.stream.Stream; -public abstract class ExcellentEnchant extends Enchantment implements IEnchantment, EventListener { +public abstract class ExcellentEnchant extends Enchantment implements IEnchantment { - protected final ExcellentEnchants plugin; - protected final JYML cfg; - protected final String id; - protected final EnchantPriority priority; - protected final EnchantDefaults defaults; - protected final NamespacedKey chargesKey; + protected final ExcellentEnchants plugin; + protected final JYML cfg; + protected final String id; + protected final EnchantDefaults defaults; + protected final NamespacedKey chargesKey; protected final Map placeholdersMap; - public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id, @NotNull EnchantPriority priority) { + public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id) { super(NamespacedKey.minecraft(id.toLowerCase())); this.plugin = plugin; this.id = this.getKey().getKey(); this.cfg = new JYML(plugin.getDataFolder() + EnchantManager.DIR_ENCHANTS, id + ".yml"); - this.priority = priority; this.chargesKey = new NamespacedKey(plugin, this.getId() + ".charges"); this.defaults = new EnchantDefaults(this); this.placeholdersMap = new HashMap<>(); @@ -111,9 +108,10 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme } } - @Override public void registerListeners() { - this.plugin.getPluginManager().registerEvents(this, plugin); + if (this instanceof EventListener listener) { + this.plugin.getPluginManager().registerEvents(listener, plugin); + } } @NotNull @@ -127,6 +125,7 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme return disabled.contains(this.getKey().getKey()) || disabled.contains(Placeholders.WILDCARD); } + @Override public boolean isAvailableToUse(@NotNull LivingEntity entity) { return !this.isDisabledInWorld(entity.getWorld()); } @@ -141,11 +140,6 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme return this.id; } - @NotNull - public EnchantPriority getPriority() { - return priority; - } - @NotNull public EnchantDefaults getDefaults() { return defaults; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/AquamanEnchant.java similarity index 84% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/AquamanEnchant.java index 67de252..c3f969a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantAquaman.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/AquamanEnchant.java @@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -public class EnchantAquaman extends ExcellentEnchant implements Potioned, PassiveEnchant { +public class AquamanEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant { public static final String ID = "aquaman"; private PotionImplementation potionImplementation; - public EnchantAquaman(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public AquamanEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.4); this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect."); @@ -46,8 +45,6 @@ public class EnchantAquaman extends ExcellentEnchant implements Potioned, Passiv @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; - return this.addEffect(entity, level); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java similarity index 89% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java index e6ac365..2ea973b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantColdSteel.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ColdSteelEnchant.java @@ -2,29 +2,29 @@ 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.enchantment.impl.ExcellentEnchant; 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.util.EnchantPriority; +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 EnchantColdSteel extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { +public class ColdSteelEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { public static final String ID = "cold_steel"; private ChanceImplementation chanceImplementation; private PotionImplementation potionImplementation; - public EnchantColdSteel(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public ColdSteelEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on attacker."); this.getDefaults().setTier(0.3); this.getDefaults().setLevelMax(3); @@ -60,6 +60,12 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio 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; @@ -67,7 +73,6 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio @Override public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; return this.addEffect(damager, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java index c879bad..bace779 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/DarknessCloakEnchant.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor; import org.bukkit.Particle; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P private PotionImplementation potionImplementation; public DarknessCloakEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on attacker."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.2); @@ -61,6 +61,12 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P 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; @@ -68,7 +74,6 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P @Override public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(victim)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(damager, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java similarity index 85% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java index 3be551f..f962f9e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantElementalProtection.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/ElementalProtectionEnchant.java @@ -8,17 +8,18 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; +import su.nexmedia.engine.api.manager.EventListener; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; +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.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.Set; -public class EnchantElementalProtection extends ExcellentEnchant { +public class ElementalProtectionEnchant extends ExcellentEnchant implements GenericEnchant, EventListener { public static final String ID = "elemental_protection"; public static final String PLACEHOLDER_PROTECTION_AMOUNT = "%enchantment_protection_amount%"; @@ -33,8 +34,8 @@ public class EnchantElementalProtection extends ExcellentEnchant { private double protectionCapacity; private boolean protectionAsModifier; - public EnchantElementalProtection(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public ElementalProtectionEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Reduces Poison, Magic, Wither, Lightning, Freeze damage by " + PLACEHOLDER_PROTECTION_AMOUNT + "."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.2); @@ -76,9 +77,9 @@ public class EnchantElementalProtection extends ExcellentEnchant { } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onDamage(EntityDamageEvent e) { - if (!DAMAGE_CAUSES.contains(e.getCause())) return; - if (!(e.getEntity() instanceof LivingEntity entity)) return; + public void onDamage(EntityDamageEvent event) { + if (!DAMAGE_CAUSES.contains(event.getCause())) return; + if (!(event.getEntity() instanceof LivingEntity entity)) return; if (!this.isAvailableToUse(entity)) return; double protectionAmount = 0D; @@ -96,10 +97,10 @@ public class EnchantElementalProtection extends ExcellentEnchant { } if (this.isProtectionAsModifier()) { - e.setDamage(Math.max(0, e.getDamage() * (1D - protectionAmount))); + event.setDamage(Math.max(0, event.getDamage() * (1D - protectionAmount))); } else { - e.setDamage(Math.max(0, e.getDamage() - protectionAmount)); + event.setDamage(Math.max(0, event.getDamage() - protectionAmount)); } } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java similarity index 91% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java index 6c11e5d..83d1db5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFireShield.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FireShieldEnchant.java @@ -2,6 +2,7 @@ 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.jetbrains.annotations.NotNull; @@ -13,9 +14,8 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -public class EnchantFireShield extends ExcellentEnchant implements Chanced, CombatEnchant { +public class FireShieldEnchant extends ExcellentEnchant implements Chanced, CombatEnchant { public static final String ID = "fire_shield"; public static final String PLACEHOLDER_FIRE_DURATION = "%enchantment_fire_duration%"; @@ -23,8 +23,8 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb private EnchantScaler fireDuration; private ChanceImplementation chanceImplementation; - public EnchantFireShield(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public FireShieldEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to ignite the attacker for " + PLACEHOLDER_FIRE_DURATION + "s."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.4); @@ -57,6 +57,12 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb return EnchantmentTarget.ARMOR; } + @NotNull + @Override + public EventPriority getProtectPriority() { + return EventPriority.HIGHEST; + } + public double getFireDuration(int level) { return this.fireDuration.getValue(level); } @@ -70,7 +76,6 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(victim)) return false; if (!this.checkTriggerChance(level)) return false; int ticksToSet = (int) (this.getFireDuration(level) * 20); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java similarity index 90% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java index 2012b33..54d500d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/FlameWalkerEnchant.java @@ -19,15 +19,16 @@ import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.Version; +import su.nexmedia.engine.api.manager.EventListener; import su.nexmedia.engine.api.server.AbstractTask; import su.nexmedia.engine.utils.Pair; import su.nexmedia.engine.utils.random.Rnd; import su.nexmedia.engine.utils.values.UniParticle; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.api.enchantment.Cleanable; +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.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.List; @@ -36,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; -public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable { +public class FlameWalkerEnchant extends ExcellentEnchant implements GenericEnchant, EventListener, Cleanable { public static final String ID = "flame_walker"; @@ -46,8 +47,8 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable { private EnchantScaler blockDecayTime; private BlockTickTask blockTickTask; - public EnchantFlameWalker(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public FlameWalkerEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Ability to walk on lava and magma blocks without getting damage."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.7); @@ -93,12 +94,12 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable { } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onPlayerMove(PlayerMoveEvent e) { - Player player = e.getPlayer(); + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); if (player.isFlying() || !this.isAvailableToUse(player)) return; - Location from = e.getFrom(); - Location to = e.getTo(); + Location from = event.getFrom(); + Location to = event.getTo(); if (to == null) return; if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) return; @@ -147,9 +148,9 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable { } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onMagmaDamage(EntityDamageEvent e) { - if (e.getCause() != EntityDamageEvent.DamageCause.HOT_FLOOR) return; - if (!(e.getEntity() instanceof LivingEntity livingEntity)) return; + public void onMagmaDamage(EntityDamageEvent event) { + if (event.getCause() != EntityDamageEvent.DamageCause.HOT_FLOOR) return; + if (!(event.getEntity() instanceof LivingEntity livingEntity)) return; if (!this.isAvailableToUse(livingEntity)) return; EntityEquipment equipment = livingEntity.getEquipment(); @@ -161,7 +162,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable { int level = EnchantUtils.getLevel(boots, this); if (level <= 0) return; - e.setCancelled(true); + event.setCancelled(true); } static class BlockTickTask extends AbstractTask { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java similarity index 89% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java index 504f8db..2f87402 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantHardened.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/HardenedEnchant.java @@ -2,6 +2,7 @@ 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; @@ -14,17 +15,16 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -public class EnchantHardened extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { +public class HardenedEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { public static final String ID = "hardened"; private ChanceImplementation chanceImplementation; private PotionImplementation potionImplementation; - public EnchantHardened(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + 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); @@ -59,6 +59,12 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion 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; @@ -66,7 +72,6 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion @Override public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; return this.addEffect(victim, level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java similarity index 90% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java index ec4bca6..96a1ff6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/IceShieldEnchant.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor; import org.bukkit.Material; 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; @@ -16,17 +17,16 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { +public class IceShieldEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { public static final String ID = "ice_shield"; private ChanceImplementation chanceImplementation; private PotionImplementation potionImplementation; - public EnchantIceShield(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public IceShieldEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to freeze and apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on attacker."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); @@ -47,6 +47,12 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio return EnchantmentTarget.ARMOR_TORSO; } + @NotNull + @Override + public EventPriority getProtectPriority() { + return EventPriority.HIGHEST; + } + @Override @NotNull public Chanced getChanceImplementation() { @@ -66,7 +72,6 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio @Override public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(victim)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(damager, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java similarity index 83% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java index a08aae3..b7dc33a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantBunnyHop.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/JumpingEnchant.java @@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -public class EnchantBunnyHop extends ExcellentEnchant implements Potioned, PassiveEnchant { +public class JumpingEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant { public static final String ID = "bunny_hop"; private PotionImplementation potionImplementation; - public EnchantBunnyHop(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public JumpingEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect."); @@ -46,8 +45,6 @@ public class EnchantBunnyHop extends ExcellentEnchant implements Potioned, Passi @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; - return this.addEffect(entity, level); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java similarity index 78% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java index 688741a..7bc9bbe 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSelfDestruction.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/KamikadzeEnchant.java @@ -1,6 +1,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor; import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -9,7 +10,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; @@ -19,20 +19,19 @@ import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; 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.EnchantPriority; -public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, DeathEnchant { +public class KamikadzeEnchant extends ExcellentEnchant implements Chanced, DeathEnchant { public static final String ID = "self_destruction"; - - private static final String META_EXPLOSION_SOURCE = ID + "_explosion_source"; private static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%"; private EnchantScaler explosionSize; private ChanceImplementation chanceImplementation; - public EnchantSelfDestruction(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + private Entity exploder; + + public KamikadzeEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("%enchantment_trigger_chance%% chance to create an explosion on death."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -68,13 +67,12 @@ public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, @Override public boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; if (!this.checkTriggerChance(level)) return false; float size = (float) this.getExplosionSize(level); - entity.setMetadata(META_EXPLOSION_SOURCE, new FixedMetadataValue(plugin, true)); + this.exploder = entity; boolean exploded = entity.getWorld().createExplosion(entity.getLocation(), size, false, false, entity); - entity.removeMetadata(META_EXPLOSION_SOURCE, plugin); + this.exploder = null; return exploded; } @@ -84,10 +82,10 @@ public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onItemDamage(EntityDamageByEntityEvent e) { - if (!e.getDamager().hasMetadata(META_EXPLOSION_SOURCE)) return; - if (!(e.getEntity() instanceof Item item)) return; + public void onItemDamage(EntityDamageByEntityEvent event) { + if (this.exploder == null || event.getDamager() != this.exploder) return; + if (!(event.getEntity() instanceof Item item)) return; - e.setCancelled(true); + event.setCancelled(true); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java similarity index 84% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java index 9ddafa5..6589f35 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantNightVision.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/NightVisionEnchant.java @@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -public class EnchantNightVision extends ExcellentEnchant implements Potioned, PassiveEnchant { +public class NightVisionEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant { public static final String ID = "night_vision"; private PotionImplementation potionImplementation; - public EnchantNightVision(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public NightVisionEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.7); @@ -46,8 +45,6 @@ public class EnchantNightVision extends ExcellentEnchant implements Potioned, Pa @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; - return this.addEffect(entity, level); } } \ No newline at end of file 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/RegrowthEnchant.java similarity index 93% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantRegrowth.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/RegrowthEnchant.java index c0c17e2..0620744 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/RegrowthEnchant.java @@ -19,10 +19,9 @@ 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.task.AbstractEnchantmentTask; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class EnchantRegrowth extends ExcellentEnchant implements Chanced, PassiveEnchant, Cleanable { +public class RegrowthEnchant extends ExcellentEnchant implements Chanced, PassiveEnchant, Cleanable { public static final String ID = "regrowth"; @@ -39,8 +38,8 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv private ChanceImplementation chanceImplementation; private Task task; - public EnchantRegrowth(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public RegrowthEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Restores " + PLACEHOLDER_HEAL_AMOUNT + " hearts every " + PLACEHOLDER_HEAL_INTERVAL + "s."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.7); @@ -111,7 +110,6 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; if (!this.checkTriggerChance(level)) return false; double healthMax = EntityUtil.getAttribute(entity, Attribute.GENERIC_MAX_HEALTH); @@ -137,7 +135,7 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv @Override public void action() { for (LivingEntity entity : this.getEntities()) { - EnchantUtils.getEquipped(entity, EnchantRegrowth.class).forEach((item, enchants) -> { + EnchantUtils.getEquipped(entity, RegrowthEnchant.class).forEach((item, enchants) -> { enchants.forEach((enchant, level) -> { if (enchant.isOutOfCharges(item)) return; if (enchant.onTrigger(entity, item, level)) { 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/SaturationEnchant.java similarity index 90% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSaturation.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SaturationEnchant.java index 1af04ac..263a8b1 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/SaturationEnchant.java @@ -14,10 +14,9 @@ import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTask; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchant, Cleanable { +public class SaturationEnchant extends ExcellentEnchant implements PassiveEnchant, Cleanable { public static final String ID = "saturation"; @@ -31,8 +30,8 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan private Task task; - public EnchantSaturation(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public SaturationEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Restores " + PLACEHOLDER_SATURATION_AMOUNT + " food points every " + PLACEHOLDER_SATURATION_INTERVAL + "s."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.5); @@ -88,13 +87,11 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; if (!(entity instanceof Player player)) return false; if (player.getFoodLevel() >= this.getMaxFoodLevel(level)) return false; int amount = this.getSaturationAmount(level); player.setFoodLevel(Math.min(20, player.getFoodLevel() + amount)); - player.setSaturation(Math.min(20, player.getSaturation() + amount)); return true; } @@ -107,7 +104,7 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan @Override public void action() { for (LivingEntity entity : this.getEntities()) { - EnchantUtils.getEquipped(entity, EnchantSaturation.class).forEach((item, enchants) -> { + EnchantUtils.getEquipped(entity, SaturationEnchant.class).forEach((item, enchants) -> { enchants.forEach((enchant, level) -> { if (enchant.isOutOfCharges(item)) return; if (enchant.onTrigger(entity, item, level)) { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java similarity index 83% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java index 9e97483..116c70d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantSonic.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/SpeedyEnchant.java @@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -public class EnchantSonic extends ExcellentEnchant implements Potioned, PassiveEnchant { +public class SpeedyEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant { public static final String ID = "sonic"; private PotionImplementation potionImplementation; - public EnchantSonic(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public SpeedyEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -46,8 +45,6 @@ public class EnchantSonic extends ExcellentEnchant implements Potioned, PassiveE @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; - return this.addEffect(entity, level); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java index 87db573..e111910 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/StoppingForceEnchant.java @@ -2,6 +2,7 @@ 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.jetbrains.annotations.NotNull; @@ -13,7 +14,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -25,7 +25,7 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C private EnchantScaler knockbackModifier; public StoppingForceEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to resist knockback in combat by " + PLACEHOLDER_KNOCKBACK_RESISTANCE + "%."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.5); @@ -52,6 +52,12 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C return EnchantmentTarget.ARMOR_LEGS; } + @NotNull + @Override + public EventPriority getProtectPriority() { + return EventPriority.HIGHEST; + } + @NotNull @Override public Chanced getChanceImplementation() { @@ -65,7 +71,6 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C @Override public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(victim)) return false; if (!this.checkTriggerChance(level)) return false; this.plugin.runTask(task -> { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java index 9910666..d2cc8d1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/DarknessArrowsEnchant.java @@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant { @@ -34,7 +33,7 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced, private PotionImplementation potionImplementation; public DarknessArrowsEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); 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().setTier(0.1); @@ -78,7 +77,6 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced, @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false; if (!this.checkTriggerChance(level)) return false; @@ -87,12 +85,12 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced, } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { - return this.isOurProjectile(projectile); + 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) { - return this.isOurProjectile(projectile); + return false; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java index 1a15d85..037f547 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantBomber.java @@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Projectile; import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; @@ -18,7 +19,6 @@ 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.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEnchant { @@ -29,7 +29,7 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha private ChanceImplementation chanceImplementation; public EnchantBomber(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGHEST); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch TNT that explodes in " + PLACEHOLDER_FUSE_TICKS + "s."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.7); @@ -73,9 +73,14 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha return EnchantmentTarget.BOW; } + @NotNull + @Override + public EventPriority getShootPriority() { + return EventPriority.LOWEST; + } + @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!this.checkTriggerChance(level)) return false; if (!(event.getProjectile() instanceof Projectile projectile)) return false; @@ -88,7 +93,7 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { return false; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java index 0480ecc..d830c10 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantConfusingArrows.java @@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant { @@ -34,7 +33,7 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced, private PotionImplementation potionImplementation; public EnchantConfusingArrows(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); 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().setTier(0.1); @@ -78,7 +77,6 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced, @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false; if (!this.checkTriggerChance(level)) return false; @@ -87,12 +85,12 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced, } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { - return this.isOurProjectile(projectile); + 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) { - return this.isOurProjectile(projectile); + return false; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java index 1ea26f0..15bfd31 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantDragonfireArrows.java @@ -31,7 +31,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { @@ -47,7 +46,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced private ChanceImplementation chanceImplementation; public EnchantDragonfireArrows(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); 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().setTier(0.7); @@ -99,19 +98,17 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; - return this.checkTriggerChance(level); } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { if (!this.isOurProjectile(projectile)) return false; if (event.getHitEntity() != null) return false; if (projectile.getShooter() == null) return false; this.createCloud(projectile.getShooter(), projectile.getLocation() , level); - return true; + return false; } @Override @@ -119,7 +116,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced if (!this.isOurProjectile(projectile)) return false; this.createCloud(shooter, victim.getLocation(), level); - return true; + return false; } private void createCloud(@NotNull ProjectileSource shooter, @NotNull Location location, int level) { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java index 292f32d..d86aab8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java @@ -26,7 +26,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { @@ -38,7 +37,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance private ChanceImplementation chanceImplementation; public EnchantElectrifiedArrows(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an electrified arrow."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -73,13 +72,11 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; - return this.checkTriggerChance(level); } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { if (!this.isOurProjectile(projectile)) return false; if (event.getHitEntity() != null || event.getHitBlock() == null) return false; @@ -90,7 +87,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance UniParticle.blockCrack(block.getType()).play(center, 1, 0.05, 120); UniParticle.of(Particle.FIREWORKS_SPARK).play(center, 1, 0.05, 120); } - return true; + return false; } @Override @@ -103,7 +100,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance victim.getWorld().strikeLightning(victim.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true)); }); - return true; + return false; } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java index 795ff07..de01b2f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantEnderBow.java @@ -5,16 +5,16 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.EnderPearl; 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.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Chanced { @@ -24,7 +24,7 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha private ChanceImplementation chanceImplementation; public EnchantEnderBow(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGHEST); + super(plugin, ID); this.getDefaults().setDescription("Shoots ender pearls instead of arrows."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(1.0); @@ -59,9 +59,14 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha return EnchantmentTarget.BOW; } + @NotNull + @Override + public EventPriority getShootPriority() { + return EventPriority.LOWEST; + } + @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!this.checkTriggerChance(level)) return false; if (!(event.getProjectile() instanceof Projectile projectile)) return false; @@ -72,7 +77,7 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { return false; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java index 29bfbf4..8cedd07 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantExplosiveArrows.java @@ -11,7 +11,6 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nexmedia.engine.utils.NumberUtil; @@ -25,15 +24,12 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { public static final String ID = "explosive_arrows"; public static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%"; - private static final String META_EXPLOSION_SOURCE = ID + "_source"; - private boolean explosionFireSpread; private boolean explosionDamageItems; private boolean explosionDamageBlocks; @@ -42,8 +38,10 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, private ArrowImplementation arrowImplementation; private ChanceImplementation chanceImplementation; + private Entity lastExploder; + public EnchantExplosiveArrows(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an explosive arrow."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.7); @@ -101,43 +99,39 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; - return this.checkTriggerChance(level); } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { if (!this.isOurProjectile(projectile)) return false; - Entity shooter = null; if (projectile.getShooter() instanceof Entity entity) { - shooter = entity; - shooter.setMetadata(META_EXPLOSION_SOURCE, new FixedMetadataValue(this.plugin, true)); + this.lastExploder = entity; } World world = projectile.getWorld(); float explSize = (float) this.getExplosionSize(level); boolean explFire = this.isExplosionFireSpread(); boolean explBlocks = this.isExplosionDamageBlocks(); - boolean exploded = world.createExplosion(projectile.getLocation(), explSize, explFire, explBlocks, shooter); - if (shooter != null) shooter.removeMetadata(META_EXPLOSION_SOURCE, this.plugin); - return exploded; + boolean exploded = world.createExplosion(projectile.getLocation(), explSize, explFire, explBlocks, this.lastExploder); + this.lastExploder = null; + return false; } @Override public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - return this.isOurProjectile(projectile); + return false; } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onItemDamage(EntityDamageByEntityEvent e) { - if (e.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) return; + public void onItemDamage(EntityDamageByEntityEvent event) { + if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) return; if (this.explosionDamageItems) return; - if (!e.getDamager().hasMetadata(META_EXPLOSION_SOURCE)) return; + if (this.lastExploder == null || this.lastExploder != event.getDamager()) return; - if (e.getEntity() instanceof Item || e.getEntity() instanceof ItemFrame) { - e.setCancelled(true); + if (event.getEntity() instanceof Item || event.getEntity() instanceof ItemFrame) { + event.setCancelled(true); } } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java index 949a0f1..9d54165 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantGhast.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Fireball; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Projectile; import org.bukkit.entity.SmallFireball; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; @@ -14,11 +15,10 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; 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; @@ -31,7 +31,7 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance private ChanceImplementation chanceImplementation; public EnchantGhast(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGHEST); + super(plugin, ID); this.getDefaults().setDescription("Shoots fireballs instead of arrows."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.3); @@ -78,9 +78,14 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance return EnchantmentTarget.BOW; } + @NotNull + @Override + public EventPriority getShootPriority() { + return EventPriority.LOWEST; + } + @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!this.checkTriggerChance(level)) return false; if (!(event.getProjectile() instanceof Projectile projectile)) return false; @@ -104,7 +109,7 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { return false; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java index f2dba34..440fda4 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantHover.java @@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant { @@ -34,7 +33,7 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed, private PotionImplementation potionImplementation; public EnchantHover(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); 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().setTier(0.1); @@ -78,7 +77,6 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed, @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false; if (!this.checkTriggerChance(level)) return false; @@ -87,12 +85,12 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed, } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { - return this.isOurProjectile(projectile); + 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) { - return this.isOurProjectile(projectile); + return false; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java index 430634e..e56fd82 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantPoisonedArrows.java @@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant { @@ -34,7 +33,7 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced, private PotionImplementation potionImplementation; public EnchantPoisonedArrows(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); 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().setTier(0.1); @@ -78,7 +77,6 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced, @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false; if (!this.checkTriggerChance(level)) return false; @@ -87,12 +85,12 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced, } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { - return this.isOurProjectile(projectile); + 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) { - return this.isOurProjectile(projectile); + return false; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java index 65de8eb..6f22ad3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantWitheredArrows.java @@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant { @@ -34,7 +33,7 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced, private PotionImplementation potionImplementation; public EnchantWitheredArrows(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); 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().setTier(0.5); @@ -78,7 +77,6 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced, @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false; if (!this.checkTriggerChance(level)) return false; @@ -87,12 +85,12 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced, } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { - return this.isOurProjectile(projectile); + 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) { - return this.isOurProjectile(projectile); + return false; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java index 3d110a6..5438f90 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/FlareEnchant.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityShootBowEvent; @@ -26,7 +27,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant { @@ -36,7 +36,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, private ArrowImplementation arrowImplementation; public FlareEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to create a torch where arrow lands."); this.getDefaults().setLevelMax(1); @@ -56,6 +56,12 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, return EnchantmentTarget.BOW; } + @NotNull + @Override + public EventPriority getHitPriority() { + return EventPriority.HIGHEST; + } + @NotNull @Override public Chanced getChanceImplementation() { @@ -71,7 +77,6 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, @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.isAvailableToUse(shooter)) return false; if (!this.checkTriggerChance(level)) return false; this.addData(arrow); @@ -79,7 +84,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, } @Override - public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent e, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { Block block = e.getHitBlock(); if (block == null) return false; @@ -106,7 +111,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, relative.setBlockData(directional, true); } - return true; + return false; } @Override diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java index 6fc6e77..2be71dc 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/SniperEnchant.java @@ -4,6 +4,7 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.Entity; 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.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; @@ -18,7 +19,6 @@ 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.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanced { @@ -30,7 +30,7 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc private EnchantScaler speedModifier; public SniperEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription("Increases projectile speed by " + PLACEHOLDER_PROJECTILE_SPEED + "%"); this.getDefaults().setLevelMax(5); @@ -48,6 +48,12 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc this.addPlaceholder(PLACEHOLDER_PROJECTILE_SPEED, level -> NumberUtil.format(this.getSpeedModifier(level) * 100D)); } + @NotNull + @Override + public Chanced getChanceImplementation() { + return this.chanceImplementation; + } + public double getSpeedModifier(int level) { return this.speedModifier.getValue(level); } @@ -60,13 +66,12 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc @NotNull @Override - public Chanced getChanceImplementation() { - return this.chanceImplementation; + public EventPriority getShootPriority() { + return EventPriority.LOWEST; } @Override public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { - if (!this.isAvailableToUse(shooter)) return false; if (!this.checkTriggerChance(level)) return false; double modifier = this.getSpeedModifier(level); @@ -79,7 +84,7 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc } @Override - public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { + public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { return false; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java index 4e13cde..f5d8808 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java @@ -7,14 +7,13 @@ import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class AutoReelEnchant extends ExcellentEnchant implements FishingEnchant { public static final String ID = "auto_reel"; public AutoReelEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Automatically reels in a hook on bite."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(1.0); @@ -29,7 +28,6 @@ public class AutoReelEnchant extends ExcellentEnchant implements FishingEnchant @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.BITE) return false; - if (!this.isAvailableToUse(event.getPlayer())) return false; this.plugin.runTask(task -> { if (event.isCancelled()) return; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java index 5486825..9a6d510 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java @@ -16,7 +16,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEnchant, Chanced { @@ -25,7 +24,7 @@ public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEn private ChanceImplementation chanceImplementation; public CurseOfDrownedEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGHEST); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to fish up a Drowned Zombie."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0D); @@ -53,7 +52,6 @@ public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEn @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; - if (!this.isAvailableToUse(event.getPlayer())) return false; if (!this.checkTriggerChance(level)) return false; FishHook hook = event.getHook(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java index f793cbf..a2b9e4b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java @@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.fishing; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.Item; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -11,7 +12,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEnchant, Chanced { @@ -20,7 +20,7 @@ public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEncha private ChanceImplementation chanceImplementation; public DoubleCatchEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription("Increases amount of caught item by x2 with " + Placeholders.ENCHANTMENT_CHANCE + "% chance."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.5); @@ -39,6 +39,12 @@ public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEncha return EnchantmentTarget.FISHING_ROD; } + @NotNull + @Override + public EventPriority getFishingPriority() { + return EventPriority.HIGHEST; + } + @Override @NotNull public ChanceImplementation getChanceImplementation() { @@ -49,7 +55,6 @@ public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEncha public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; if (!(event.getCaught() instanceof Item drop)) return false; - if (!this.isAvailableToUse(event.getPlayer())) return false; if (!this.checkTriggerChance(level)) return false; ItemStack stack = drop.getItemStack(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java index b339ecc..67a2666 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java @@ -8,21 +8,22 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.manager.EventListener; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; +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.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class RiverMasterEnchant extends ExcellentEnchant { +public class RiverMasterEnchant extends ExcellentEnchant implements GenericEnchant, EventListener { public static final String ID = "river_master"; private EnchantScaler distanceMod; public RiverMasterEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Increases casting distance."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.1); @@ -51,7 +52,6 @@ public class RiverMasterEnchant extends ExcellentEnchant { public void onHookLaunch(ProjectileLaunchEvent event) { if (!(event.getEntity() instanceof FishHook hook)) return; if (!(hook.getShooter() instanceof Player player)) return; - if (!this.isAvailableToUse(player)) return; ItemStack rod = EnchantUtils.getFishingRod(player); if (rod == null) return; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java index 7a2d0c5..ce3f0e3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java @@ -10,7 +10,6 @@ import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEnchant { @@ -19,7 +18,7 @@ public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEn private EnchantScaler expMod; public SeasonedAnglerEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Increases amount of XP gained from fishing by " + Placeholders.GENERIC_AMOUNT + "%."); this.getDefaults().setLevelMax(4); this.getDefaults().setTier(0.1); @@ -48,7 +47,6 @@ public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEn @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; - if (!this.isAvailableToUse(event.getPlayer())) return false; if (event.getExpToDrop() == 0) return false; int expDrop = event.getExpToDrop(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java index e40c3c0..3729622 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java @@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.fishing; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.Item; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.CookingRecipe; import org.bukkit.inventory.ItemStack; @@ -11,7 +12,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.HashSet; import java.util.Set; @@ -25,7 +25,7 @@ public class SurvivalistEnchant extends ExcellentEnchant implements FishingEncha private ChanceImplementation chanceImplementation; public SurvivalistEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGH); + super(plugin, ID); this.getDefaults().setDescription("Automatically cooks fish if what is caught is raw."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.4); @@ -58,10 +58,15 @@ public class SurvivalistEnchant extends ExcellentEnchant implements FishingEncha return EnchantmentTarget.FISHING_ROD; } + @NotNull + @Override + public EventPriority getFishingPriority() { + return EventPriority.HIGH; + } + @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; - if (!this.isAvailableToUse(event.getPlayer())) return false; if (!this.checkTriggerChance(level)) return false; if (!(event.getCaught() instanceof Item drop)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/ChanceImplementation.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/ChanceImplementation.java index 165121b..c1bad7f 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/ChanceImplementation.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/ChanceImplementation.java @@ -2,9 +2,9 @@ package su.nightexpress.excellentenchants.enchantment.impl.meta; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.random.Rnd; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; public final class ChanceImplementation implements Chanced { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java index 5f8f885..9ec91f2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java @@ -6,10 +6,10 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.Scaler; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; public final class PotionImplementation implements Potioned { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java similarity index 91% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java index 8c0042d..4f5af6d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantBlastMining.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/BlastMiningEnchant.java @@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.tool; import org.bukkit.block.Block; import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -12,6 +13,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.manager.EventListener; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; @@ -21,13 +23,12 @@ 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.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook; import java.util.List; -public class EnchantBlastMining extends ExcellentEnchant implements Chanced, BlockBreakEnchant { +public class BlastMiningEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, EventListener { public static final String ID = "blast_mining"; public static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%"; @@ -38,12 +39,12 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo private int explodeLevel; - public EnchantBlastMining(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public BlastMiningEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to mine blocks by explosion."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(1.0); - this.getDefaults().setConflicts(EnchantVeinminer.ID, EnchantTunnel.ID); + this.getDefaults().setConflicts(VeinminerEnchant.ID, TunnelEnchant.ID); } @Override @@ -98,8 +99,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(player)) return false; + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { + if (!(entity instanceof Player player)) return false; if (EnchantUtils.isBusy()) return false; Block block = event.getBlock(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java similarity index 83% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java index bc88ee9..cc0582b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfBreaking.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfBreakingEnchant.java @@ -7,17 +7,18 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.manager.EventListener; 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.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.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced { +public class CurseOfBreakingEnchant extends ExcellentEnchant implements GenericEnchant, EventListener, Chanced { public static final String ID = "curse_of_breaking"; public static final String PLACEHOLDER_DURABILITY_AMOUNT = "%enchantment_durability_amount%"; @@ -25,8 +26,8 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced private EnchantScaler durabilityAmount; private ChanceImplementation chanceImplementation; - public EnchantCurseOfBreaking(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public CurseOfBreakingEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to consume extra " + PLACEHOLDER_DURABILITY_AMOUNT + " durability points."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0D); @@ -66,11 +67,11 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onItemDurability(PlayerItemDamageEvent e) { - Player player = e.getPlayer(); + public void onItemDurability(PlayerItemDamageEvent event) { + Player player = event.getPlayer(); if (!this.isAvailableToUse(player)) return; - ItemStack item = e.getItem(); + ItemStack item = event.getItem(); int level = EnchantUtils.getLevel(item, this); if (level < 1) return; @@ -79,6 +80,6 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced int durabilityAmount = this.getDurabilityAmount(level); if (durabilityAmount <= 0) return; - e.setDamage(e.getDamage() + durabilityAmount); + event.setDamage(event.getDamage() + durabilityAmount); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java index 6607314..d167001 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMediocrityEnchant.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.tool; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; @@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant, DeathEnchant { @@ -25,7 +25,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance private ChanceImplementation chanceImplementation; public CurseOfMediocrityEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to disenchant item drops."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0D); @@ -49,6 +49,12 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance return new FitItemType[] {FitItemType.WEAPON, FitItemType.TOOL}; } + @NotNull + @Override + public EventPriority getDropPriority() { + return EventPriority.HIGHEST; + } + @NotNull @Override public Chanced getChanceImplementation() { @@ -62,8 +68,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance @Override public boolean onDrop(@NotNull BlockDropItemEvent event, - @NotNull Player player, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(player)) return false; + @NotNull LivingEntity player, @NotNull ItemStack item, int level) { if (!this.checkTriggerChance(level)) return false; event.getItems().forEach(drop -> { @@ -84,7 +89,6 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(killer)) return false; if (!this.checkTriggerChance(level)) return false; event.getDrops().forEach(stack -> { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java similarity index 86% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java index 7e4098f..683f37c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantCurseOfMisfortune.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/CurseOfMisfortuneEnchant.java @@ -4,6 +4,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; @@ -11,23 +12,22 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chanced, BlockBreakEnchant, DeathEnchant { +public class CurseOfMisfortuneEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, DeathEnchant { public static final String ID = "curse_of_misfortune"; private boolean dropExp; private ChanceImplementation chanceImplementation; - public EnchantCurseOfMisfortune(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + public CurseOfMisfortuneEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to have no drops from blocks or mobs."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0D); @@ -68,14 +68,25 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance return EnchantmentTarget.BREAKABLE; } + @NotNull + @Override + public EventPriority getBreakPriority() { + return EventPriority.HIGHEST; + } + + @NotNull + @Override + public EventPriority getKillPriority() { + return EventPriority.HIGH; + } + @Override public boolean isCursed() { return true; } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(player)) return false; + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { if (!this.checkTriggerChance(level)) return false; event.setDropItems(false); @@ -85,7 +96,6 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(killer)) return false; if (!this.checkTriggerChance(level)) return false; event.getDrops().clear(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/DivineTouchEnchant.java similarity index 80% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/DivineTouchEnchant.java index d9871c2..a3f649d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantDivineTouch.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/DivineTouchEnchant.java @@ -8,6 +8,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.CreatureSpawner; import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -16,10 +17,12 @@ import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; -import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; +import su.nexmedia.engine.api.manager.EventListener; +import su.nexmedia.engine.lang.LangManager; import su.nexmedia.engine.utils.Colorizer; +import su.nexmedia.engine.utils.Colors; import su.nexmedia.engine.utils.LocationUtil; import su.nexmedia.engine.utils.PDCUtil; import su.nexmedia.engine.utils.values.UniParticle; @@ -31,39 +34,41 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant { +public class DivineTouchEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant, EventListener { public static final String ID = "divine_touch"; - private static final String META_HANDLE = ID + "_handle"; + + private final NamespacedKey key; private String spawnerName; private ChanceImplementation chanceImplementation; - private final NamespacedKey key; + private Location handleSpawner; - public EnchantDivineTouch(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public DivineTouchEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.key = new NamespacedKey(plugin, "divine_spawner"); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to mine spawner."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(1.0); - this.getDefaults().setConflicts(EnchantSmelter.ID); + this.getDefaults().setConflicts(SmelterEnchant.ID); } @Override public void loadSettings() { super.loadSettings(); + this.chanceImplementation = ChanceImplementation.create(this, "15.0 * " + Placeholders.ENCHANTMENT_LEVEL); + this.spawnerName = JOption.create("Settings.Spawner_Item.Name", - "&aMob Spawner &7(" + Placeholders.GENERIC_TYPE + ")", + Colors.GREEN + "Mob Spawner " + Colors.GRAY + "(" + Placeholders.GENERIC_TYPE + ")", "Spawner item display name.", - "Placeholder '" + Placeholders.GENERIC_TYPE + "' for the mob type.") - .mapReader(Colorizer::apply).read(cfg); + "Placeholder '" + Placeholders.GENERIC_TYPE + "' for the mob type." + ).mapReader(Colorizer::apply).read(cfg); } @NotNull @@ -84,6 +89,18 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo return EnchantmentTarget.TOOL; } + @NotNull + @Override + public EventPriority getDropPriority() { + return EventPriority.NORMAL; + } + + @NotNull + @Override + public EventPriority getBreakPriority() { + return EventPriority.HIGH; + } + @NotNull public ItemStack getSpawner(@NotNull CreatureSpawner spawnerBlock) { ItemStack itemSpawner = new ItemStack(Material.SPAWNER); @@ -94,7 +111,7 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo spawnerItem.setSpawnedType(spawnerBlock.getSpawnedType()); spawnerItem.update(true); stateItem.setBlockState(spawnerItem); - stateItem.setDisplayName(this.spawnerName.replace(Placeholders.GENERIC_TYPE, plugin.getLangManager().getEnum(spawnerBlock.getSpawnedType()))); + stateItem.setDisplayName(this.spawnerName.replace(Placeholders.GENERIC_TYPE, LangManager.getEntityType(spawnerBlock.getSpawnedType()))); itemSpawner.setItemMeta(stateItem); PDCUtil.set(itemSpawner, this.key, true); @@ -102,10 +119,12 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo } @Override - public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { + public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { BlockState state = event.getBlockState(); Block block = state.getBlock(); - if (!block.hasMetadata(META_HANDLE)) return false; + if (this.handleSpawner == null || !this.handleSpawner.equals(block.getLocation())) return false; + this.handleSpawner = null; + if (!(state instanceof CreatureSpawner spawnerBlock)) return false; EnchantUtils.popResource(event, this.getSpawner(spawnerBlock)); @@ -114,20 +133,18 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo Location location = LocationUtil.getCenter(block.getLocation()); UniParticle.of(Particle.VILLAGER_HAPPY).play(location, 0.3, 0.15, 30); } - block.removeMetadata(META_HANDLE, this.plugin); return true; } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { Block block = event.getBlock(); - if (!this.isAvailableToUse(player)) return false; if (!(block.getState() instanceof CreatureSpawner spawnerBlock)) return false; if (!this.checkTriggerChance(level)) return false; event.setExpToDrop(0); event.setDropItems(true); - block.setMetadata(META_HANDLE, new FixedMetadataValue(this.plugin, true)); + this.handleSpawner = block.getLocation(); return false; // Do not consume charges } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java similarity index 84% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java index 2ed436e..4fd578b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantHaste.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/HasteEnchant.java @@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation; -public class EnchantHaste extends ExcellentEnchant implements Potioned, PassiveEnchant { +public class HasteEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant { public static final String ID = "haste"; private PotionImplementation potionImplementation; - public EnchantHaste(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public HasteEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -46,8 +45,6 @@ public class EnchantHaste extends ExcellentEnchant implements Potioned, PassiveE @Override public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(entity)) return false; - return this.addEffect(entity, level); } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java similarity index 87% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java index 0c559cd..0a90278 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantLuckyMiner.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/LuckyMinerEnchant.java @@ -1,7 +1,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.tool; import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -14,9 +14,8 @@ 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.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, BlockBreakEnchant { +public class LuckyMinerEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant { public static final String ID = "lucky_miner"; private static final String PLACEHOLDER_EXP_MODIFIER = "%enchantment_exp_modifier%"; @@ -24,8 +23,8 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc private EnchantScaler expModifier; private ChanceImplementation chanceImplementation; - public EnchantLuckyMiner(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public LuckyMinerEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to gain " + PLACEHOLDER_EXP_MODIFIER + "% more exp from ores."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.1); @@ -66,8 +65,7 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(player)) return false; + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { if (!this.checkTriggerChance(level)) return false; double expMod = this.getExpModifier(level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java similarity index 92% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java index 54cf16b..9d09522 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantReplanter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/ReplanterEnchant.java @@ -7,7 +7,9 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.data.Ageable; import org.bukkit.block.data.BlockData; import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -23,11 +25,10 @@ import su.nightexpress.excellentenchants.api.enchantment.type.InteractEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.Set; -public class EnchantReplanter extends ExcellentEnchant implements Chanced, InteractEnchant, BlockBreakEnchant { +public class ReplanterEnchant extends ExcellentEnchant implements Chanced, InteractEnchant, BlockBreakEnchant { public static final String ID = "replanter"; @@ -41,8 +42,8 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter Material.MELON_SEEDS, Material.PUMPKIN_SEEDS, Material.POTATO, Material.CARROT, Material.NETHER_WART); - public EnchantReplanter(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGH); + public ReplanterEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Automatically replant crops on right click and when harvest."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.3); @@ -119,10 +120,16 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter return EnchantmentTarget.TOOL; } + @NotNull @Override - public boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { + public EventPriority getInteractPriority() { + return EventPriority.HIGHEST; + } + + @Override + public boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { + if (!(entity instanceof Player player)) return false; if (!this.isReplantOnRightClick()) return false; - if (!this.isAvailableToUse(player)) return false; if (!this.checkTriggerChance(level)) return false; // Check for a event hand. We dont want to trigger it twice. @@ -158,9 +165,9 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { + if (!(entity instanceof Player player)) return false; if (!this.isReplantOnPlantBreak()) return false; - if (!this.isAvailableToUse(player)) return false; if (!this.checkTriggerChance(level)) return false; Block blockPlant = event.getBlock(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java similarity index 93% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java index f00a733..78b0f2e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSilkChest.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SilkChestEnchant.java @@ -6,6 +6,7 @@ import org.bukkit.block.BlockState; import org.bukkit.block.Chest; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -20,6 +21,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; +import su.nexmedia.engine.api.manager.EventListener; import su.nexmedia.engine.utils.Colorizer; import su.nexmedia.engine.utils.ItemUtil; import su.nexmedia.engine.utils.PDCUtil; @@ -28,14 +30,13 @@ import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; -public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEnchant { +public class SilkChestEnchant extends ExcellentEnchant implements BlockDropEnchant, EventListener { public static final String ID = "silk_chest"; @@ -43,8 +44,8 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha private List chestLore; private final NamespacedKey keyChest; - public EnchantSilkChest(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGH); + public SilkChestEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Drop chests and saves all its content."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.5); @@ -75,6 +76,12 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha return EnchantmentTarget.TOOL; } + @NotNull + @Override + public EventPriority getDropPriority() { + return EventPriority.NORMAL; + } + public boolean isSilkChest(@NotNull ItemStack item) { return PDCUtil.getBoolean(item, this.keyChest).isPresent(); } @@ -131,11 +138,10 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha @Override public boolean onDrop(@NotNull BlockDropItemEvent event, - @NotNull Player player, @NotNull ItemStack item, int level) { + @NotNull LivingEntity player, @NotNull ItemStack item, int level) { BlockState state = event.getBlockState(); Block block = state.getBlock(); - if (!this.isAvailableToUse(player)) return false; if (!(state instanceof Chest chest)) return false; // Добавляем в сундук обратно предметы из дроп листа, кроме самого сундука. diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java similarity index 91% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java index 1f771cb..13d347c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantSmelter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/SmelterEnchant.java @@ -8,7 +8,8 @@ import org.bukkit.block.Block; import org.bukkit.block.Container; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -23,11 +24,10 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.Map; -public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDropEnchant { +public class SmelterEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant { public static final String ID = "smelter"; @@ -35,13 +35,13 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr private Map smeltingTable; private ChanceImplementation chanceImplementation; - public EnchantSmelter(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public SmelterEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to smelt a block/ore."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.3); this.getDefaults().setConflicts( - EnchantDivineTouch.ID, + DivineTouchEnchant.ID, Enchantment.SILK_TOUCH.getKey().getKey() ); } @@ -88,12 +88,17 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr return EnchantmentTarget.TOOL; } + @NotNull @Override - public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { + public EventPriority getDropPriority() { + return EventPriority.NORMAL; + } + + @Override + public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { // TODO Use furnace recipes & Re-add smelted items instead of setType if (event.getBlockState() instanceof Container) return false; - if (!this.isAvailableToUse(player)) return false; if (!this.checkTriggerChance(level)) return false; if (event.getItems().stream().noneMatch(drop -> this.isSmeltable(drop.getItemStack().getType()))) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java similarity index 71% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java index 756224f..2888a2a 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTelekinesis.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TelekinesisEnchant.java @@ -1,8 +1,9 @@ package su.nightexpress.excellentenchants.enchantment.impl.tool; import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -13,19 +14,15 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -import java.util.ArrayList; -import java.util.List; - -public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, BlockDropEnchant { +public class TelekinesisEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant { public static final String ID = "telekinesis"; private ChanceImplementation chanceImplementation; - public EnchantTelekinesis(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + public TelekinesisEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Moves all blocks loot directly to your inventory."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.75); @@ -55,18 +52,21 @@ public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, Blo return EnchantmentTarget.TOOL; } + @NotNull @Override - public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { - if (!this.isAvailableToUse(player)) return false; + public EventPriority getDropPriority() { + return EventPriority.HIGHEST; + } + + @Override + public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { + if (!(entity instanceof Player player)) return false; if (!this.checkTriggerChance(level)) return false; - List drops = new ArrayList<>(event.getItems().stream().map(Item::getItemStack).toList()); - //drops.addAll(dropContainer.getDrop()); - //drops.removeIf(Objects::isNull); - drops.forEach(drop -> PlayerUtil.addItem(player, drop)); - + event.getItems().forEach(drop -> { + PlayerUtil.addItem(player, drop.getItemStack()); + }); event.getItems().clear(); - return true; } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TreasuresEnchant.java similarity index 85% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TreasuresEnchant.java index 6de1f92..2fc01e7 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTreasures.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TreasuresEnchant.java @@ -4,11 +4,11 @@ import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.enchantments.EnchantmentTarget; -import org.bukkit.entity.Player; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.blocktracker.PlayerBlockTracker; import su.nexmedia.engine.utils.random.Rnd; @@ -21,24 +21,24 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.*; import java.util.function.Predicate; -public class EnchantTreasures extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant, Cleanable { +public class TreasuresEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant, Cleanable { public static final String ID = "treasures"; - @Deprecated private static final String META = "wasted"; + + private final Predicate blockTracker; private Map> treasures; private ChanceImplementation chanceImplementation; - private final Predicate blockTracker; + private Block handleDrop; - public EnchantTreasures(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public TreasuresEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to attempt to find a treasure in mined block."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.1); @@ -126,29 +126,31 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block return EnchantmentTarget.TOOL; } + @NotNull @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { - if (PlayerBlockTracker.isTracked(event.getBlock())) { - event.getBlock().setMetadata(META, new FixedMetadataValue(plugin, true)); - } + public EventPriority getDropPriority() { + return EventPriority.NORMAL; + } + + @Override + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { + if (!event.isDropItems()) return false; + if (PlayerBlockTracker.isTracked(event.getBlock())) return false; + + this.handleDrop = event.getBlock(); return false; } @Override - public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { - Block block = event.getBlockState().getBlock(); - if (block.hasMetadata(META)) { - block.removeMetadata(META, plugin); - return false; - } - if (!this.isAvailableToUse(player)) return false; + public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) { + if (this.handleDrop != event.getBlock()) return false; + this.handleDrop = null; + if (!this.checkTriggerChance(level)) return false; this.getTreasures(event.getBlockState().getType()).forEach(treasure -> { EnchantUtils.popResource(event, treasure); }); - - //dropContainer.getDrop().addAll(this.getTreasures(event.getBlockState().getType())); return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java similarity index 90% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java index dc540a7..1bae4ef 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantTunnel.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/TunnelEnchant.java @@ -4,17 +4,16 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; -import su.nexmedia.engine.utils.EntityUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook; @@ -22,7 +21,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant { +public class TunnelEnchant extends ExcellentEnchant implements BlockBreakEnchant { public static final String ID = "tunnel"; // X and Z offsets for each block AoE mined @@ -36,13 +35,13 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant private boolean disableOnSneak; - public EnchantTunnel(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGH); + public TunnelEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Mines multiple blocks at once in a certain shape."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(1.0); - this.getDefaults().setConflicts(EnchantVeinminer.ID, EnchantBlastMining.ID); + this.getDefaults().setConflicts(VeinminerEnchant.ID, BlastMiningEnchant.ID); } @Override @@ -65,9 +64,9 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) { + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) { + if (!(entity instanceof Player player)) return false; if (EnchantUtils.isBusy()) return false; - if (!this.isAvailableToUse(player)) return false; if (this.disableOnSneak && player.isSneaking()) return false; Block block = event.getBlock(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java similarity index 91% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java index a11e299..7c2bb15 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/EnchantVeinminer.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/tool/VeinminerEnchant.java @@ -5,6 +5,7 @@ import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; @@ -17,7 +18,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.type.FitItemType; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook; @@ -26,7 +26,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnchant { +public class VeinminerEnchant extends ExcellentEnchant implements BlockBreakEnchant { public static final String ID = "veinminer"; @@ -40,13 +40,13 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch private Scaler blocksLimit; private Set blocksAffected; - public EnchantVeinminer(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.HIGH); + public VeinminerEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Mines up to " + PLACEHOLDER_BLOCK_LIMIT + " blocks of the ore vein at once."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); - this.getDefaults().setConflicts(EnchantBlastMining.ID, EnchantTunnel.ID); + this.getDefaults().setConflicts(BlastMiningEnchant.ID, TunnelEnchant.ID); } @Override @@ -125,8 +125,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch } @Override - public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack tool, int level) { - if (!this.isAvailableToUse(player)) return false; + public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack tool, int level) { + if (!(entity instanceof Player player)) return false; if (EnchantUtils.isBusy()) return false; Block block = event.getBlock(); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/EnchantCurseOfFragility.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java similarity index 89% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/EnchantCurseOfFragility.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java index 01a729c..9e12173 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/EnchantCurseOfFragility.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/CurseOfFragilityEnchant.java @@ -11,17 +11,18 @@ import org.bukkit.inventory.AnvilInventory; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.manager.EventListener; import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class EnchantCurseOfFragility extends ExcellentEnchant { +public class CurseOfFragilityEnchant extends ExcellentEnchant implements GenericEnchant, EventListener { public static final String ID = "curse_of_fragility"; - public EnchantCurseOfFragility(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + public CurseOfFragilityEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID); this.getDefaults().setDescription("Prevents an item from being grindstoned or anviled."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0D); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java index 99c968a..c68ebf2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/universal/SoulboundEnchant.java @@ -9,20 +9,21 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.manager.EventListener; import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.ArrayList; import java.util.List; -public class SoulboundEnchant extends ExcellentEnchant { +public class SoulboundEnchant extends ExcellentEnchant implements GenericEnchant, EventListener { public static final String ID = "soulbound"; public SoulboundEnchant(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription("Protects from being dropped on death."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.8); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java index a9f742d..5c9a91b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBaneOfNetherspawn.java @@ -15,7 +15,6 @@ import su.nightexpress.excellentenchants.Placeholders; 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.util.EnchantPriority; import java.util.Set; @@ -36,7 +35,7 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat private EnchantScaler damageFormula; public EnchantBaneOfNetherspawn(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Inflicts " + PLACEHOLDER_DAMAGE + " more damage to nether mobs."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.1); @@ -67,7 +66,6 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { if (!ENTITY_TYPES.contains(victim.getType())) return false; - if (!this.isAvailableToUse(damager)) return false; double damageEvent = event.getDamage(); double damageAdd = this.getDamageModifier(level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java index 3342488..98a9c73 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantBlindness.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Particle; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio private PotionImplementation potionImplementation; public EnchantBlindness(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); @@ -60,9 +60,14 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java index 5b8acec..6bd0e12 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantConfusion.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Material; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio private PotionImplementation potionImplementation; public EnchantConfusion(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); @@ -60,9 +60,14 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java index 55e1d9e..3422111 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCure.java @@ -4,6 +4,7 @@ import com.google.common.collect.Sets; import org.bukkit.Particle; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.*; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; 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.util.EnchantPriority; import java.util.Set; @@ -27,7 +27,7 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch private static final Set CUREABLE = Sets.newHashSet(EntityType.ZOMBIFIED_PIGLIN, EntityType.ZOMBIE_VILLAGER); public EnchantCure(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to cure Zombified Piglins and Zombie Villagers on hit."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.5); @@ -52,9 +52,14 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch 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.isAvailableToUse(damager)) return false; if (!CUREABLE.contains(victim.getType())) return false; if (!this.checkTriggerChance(level)) return false; if (!(damager instanceof Player player)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java index bf87080..f7ed994 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantCutter.java @@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; @@ -23,7 +24,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -36,7 +36,7 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn private boolean allowMobs; public EnchantCutter(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to throw away enemy''s armor and damage it for " + PLACEHOLDER_DURABILITY_DAMAGE + "%."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.75); @@ -76,10 +76,14 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn 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.isAvailableToUse(damager)) return false; - EntityEquipment equipment = victim.getEquipment(); if (equipment == null) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java index 44201c6..8a90738 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java @@ -29,7 +29,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.HashMap; import java.util.Map; @@ -48,7 +47,7 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea private final NamespacedKey skullKey; public EnchantDecapitator(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain player''s or mob''s head."); this.getDefaults().setLevelMax(4); this.getDefaults().setTier(0.75); @@ -185,8 +184,6 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(entity)) return false; - EntityType entityType = entity.getType(); if (this.ignoredEntityTypes.contains(entityType)) return false; if (!this.checkTriggerChance(level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java index 7e26d9f..12f8ede 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDoubleStrike.java @@ -4,6 +4,7 @@ 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; @@ -15,7 +16,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; 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.util.EnchantPriority; public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -24,7 +24,7 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co private ChanceImplementation chanceImplementation; public EnchantDoubleStrike(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOW); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to inflict double damage."); this.getDefaults().setLevelMax(4); this.getDefaults().setTier(1.0); @@ -49,9 +49,14 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; event.setDamage(event.getDamage() * 2D); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java index e538f56..38c2f34 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExhaust.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Material; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione private PotionImplementation potionImplementation; public EnchantExhaust(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); @@ -60,9 +60,14 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java index 64faa91..0217c56 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantExpHunter.java @@ -12,7 +12,6 @@ import su.nightexpress.excellentenchants.Placeholders; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant { @@ -22,7 +21,7 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant { private EnchantScaler expModifier; public EnchantExpHunter(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Increases exp drop from mobs by " + PLACEHOLDER_EXP_MODIFIER + "%."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.3); @@ -50,8 +49,6 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant { @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(entity)) return false; - double expModifier = this.getExpModifier(level); double expFinal = Math.ceil((double) event.getDroppedExp() * expModifier); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java index df2354c..22355c1 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Material; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio private PotionImplementation potionImplementation; public EnchantIceAspect(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Freezes and applies " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); @@ -59,9 +59,14 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java index b0600c6..734106c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantInfernus.java @@ -10,15 +10,16 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.manager.EventListener; import su.nexmedia.engine.utils.NumberUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; +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.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; -public class EnchantInfernus extends ExcellentEnchant { +public class EnchantInfernus extends ExcellentEnchant implements GenericEnchant, EventListener { public static final String ID = "infernus"; public static final String PLACEHOLDER_FIRE_DURATION = "%enchantment_fire_duration%"; @@ -26,7 +27,7 @@ public class EnchantInfernus extends ExcellentEnchant { private EnchantScaler fireTicks; public EnchantInfernus(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Launched trident will ignite the enemy for " + PLACEHOLDER_FIRE_DURATION + "s. on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.1); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java index 0e1d620..f0b9c90 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantNimble.java @@ -3,15 +3,15 @@ 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.EventPriority; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.utils.PlayerUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnchant { @@ -21,7 +21,7 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc private ChanceImplementation chanceImplementation; public EnchantNimble(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription("Moves all mob's loot directly to your inventory."); this.getDefaults().setLevelMax(1); this.getDefaults().setTier(0.4); @@ -45,9 +45,14 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc return EnchantmentTarget.WEAPON; } + @NotNull + @Override + public EventPriority getKillPriority() { + return EventPriority.HIGHEST; + } + @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(entity)) return false; if (!this.checkTriggerChance(level)) return false; event.getDrops().forEach(item -> PlayerUtil.addItem(killer, item)); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java index fd55183..e06a05d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantParalyze.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Particle; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion private PotionImplementation potionImplementation; public EnchantParalyze(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -60,9 +60,14 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java index 312c288..077c4e0 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRage.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Particle; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned, private PotionImplementation potionImplementation; public EnchantRage(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to get " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.5); @@ -60,9 +60,14 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned, 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(damager, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java index d928f75..4627fcf 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantRocket.java @@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.FireworkMeta; @@ -18,7 +19,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -28,7 +28,7 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn private ChanceImplementation chanceImplementation; public EnchantRocket(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch your enemy into the space."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.5); @@ -60,9 +60,14 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (victim.isInsideVehicle()) { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java index 55be0dd..19da38d 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantScavenger.java @@ -17,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.HashMap; import java.util.Map; @@ -31,7 +30,7 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death private ChanceImplementation chanceImplementation; public EnchantScavenger(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain additional loot from mobs."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -100,8 +99,6 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(entity)) return false; - Map> items = this.loot.get(entity.getType()); if (items == null) return false; 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 ab646a7..5a33521 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 @@ -4,6 +4,7 @@ import org.bukkit.Color; import org.bukkit.Particle; 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.PotionEffect; @@ -19,7 +20,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -29,7 +29,7 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion private PotionImplementation potionImplementation; public EnchantSurprise(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply random potion effect to enemy on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.75); @@ -63,9 +63,14 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; PotionEffect effect = new PotionEffect(Rnd.get(PotionEffectType.values()), this.getEffectDuration(level), Math.max(0, this.getEffectAmplifier(level) - 1), false, false); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java index 0cc08a8..8eba614 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantTemper.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.attribute.Attribute; 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; @@ -13,7 +14,6 @@ import su.nightexpress.excellentenchants.Placeholders; 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.util.EnchantPriority; public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { @@ -27,7 +27,7 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { private EnchantScaler healthPoint; public EnchantTemper(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Inflicts " + PLACEHOLDER_DAMAGE_AMOUNT + "% (max. " + PLACEHOLDER_DAMAGE_CAPACITY + "%) more damage for each " + PLACEHOLDER_HEALTH_POINT + " hearts missing."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.3); @@ -67,10 +67,14 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant { return EnchantmentTarget.WEAPON; } + @NotNull + @Override + public EventPriority getAttackPriority() { + return EventPriority.NORMAL; + } + @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(damager)) return false; - double healthPoint = this.getHealthPoint(level); double healthHas = damager.getHealth(); double healthMax = EntityUtil.getAttribute(damager, Attribute.GENERIC_MAX_HEALTH); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java index e7f2b83..bde26a3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java @@ -20,7 +20,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import java.util.Objects; import java.util.Set; @@ -37,7 +36,7 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn private ChanceImplementation chanceImplementation; public EnchantThrifty(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain mob spawn egg on kill."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.75); @@ -82,8 +81,6 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn @Override public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) { - if (!this.isAvailableToUse(entity)) return false; - if (this.ignoredEntityTypes.contains(entity.getType())) return false; if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false; if (!this.checkTriggerChance(level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java index 85a6447..269ccec 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThunder.java @@ -12,10 +12,9 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.config.JOption; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -28,7 +27,7 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE private ChanceImplementation chanceImplementation; public EnchantThunder(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to summon lightning to enemy on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -59,9 +58,14 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE 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.isAvailableToUse(damager)) return false; if (this.isInThunderstormOnly() && !victim.getWorld().isThundering()) return false; if (victim.getLocation().getBlock().getLightFromSky() != 15) return false; if (!this.checkTriggerChance(level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java index c2fb76e..a1e6f07 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVampire.java @@ -4,6 +4,7 @@ import org.bukkit.Particle; import org.bukkit.attribute.Attribute; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.inventory.ItemStack; @@ -19,7 +20,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatEnchant { @@ -31,7 +31,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE private ChanceImplementation chanceImplementation; public EnchantVampire(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.LOWEST); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to heal for " + PLACEHOLDER_HEAL_AMOUNT + " heart(s) on hit."); this.getDefaults().setLevelMax(4); this.getDefaults().setTier(0.75); @@ -72,10 +72,14 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE return EnchantmentTarget.WEAPON; } + @NotNull + @Override + public EventPriority getAttackPriority() { + return EventPriority.MONITOR; + } + @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(damager)) return false; - double healthMax = EntityUtil.getAttribute(damager, Attribute.GENERIC_MAX_HEALTH); double healthHas = damager.getHealth(); if (healthHas == healthMax) return false; @@ -83,7 +87,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE if (!this.checkTriggerChance(level)) return false; double healAmount = this.getHealAmount(level); - double healFinal = this.isHealMultiplier() ? event.getDamage() * healAmount : healAmount; + double healFinal = this.isHealMultiplier() ? event.getFinalDamage() * healAmount : healAmount; EntityRegainHealthEvent healthEvent = new EntityRegainHealthEvent(damager, healFinal, EntityRegainHealthEvent.RegainReason.CUSTOM); plugin.getPluginManager().callEvent(healthEvent); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java index 2703ad1..922fbb3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVenom.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Particle; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned, private PotionImplementation potionImplementation; public EnchantVenom(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.3); @@ -60,9 +60,14 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned, 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java index c79c404..719ea14 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantVillageDefender.java @@ -15,7 +15,6 @@ import su.nightexpress.excellentenchants.Placeholders; 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.util.EnchantPriority; public class EnchantVillageDefender extends ExcellentEnchant implements CombatEnchant { @@ -26,7 +25,7 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn private EnchantScaler damageAmount; public EnchantVillageDefender(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription("Inflicts " + PLACEHOLDER_DAMAGE_AMOUNT + " more damage to all pillagers."); this.getDefaults().setLevelMax(5); this.getDefaults().setTier(0.1); @@ -62,7 +61,6 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn @Override public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { - if (!this.isAvailableToUse(damager)) return false; if (!(victim instanceof Illager)) return false; double damageAdd = this.getDamageAddict(level); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java index f229498..3e8c7be 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantWither.java @@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; import org.bukkit.Particle; 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; @@ -16,7 +17,6 @@ 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; -import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant { @@ -26,7 +26,7 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned private PotionImplementation potionImplementation; public EnchantWither(@NotNull ExcellentEnchants plugin) { - super(plugin, ID, EnchantPriority.MEDIUM); + super(plugin, ID); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit."); this.getDefaults().setLevelMax(3); this.getDefaults().setTier(0.5); @@ -60,9 +60,14 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned 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.isAvailableToUse(damager)) return false; if (!this.checkTriggerChance(level)) return false; if (!this.addEffect(victim, level)) return false; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java index 14c2d0c..997a83b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantAnvilListener.java @@ -53,7 +53,7 @@ public class EnchantAnvilListener extends AbstractListener { this.handleEnchantMerging(e, first, second, result); } - private boolean handleRename(@NotNull PrepareAnvilEvent e, + private boolean handleRename(@NotNull PrepareAnvilEvent event, @NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) { if (!second.getType().isAir() && (second.getType() == first.getType() || second.getType() == Material.ENCHANTED_BOOK)) return false; @@ -64,11 +64,11 @@ public class EnchantAnvilListener extends AbstractListener { EnchantUtils.add(result2, hasEnch, hasLevel, true); }); EnchantUtils.updateDisplay(result2); - e.setResult(result2); + event.setResult(result2); return true; } - private boolean handleRecharge(@NotNull PrepareAnvilEvent e, + private boolean handleRecharge(@NotNull PrepareAnvilEvent event, @NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) { if (second.getType().isAir()) return false; @@ -90,12 +90,12 @@ public class EnchantAnvilListener extends AbstractListener { PDCUtil.set(result2, RECHARGED, count); EnchantUtils.updateDisplay(result2); - e.setResult(result2); - this.plugin.runTask(task -> e.getInventory().setRepairCost(chargable.size())); + event.setResult(result2); + this.plugin.runTask(task -> event.getInventory().setRepairCost(chargable.size())); return true; } - private boolean handleEnchantMerging(@NotNull PrepareAnvilEvent e, + private boolean handleEnchantMerging(@NotNull PrepareAnvilEvent event, @NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) { // Validate items in the first two slots. if (second.getType().isAir() || second.getAmount() > 1 || !EnchantUtils.isEnchantable(second)) return false; @@ -104,7 +104,7 @@ public class EnchantAnvilListener extends AbstractListener { ItemStack result2 = new ItemStack(result.getType().isAir() ? first : result); Map enchantments = EnchantUtils.getExcellents(first); Map charges = new HashMap<>(enchantments.keySet().stream().collect(Collectors.toMap(k -> k, v -> v.getCharges(first)))); - AtomicInteger repairCost = new AtomicInteger(e.getInventory().getRepairCost()); + AtomicInteger repairCost = new AtomicInteger(event.getInventory().getRepairCost()); // Merge only if it's Item + Item, Item + Enchanted book or Enchanted Book + Enchanted Book if (second.getType() == Material.ENCHANTED_BOOK || second.getType() == first.getType()) { @@ -125,31 +125,31 @@ public class EnchantAnvilListener extends AbstractListener { if (first.equals(result2)) return false; EnchantUtils.updateDisplay(result2); - e.setResult(result2); + event.setResult(result2); // NMS ContainerAnvil will set level cost to 0 right after calling the event, need 1 tick delay. - this.plugin.runTask(task -> e.getInventory().setRepairCost(repairCost.get())); + this.plugin.runTask(task -> event.getInventory().setRepairCost(repairCost.get())); return true; } @EventHandler(priority = EventPriority.NORMAL) - public void onClickAnvil(InventoryClickEvent e) { - if (!(e.getInventory() instanceof AnvilInventory inventory)) return; - if (e.getRawSlot() != 2) return; + public void onClickAnvil(InventoryClickEvent event) { + if (!(event.getInventory() instanceof AnvilInventory inventory)) return; + if (event.getRawSlot() != 2) return; - ItemStack item = e.getCurrentItem(); + ItemStack item = event.getCurrentItem(); if (item == null) return; int count = PDCUtil.getInt(item, RECHARGED).orElse(0); if (count == 0) return; - Player player = (Player) e.getWhoClicked(); + Player player = (Player) event.getWhoClicked(); if (player.getLevel() < inventory.getRepairCost()) return; player.setLevel(player.getLevel() - inventory.getRepairCost()); PDCUtil.remove(item, RECHARGED); - e.getView().setCursor(item); - e.setCancelled(false); + event.getView().setCursor(item); + event.setCancelled(false); UniSound.of(Sound.BLOCK_ENCHANTMENT_TABLE_USE).play(player); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java index bbd2e34..48a5ec2 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java @@ -2,14 +2,11 @@ package su.nightexpress.excellentenchants.enchantment.listener; import org.bukkit.World; import org.bukkit.block.Chest; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.enchantment.EnchantItemEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityPickupItemEvent; -import org.bukkit.event.entity.VillagerAcquireTradeEvent; +import org.bukkit.event.entity.*; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryType; @@ -24,6 +21,7 @@ import su.nexmedia.engine.utils.EngineUtils; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.enchantment.EnchantPopulator; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.type.ObtainType; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; @@ -39,21 +37,33 @@ public class EnchantGenericListener extends AbstractListener super(enchantManager.plugin()); } + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEnchantProjectileShoot(EntityShootBowEvent event) { + if (event.getProjectile() instanceof Projectile projectile) { + EnchantUtils.setSourceWeapon(projectile, event.getBow()); + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onEnchantProjectileLand(ProjectileHitEvent event) { + EnchantUtils.removeSourceWeapon(event.getEntity()); + } + // --------------------------------------------------------------- // Update enchantment lore after grindstone // --------------------------------------------------------------- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantUpdateGrindstoneClick(InventoryClickEvent e) { - Inventory inventory = e.getInventory(); + public void onEnchantUpdateGrindstoneClick(InventoryClickEvent event) { + Inventory inventory = event.getInventory(); if (inventory.getType() != InventoryType.GRINDSTONE) return; - if (e.getRawSlot() == 2) return; + if (event.getRawSlot() == 2) return; this.updateGrindstone(inventory); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantUpdateGrindstoneDrag(InventoryDragEvent e) { - Inventory inventory = e.getInventory(); + public void onEnchantUpdateGrindstoneDrag(InventoryDragEvent event) { + Inventory inventory = event.getInventory(); if (inventory.getType() != InventoryType.GRINDSTONE) return; this.updateGrindstone(inventory); @@ -80,10 +90,10 @@ public class EnchantGenericListener extends AbstractListener } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantUpdatePickup(EntityPickupItemEvent e) { - if (!(e.getEntity() instanceof Player player)) return; + public void onEnchantUpdatePickup(EntityPickupItemEvent event) { + if (!(event.getEntity() instanceof Player player)) return; - Item item = e.getItem(); + Item item = event.getItem(); ItemStack itemStack = item.getItemStack(); if (EnchantUtils.updateDisplay(itemStack)) { item.setItemStack(itemStack); @@ -98,13 +108,12 @@ public class EnchantGenericListener extends AbstractListener ItemStack target = event.getItem(); World world = event.getEnchanter().getWorld(); - Map enchantsPrepared = event.getEnchantsToAdd(); - Map enchantsToPopulate = EnchantUtils.getPopulationCandidates( - target, ObtainType.ENCHANTING, enchantsPrepared, - enchant -> enchant.getLevelByEnchantCost(event.getExpLevelCost()), - world); + EnchantPopulator populator = this.plugin.createPopulator(target, ObtainType.ENCHANTING) + .withWorld(world) + .withLevelGenerator(enchant -> enchant.getLevelByEnchantCost(event.getExpLevelCost())) + .withDefaultPopulation(event.getEnchantsToAdd()); - enchantsPrepared.putAll(enchantsToPopulate); + event.getEnchantsToAdd().putAll(populator.createPopulation()); plugin.getServer().getScheduler().runTask(plugin, () -> { ItemStack result = event.getInventory().getItem(0); @@ -141,10 +150,11 @@ public class EnchantGenericListener extends AbstractListener public void onEnchantPopulateVillagerAcquire(VillagerAcquireTradeEvent event) { MerchantRecipe recipe = event.getRecipe(); ItemStack result = recipe.getResult(); - World world = event.getEntity().getWorld(); - if (!EnchantUtils.isEnchantable(result)) return; - if (!EnchantUtils.populate(result, ObtainType.VILLAGER, world)) return; + + EnchantPopulator populator = this.plugin.createPopulator(result, ObtainType.VILLAGER) + .withWorld(event.getEntity().getWorld()); + if (!populator.populate()) return; int uses = recipe.getUses(); int maxUses = recipe.getMaxUses(); @@ -171,7 +181,9 @@ public class EnchantGenericListener extends AbstractListener if (entity instanceof Minecart || holder instanceof Chest) { event.getLoot().forEach(item -> { if (item != null && EnchantUtils.isEnchantable(item)) { - EnchantUtils.populate(item, ObtainType.LOOT_GENERATION, world); + this.plugin.createPopulator(item, ObtainType.LOOT_GENERATION) + .withWorld(world) + .populate(); } }); } @@ -186,15 +198,18 @@ public class EnchantGenericListener extends AbstractListener ItemStack itemStack = item.getItemStack(); World world = item.getWorld(); if (EnchantUtils.isEnchantable(itemStack)) { - EnchantUtils.populate(itemStack, ObtainType.FISHING, world); + this.plugin.createPopulator(itemStack, ObtainType.FISHING).withWorld(world).populate(); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantPopulateSpawn(CreatureSpawnEvent e) { + public void onEnchantPopulateSpawn(CreatureSpawnEvent event) { //if (Config.getObtainSettings(ObtainType.MOB_SPAWNING).isEmpty()) return; - LivingEntity entity = e.getEntity(); + LivingEntity entity = event.getEntity(); if (entity.getType() == EntityType.ARMOR_STAND) return; + if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) return; + if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) return; + if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) return; this.plugin.runTaskLater(task -> { EntityEquipment equipment = entity.getEquipment(); @@ -207,7 +222,9 @@ public class EnchantGenericListener extends AbstractListener for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack item = equipment.getItem(slot); if (EnchantUtils.isEnchantable(item)) { - if (doPopulation) EnchantUtils.populate(item, ObtainType.MOB_SPAWNING, world); + if (doPopulation) { + this.plugin.createPopulator(item, ObtainType.MOB_SPAWNING).withWorld(world).populate(); + } EnchantUtils.getExcellents(item).forEach((enchant, level) -> EnchantUtils.restoreCharges(item, enchant, level)); equipment.setItem(slot, item); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java index 6931d08..5a71e2c 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java @@ -1,82 +1,37 @@ package su.nightexpress.excellentenchants.enchantment.listener; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.Event.Result; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockDropItemEvent; -import org.bukkit.event.entity.*; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.api.manager.AbstractListener; -import su.nexmedia.engine.utils.EntityUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; -import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed; -import su.nightexpress.excellentenchants.api.enchantment.type.*; -import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.EnchantManager; -import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; public class EnchantHandlerListener extends AbstractListener { - private static final String META_PROJECTILE_WEAPON = "sourceWeapon"; - public EnchantHandlerListener(@NotNull EnchantManager enchantManager) { super(enchantManager.plugin()); } - private void setSourceWeapon(@NotNull Projectile projectile, @NotNull ItemStack item) { - projectile.setMetadata(META_PROJECTILE_WEAPON, new FixedMetadataValue(plugin, item)); - } - - @Nullable - private ItemStack getSourceWeapon(@NotNull Projectile projectile) { - return projectile.hasMetadata(META_PROJECTILE_WEAPON) ? (ItemStack) projectile.getMetadata(META_PROJECTILE_WEAPON).get(0).value() : null; - } - - private void removeSourceWeapon(@NotNull Projectile projectile) { - projectile.removeMetadata(META_PROJECTILE_WEAPON, plugin); - } - // --------------------------------------------------------------- // Combat Attacking Enchants // --------------------------------------------------------------- - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantCombatMelee(EntityDamageEvent e) { - if (e.getCause() == DamageCause.THORNS) return; - if (!(e.getEntity() instanceof LivingEntity victim)) return; + /*@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEnchantCombatMelee(EntityDamageEvent event) { + if (event.getCause() == DamageCause.THORNS) return; + if (!(event.getEntity() instanceof LivingEntity victim)) return; - if (e instanceof EntityDamageByEntityEvent ede) { - LivingEntity damager = null; - if (ede.getDamager() instanceof LivingEntity living) { - damager = living; - } - else if (ede.getDamager() instanceof Projectile pj && pj.getShooter() instanceof LivingEntity living) { - damager = living; - } - if (damager == null || damager.equals(victim)) return; - - if (ede.getDamager() instanceof Projectile projectile) { + if (event instanceof EntityDamageByEntityEvent ede) { + if (ede.getDamager() instanceof Projectile projectile && this.getSourceWeapon(projectile) != null) { this.handleCombatBowEnchants(ede, projectile, victim); + return; } - else { - this.handleCombatWeaponEnchants(ede, damager, victim); - } + + if (!(ede.getDamager() instanceof LivingEntity damager) || damager == victim) return; + + this.handleCombatWeaponEnchants(ede, damager, victim); this.handleCombatArmorEnchants(ede, damager, victim); } else { - this.handleArmorEnchants(e, victim); + this.handleArmorEnchants(event, victim); } } @@ -145,17 +100,17 @@ public class EnchantHandlerListener extends AbstractListener // Bow Shooting Enchants // --------------------------------------------------------------- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantBowShoot(EntityShootBowEvent e) { - LivingEntity shooter = e.getEntity(); + public void onEnchantBowShoot(EntityShootBowEvent event) { + LivingEntity shooter = event.getEntity(); if (shooter.getEquipment() == null) return; - ItemStack bow = e.getBow(); + ItemStack bow = event.getBow(); if (bow == null || bow.getType().isAir() || bow.getType() == Material.ENCHANTED_BOOK) return; EnchantUtils.getExcellents(bow, BowEnchant.class).forEach((bowEnchant, level) -> { if (bowEnchant.isOutOfCharges(bow)) return; - if (bowEnchant.onShoot(e, shooter, bow, level)) { - if (bowEnchant instanceof Arrowed arrowed && e.getProjectile() instanceof Projectile projectile) { + if (bowEnchant.onShoot(event, shooter, bow, level)) { + if (bowEnchant instanceof Arrowed arrowed && event.getProjectile() instanceof Projectile projectile) { arrowed.addData(projectile); arrowed.addTrail(projectile); } @@ -164,7 +119,7 @@ public class EnchantHandlerListener extends AbstractListener }); EnchantUtils.updateChargesDisplay(bow); - if (e.getProjectile() instanceof Projectile projectile) { + if (event.getProjectile() instanceof Projectile projectile) { this.setSourceWeapon(projectile, bow); } } @@ -173,35 +128,35 @@ public class EnchantHandlerListener extends AbstractListener // Bow Hit Land Enchants // --------------------------------------------------------------- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantBowHit(ProjectileHitEvent e) { - Projectile projectile = e.getEntity(); + public void onEnchantBowHit(ProjectileHitEvent event) { + Projectile projectile = event.getEntity(); ItemStack bow = this.getSourceWeapon(projectile); if (bow == null || bow.getType().isAir() || bow.getType() == Material.ENCHANTED_BOOK) return; EnchantUtils.getExcellents(bow, BowEnchant.class).forEach((bowEnchant, level) -> { - bowEnchant.onHit(e, projectile, bow, level); + bowEnchant.onHit(event, null, projectile, bow, level); }); // Prevent to apply enchants multiple times on hits. - this.plugin.getScheduler().runTask(this.plugin, c -> this.removeSourceWeapon(projectile)); + this.plugin.runTask(task -> this.removeSourceWeapon(projectile)); } // --------------------------------------------------------------- // Interaction Related Enchants // --------------------------------------------------------------- @EventHandler(priority = EventPriority.HIGHEST) - public void onEnchantInteract(PlayerInteractEvent e) { - if (e.useInteractedBlock() == Result.DENY) return; - if (e.useItemInHand() == Result.DENY) return; + public void onEnchantInteract(PlayerInteractEvent event) { + if (event.useInteractedBlock() == Result.DENY) return; + if (event.useItemInHand() == Result.DENY) return; - ItemStack item = e.getItem(); + ItemStack item = event.getItem(); if (item == null || item.getType().isAir() || item.getType() == Material.ENCHANTED_BOOK) return; - Player player = e.getPlayer(); + Player player = event.getPlayer(); EnchantUtils.getExcellents(item, InteractEnchant.class).forEach((interEnchant, level) -> { if (interEnchant.isOutOfCharges(item)) return; - if (interEnchant.onInteract(e, player, item, level)) { + if (interEnchant.onInteract(event, player, item, level)) { interEnchant.consumeChargesNoUpdate(item, level); } }); @@ -261,8 +216,8 @@ public class EnchantHandlerListener extends AbstractListener // Handle BlockBreak enchantments. @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEnchantBlockBreak(BlockBreakEvent e) { - Player player = e.getPlayer(); + public void onEnchantBlockBreak(BlockBreakEvent event) { + Player player = event.getPlayer(); if (player.getGameMode() == GameMode.CREATIVE) return; ItemStack tool = player.getInventory().getItemInMainHand(); @@ -270,7 +225,7 @@ public class EnchantHandlerListener extends AbstractListener EnchantUtils.getExcellents(tool, BlockBreakEnchant.class).forEach((blockEnchant, level) -> { if (blockEnchant.isOutOfCharges(tool)) return; - if (blockEnchant.onBreak(e, player, tool, level)) { + if (blockEnchant.onBreak(event, player, tool, level)) { blockEnchant.consumeChargesNoUpdate(tool, level); } }); @@ -285,7 +240,6 @@ public class EnchantHandlerListener extends AbstractListener ItemStack tool = player.getInventory().getItemInMainHand(); if (tool.getType().isAir() || tool.getType() == Material.ENCHANTED_BOOK) return; - //EnchantDropContainer dropContainer = new EnchantDropContainer(e); EnchantUtils.getExcellents(tool, BlockDropEnchant.class).forEach((enchant, level) -> { if (enchant.isOutOfCharges(tool)) return; if (enchant.onDrop(event, player, tool, level)) { @@ -293,11 +247,5 @@ public class EnchantHandlerListener extends AbstractListener } }); EnchantUtils.updateChargesDisplay(tool); - - //BlockState state = e.getBlockState(); - //World world = state.getWorld(); - //Location location = state.getLocation(); - - //dropContainer.getDrop().forEach(item -> world.dropItem(location, item)); - } + }*/ } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java index a7e1980..7e9a649 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/menu/EnchantmentsListMenu.java @@ -18,8 +18,8 @@ import su.nexmedia.engine.utils.PDCUtil; import su.nexmedia.engine.utils.StringUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.Placeholders; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.*; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/EnchantRegistry.java similarity index 50% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/EnchantRegistry.java index eee5431..a158045 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/EnchantRegistry.java @@ -1,21 +1,37 @@ -package su.nightexpress.excellentenchants.enchantment; +package su.nightexpress.excellentenchants.enchantment.registry; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.Event; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDropItemEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.Version; +import su.nexmedia.engine.api.manager.AbstractManager; import su.nexmedia.engine.utils.Reflex; import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; +import su.nightexpress.excellentenchants.api.enchantment.type.*; import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.armor.*; import su.nightexpress.excellentenchants.enchantment.impl.bow.*; import su.nightexpress.excellentenchants.enchantment.impl.fishing.*; import su.nightexpress.excellentenchants.enchantment.impl.tool.*; -import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility; +import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant; import su.nightexpress.excellentenchants.enchantment.impl.universal.SoulboundEnchant; import su.nightexpress.excellentenchants.enchantment.impl.weapon.*; +import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGather; +import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGathers; +import su.nightexpress.excellentenchants.enchantment.registry.wrapper.WrappedEvent; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.tier.Tier; @@ -23,18 +39,34 @@ import java.util.*; import java.util.function.Supplier; import java.util.stream.Collectors; -public class EnchantRegistry { +public class EnchantRegistry extends AbstractManager { public static final Map REGISTRY_MAP = new HashMap<>(); + private static final Map, Set> ENCHANTS_MAP = new HashMap<>(); - private final ExcellentEnchants plugin; private boolean isLocked; public EnchantRegistry(@NotNull ExcellentEnchants plugin) { - this.plugin = plugin; + super(plugin); } - public void setup() { + @Override + protected void onLoad() { + this.registerType(GenericEnchant.class); + this.registerType(PassiveEnchant.class); + + this.registerWrapper(BlockBreakEvent.class, BlockBreakEnchant.class, DataGathers.BLOCK_BREAK); + this.registerWrapper(BlockDropItemEvent.class, BlockDropEnchant.class, DataGathers.BLOCK_DROP); + this.registerWrapper(EntityShootBowEvent.class, BowEnchant.class, DataGathers.BOW_SHOOT); + this.registerWrapper(ProjectileHitEvent.class, BowEnchant.class, DataGathers.PROJECTILE_HIT); + this.registerWrapper(EntityDamageByEntityEvent.class, BowEnchant.class, DataGathers.ENTITY_DAMAGE_SHOOT); + this.registerWrapper(EntityDamageByEntityEvent.class, CombatEnchant.class, DataGathers.ENTITY_DAMAGE_ATTACK); + this.registerWrapper(EntityDamageByEntityEvent.class, CombatEnchant.class, DataGathers.ENTITY_DAMAGE_DEFENSE); + this.registerWrapper(EntityDeathEvent.class, DeathEnchant.class, DataGathers.ENTITY_KILL); + this.registerWrapper(EntityDeathEvent.class, DeathEnchant.class, DataGathers.ENTITY_DEATH); + this.registerWrapper(PlayerFishEvent.class, FishingEnchant.class, DataGathers.FISHING); + this.registerWrapper(PlayerInteractEvent.class, InteractEnchant.class, DataGathers.INTERACT); + // Prevent to register enchantments during the runtime. if (this.isLocked) { REGISTRY_MAP.values().forEach(enchant -> { @@ -46,7 +78,7 @@ public class EnchantRegistry { Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); - // Fising Enchants + // Fishing Enchants this.register(AutoReelEnchant.ID,() -> new AutoReelEnchant(plugin)); this.register(DoubleCatchEnchant.ID, () -> new DoubleCatchEnchant(plugin)); this.register(SeasonedAnglerEnchant.ID, () -> new SeasonedAnglerEnchant(plugin)); @@ -55,19 +87,19 @@ public class EnchantRegistry { this.register(RiverMasterEnchant.ID, () -> new RiverMasterEnchant(plugin)); // Tool enchants - this.register(EnchantBlastMining.ID, () -> new EnchantBlastMining(plugin)); - this.register(EnchantCurseOfBreaking.ID, () -> new EnchantCurseOfBreaking(plugin)); - this.register(EnchantCurseOfMisfortune.ID, () -> new EnchantCurseOfMisfortune(plugin)); - this.register(EnchantDivineTouch.ID, () -> new EnchantDivineTouch(plugin)); - this.register(EnchantHaste.ID, () -> new EnchantHaste(plugin)); - this.register(EnchantLuckyMiner.ID, () -> new EnchantLuckyMiner(plugin)); - this.register(EnchantReplanter.ID, () -> new EnchantReplanter(plugin)); - this.register(EnchantSilkChest.ID, () -> new EnchantSilkChest(plugin)); - this.register(EnchantSmelter.ID, () -> new EnchantSmelter(plugin)); - this.register(EnchantTelekinesis.ID, () -> new EnchantTelekinesis(plugin)); - this.register(EnchantTreasures.ID, () -> new EnchantTreasures(plugin)); - this.register(EnchantTunnel.ID, () -> new EnchantTunnel(plugin)); - this.register(EnchantVeinminer.ID, () -> new EnchantVeinminer(plugin)); + this.register(BlastMiningEnchant.ID, () -> new BlastMiningEnchant(plugin)); + this.register(CurseOfBreakingEnchant.ID, () -> new CurseOfBreakingEnchant(plugin)); + this.register(CurseOfMisfortuneEnchant.ID, () -> new CurseOfMisfortuneEnchant(plugin)); + this.register(DivineTouchEnchant.ID, () -> new DivineTouchEnchant(plugin)); + this.register(HasteEnchant.ID, () -> new HasteEnchant(plugin)); + this.register(LuckyMinerEnchant.ID, () -> new LuckyMinerEnchant(plugin)); + this.register(ReplanterEnchant.ID, () -> new ReplanterEnchant(plugin)); + this.register(SilkChestEnchant.ID, () -> new SilkChestEnchant(plugin)); + this.register(SmelterEnchant.ID, () -> new SmelterEnchant(plugin)); + this.register(TelekinesisEnchant.ID, () -> new TelekinesisEnchant(plugin)); + this.register(TreasuresEnchant.ID, () -> new TreasuresEnchant(plugin)); + this.register(TunnelEnchant.ID, () -> new TunnelEnchant(plugin)); + this.register(VeinminerEnchant.ID, () -> new VeinminerEnchant(plugin)); // Weapon enchants this.register(EnchantBaneOfNetherspawn.ID, () -> new EnchantBaneOfNetherspawn(plugin)); @@ -96,20 +128,20 @@ public class EnchantRegistry { this.register(EnchantWither.ID, () -> new EnchantWither(plugin)); // Armor enchants - this.register(EnchantAquaman.ID, () -> new EnchantAquaman(plugin)); - this.register(EnchantBunnyHop.ID, () -> new EnchantBunnyHop(plugin)); - this.register(EnchantColdSteel.ID, () -> new EnchantColdSteel(plugin)); - this.register(EnchantIceShield.ID, () -> new EnchantIceShield(plugin)); - this.register(EnchantElementalProtection.ID, () -> new EnchantElementalProtection(plugin)); - this.register(EnchantFireShield.ID, () -> new EnchantFireShield(plugin)); - this.register(EnchantFlameWalker.ID, () -> new EnchantFlameWalker(plugin)); - this.register(EnchantHardened.ID, () -> new EnchantHardened(plugin)); - this.register(EnchantNightVision.ID, () -> new EnchantNightVision(plugin)); - this.register(EnchantRegrowth.ID, () -> new EnchantRegrowth(plugin)); - this.register(EnchantSaturation.ID, () -> new EnchantSaturation(plugin)); - this.register(EnchantSelfDestruction.ID, () -> new EnchantSelfDestruction(plugin)); + this.register(AquamanEnchant.ID, () -> new AquamanEnchant(plugin)); + this.register(JumpingEnchant.ID, () -> new JumpingEnchant(plugin)); + this.register(ColdSteelEnchant.ID, () -> new ColdSteelEnchant(plugin)); + this.register(IceShieldEnchant.ID, () -> new IceShieldEnchant(plugin)); + this.register(ElementalProtectionEnchant.ID, () -> new ElementalProtectionEnchant(plugin)); + this.register(FireShieldEnchant.ID, () -> new FireShieldEnchant(plugin)); + this.register(FlameWalkerEnchant.ID, () -> new FlameWalkerEnchant(plugin)); + this.register(HardenedEnchant.ID, () -> new HardenedEnchant(plugin)); + this.register(NightVisionEnchant.ID, () -> new NightVisionEnchant(plugin)); + this.register(RegrowthEnchant.ID, () -> new RegrowthEnchant(plugin)); + this.register(SaturationEnchant.ID, () -> new SaturationEnchant(plugin)); + this.register(KamikadzeEnchant.ID, () -> new KamikadzeEnchant(plugin)); this.register(StoppingForceEnchant.ID, () -> new StoppingForceEnchant(plugin)); - this.register(EnchantSonic.ID, () -> new EnchantSonic(plugin)); + this.register(SpeedyEnchant.ID, () -> new SpeedyEnchant(plugin)); // Bow enchants this.register(EnchantBomber.ID, () -> new EnchantBomber(plugin)); @@ -130,36 +162,48 @@ public class EnchantRegistry { } // Universal - this.register(EnchantCurseOfFragility.ID, () -> new EnchantCurseOfFragility(plugin)); + this.register(CurseOfFragilityEnchant.ID, () -> new CurseOfFragilityEnchant(plugin)); this.register(CurseOfMediocrityEnchant.ID, () -> new CurseOfMediocrityEnchant(plugin)); this.register(SoulboundEnchant.ID, () -> new SoulboundEnchant(plugin)); Enchantment.stopAcceptingRegistrations(); - this.plugin.info("Enchantments Registered: " + getRegistered().size()); + this.plugin.info("Enchantments Registered: " + EnchantRegistry.getRegistered().size()); this.isLocked = true; } - /*@SuppressWarnings("unchecked") - public void shutdown() { - if (this.plugin.isEnabled()) return; // Prevent to unregister enchantments during the runtime. + @Override + protected void onShutdown() { + ENCHANTS_MAP.clear(); + } - Map byKey = (Map) Reflex.getFieldValue(Enchantment.class, "byKey"); - Map byName = (Map) Reflex.getFieldValue(Enchantment.class, "byName"); + public void registerType(@NotNull Class enchantClass) { + ENCHANTS_MAP.computeIfAbsent(enchantClass, k -> new HashSet<>()); + } - if (byKey == null || byName == null) return; + public void registerWrapper(@NotNull Class eventClass, + @NotNull Class enchantClass, + @NotNull DataGather dataGather) { - for (ExcellentEnchant enchant : REGISTRY_MAP.values()) { - if (enchant instanceof ICleanable cleanable) { - cleanable.clear(); - } - - byKey.remove(enchant.getKey()); - byName.remove(enchant.getName()); - enchant.unregisterListeners(); + for (EventPriority priority : EventPriority.values()) { + WrappedEvent event = new WrappedEvent<>(plugin, priority, eventClass, enchantClass, dataGather); + plugin.getPluginManager().registerEvent(eventClass, event, priority, event, plugin, true); } - REGISTRY_MAP.clear(); - this.plugin.info("All enchants are unregistered."); - }*/ + + this.registerType(enchantClass); + } + + private boolean registerEnchantType(@NotNull T enchant) { + Class enchantClass = enchant.getClass(); + + Set> assignables = ENCHANTS_MAP.keySet().stream().filter(clazz -> clazz.isAssignableFrom(enchantClass)).collect(Collectors.toSet()); + if (assignables.isEmpty()) { + this.plugin.warn("Could not register enchantment '" + enchant.getId() + "': Enchantment type is not registered."); + return false; + } + + assignables.forEach(clazz -> ENCHANTS_MAP.get(clazz).add(enchant)); + return true; + } private void register(@NotNull String id, @NotNull Supplier supplier) { if (Config.ENCHANTMENTS_DISABLED.get().contains(id)) return; @@ -171,6 +215,10 @@ public class EnchantRegistry { return; } + if (!this.registerEnchantType(enchant)) { + return; + } + Enchantment.registerEnchantment(enchant); REGISTRY_MAP.put(enchant.getKey(), enchant); enchant.loadSettings(); @@ -179,6 +227,18 @@ public class EnchantRegistry { this.plugin.info("Registered enchantment: " + enchant.getId()); } + @NotNull + public static Set getPeriodicTalents() { + return getEnchantments(PassiveEnchant.class); + } + + @NotNull + @SuppressWarnings("unchecked") + public static Set getEnchantments(@NotNull Class clazz) { + Set set = new HashSet<>(ENCHANTS_MAP.getOrDefault(clazz, Collections.emptySet())); + return (Set) set; + } + @Nullable public static ExcellentEnchant getById(@NotNull String id) { return getByKey(EnchantUtils.createKey(id)); @@ -196,8 +256,6 @@ public class EnchantRegistry { @NotNull public static Set getOfTier(@NotNull Tier tier) { - return getRegistered().stream().filter(enchant -> enchant.getTier() == tier) - .collect(Collectors.toCollection(HashSet::new)); + return getRegistered().stream().filter(enchant -> enchant.getTier() == tier).collect(Collectors.toCollection(HashSet::new)); } - } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java new file mode 100644 index 0000000..92c9679 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGather.java @@ -0,0 +1,31 @@ +package su.nightexpress.excellentenchants.enchantment.registry.wrapper; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.bukkit.event.EventPriority; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; +import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; + +import java.util.Map; + +public abstract class DataGather { + + @Nullable + public abstract LivingEntity getEntity(@NotNull E event); + + @NotNull + public abstract EquipmentSlot[] getEnchantSlots(@NotNull E event); + + public abstract boolean checkPriority(@NotNull T enchant, @NotNull EventPriority priority); + + @NotNull + public Map> getEnchants(@NotNull E event, @NotNull Class enchantClass, @NotNull LivingEntity entity) { + return EnchantUtils.getEquipped(entity, enchantClass, this.getEnchantSlots(event)); + } + + public abstract boolean useEnchant(@NotNull E event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull T enchant, int level); +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java new file mode 100644 index 0000000..0df6e3b --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/DataGathers.java @@ -0,0 +1,351 @@ +package su.nightexpress.excellentenchants.enchantment.registry.wrapper; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDropItemEvent; +import org.bukkit.event.entity.*; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed; +import su.nightexpress.excellentenchants.api.enchantment.type.*; +import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class DataGathers { + + public static final DataGather BLOCK_BREAK = new DataGather<>() { + + @Override + @NotNull + public LivingEntity getEntity(@NotNull BlockBreakEvent event) { + return event.getPlayer(); + } + + @Override + public boolean checkPriority(@NotNull BlockBreakEnchant enchant, @NotNull EventPriority priority) { + return enchant.getBreakPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull BlockBreakEvent event) { + return new EquipmentSlot[]{EquipmentSlot.HAND}; + } + + @Override + public boolean useEnchant(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BlockBreakEnchant enchant, int level) { + return enchant.onBreak(event, entity, item, level); + } + }; + + public static final DataGather BLOCK_DROP = new DataGather<>() { + + @Override + @NotNull + public LivingEntity getEntity(@NotNull BlockDropItemEvent event) { + return event.getPlayer(); + } + + @Override + public boolean checkPriority(@NotNull BlockDropEnchant enchant, @NotNull EventPriority priority) { + return enchant.getDropPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull BlockDropItemEvent event) { + return new EquipmentSlot[]{EquipmentSlot.HAND}; + } + + @Override + public boolean useEnchant(@NotNull BlockDropItemEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BlockDropEnchant enchant, int level) { + return enchant.onDrop(event, entity, item, level); + } + }; + + public static final DataGather BOW_SHOOT = new DataGather<>() { + + @Override + @NotNull + public LivingEntity getEntity(@NotNull EntityShootBowEvent event) { + return event.getEntity(); + } + + @Override + public boolean checkPriority(@NotNull BowEnchant enchant, @NotNull EventPriority priority) { + return enchant.getShootPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull EntityShootBowEvent event) { + return new EquipmentSlot[]{event.getHand()}; + } + + @Override + public boolean useEnchant(@NotNull EntityShootBowEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BowEnchant enchant, int level) { + if (enchant.onShoot(event, entity, item, level)) { + if (enchant instanceof Arrowed arrowed && event.getProjectile() instanceof Projectile projectile) { + arrowed.addData(projectile); + arrowed.addTrail(projectile); + } + return true; + } + return false; + } + }; + + public static final DataGather PROJECTILE_HIT = new DataGather<>() { + + @Override + @Nullable + public LivingEntity getEntity(@NotNull ProjectileHitEvent event) { + return event.getEntity().getShooter() instanceof LivingEntity entity ? entity : null; + } + + @Override + public boolean checkPriority(@NotNull BowEnchant enchant, @NotNull EventPriority priority) { + return enchant.getHitPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull ProjectileHitEvent event) { + return new EquipmentSlot[0]; + } + + @NotNull + @Override + public Map> getEnchants(@NotNull ProjectileHitEvent event, @NotNull Class enchantClass, @NotNull LivingEntity entity) { + Map> map = new HashMap<>(); + ItemStack bow = EnchantUtils.getSourceWeapon(event.getEntity()); + if (bow != null) { + map.put(bow, EnchantUtils.getExcellents(bow, enchantClass)); + } + return map; + } + + @Override + public boolean useEnchant(@NotNull ProjectileHitEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BowEnchant enchant, int level) { + return enchant.onHit(event, entity, event.getEntity(), item, level); + } + }; + + public static final DataGather ENTITY_DAMAGE_SHOOT = new DataGather<>() { + + @Override + @Nullable + public LivingEntity getEntity(@NotNull EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof Projectile projectile && projectile.getShooter() instanceof LivingEntity shooter) { + return shooter; + } + return null; + } + + @Override + public boolean checkPriority(@NotNull BowEnchant enchant, @NotNull EventPriority priority) { + return enchant.getDamagePriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull EntityDamageByEntityEvent event) { + return new EquipmentSlot[0]; + } + + @NotNull + @Override + public Map> getEnchants(@NotNull EntityDamageByEntityEvent event, @NotNull Class enchantClass, @NotNull LivingEntity entity) { + if (!(event.getDamager() instanceof Projectile projectile)) return Collections.emptyMap(); + + Map> map = new HashMap<>(); + ItemStack bow = EnchantUtils.getSourceWeapon(projectile); + if (bow != null) { + map.put(bow, EnchantUtils.getExcellents(bow, enchantClass)); + } + return map; + } + + @Override + public boolean useEnchant(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull ItemStack item, @NotNull BowEnchant enchant, int level) { + if (!(event.getDamager() instanceof Projectile projectile)) return false; + if (!(event.getEntity() instanceof LivingEntity victim)) return false; + + return enchant.onDamage(event, projectile, damager, victim, item, level); + } + }; + + public static final DataGather ENTITY_DAMAGE_ATTACK = new DataGather<>() { + + @Override + @Nullable + public LivingEntity getEntity(@NotNull EntityDamageByEntityEvent event) { + if (event.getDamager() instanceof LivingEntity entity) { + return entity; + } + return null; + } + + @Override + public boolean checkPriority(@NotNull CombatEnchant enchant, @NotNull EventPriority priority) { + return enchant.getAttackPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull EntityDamageByEntityEvent event) { + return new EquipmentSlot[]{EquipmentSlot.HAND}; + } + + @Override + public boolean useEnchant(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull ItemStack item, @NotNull CombatEnchant enchant, int level) { + if (event.getCause() == EntityDamageEvent.DamageCause.THORNS) return false; + if (!(event.getEntity() instanceof LivingEntity victim)) return false; + + return enchant.onAttack(event, damager, victim, item, level); + } + }; + + public static final DataGather ENTITY_DAMAGE_DEFENSE = new DataGather<>() { + + @Override + @Nullable + public LivingEntity getEntity(@NotNull EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + return entity instanceof Player player ? player : null; + } + + @Override + public boolean checkPriority(@NotNull CombatEnchant enchant, @NotNull EventPriority priority) { + return enchant.getProtectPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull EntityDamageByEntityEvent event) { + return EquipmentSlot.values(); + } + + @Override + public boolean useEnchant(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity victim, @NotNull ItemStack item, @NotNull CombatEnchant enchant, int level) { + if (event.getCause() == EntityDamageEvent.DamageCause.THORNS) return false; + if (!(event.getDamager() instanceof LivingEntity damager)) return false; + + return enchant.onProtect(event, damager, victim, item, level); + } + }; + + public static final DataGather ENTITY_KILL = new DataGather<>() { + + @Override + @Nullable + public LivingEntity getEntity(@NotNull EntityDeathEvent event) { + return event.getEntity().getKiller(); + } + + @Override + public boolean checkPriority(@NotNull DeathEnchant enchant, @NotNull EventPriority priority) { + return enchant.getKillPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull EntityDeathEvent event) { + return new EquipmentSlot[] {EquipmentSlot.HAND}; + } + + @Override + public boolean useEnchant(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull DeathEnchant enchant, int level) { + Player killer = entity.getKiller(); + if (killer == null) return false; + + return enchant.onKill(event, entity, killer, level); // TODO item? + } + }; + + public static final DataGather ENTITY_DEATH = new DataGather<>() { + + @Override + @NotNull + public LivingEntity getEntity(@NotNull EntityDeathEvent event) { + return event.getEntity(); + } + + @Override + public boolean checkPriority(@NotNull DeathEnchant enchant, @NotNull EventPriority priority) { + return enchant.getDeathPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull EntityDeathEvent event) { + return EquipmentSlot.values(); + } + + @Override + public boolean useEnchant(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull DeathEnchant enchant, int level) { + return enchant.onDeath(event, entity, item, level); + } + }; + + public static final DataGather FISHING = new DataGather<>() { + + @Override + @NotNull + public LivingEntity getEntity(@NotNull PlayerFishEvent event) { + return event.getPlayer(); + } + + @Override + public boolean checkPriority(@NotNull FishingEnchant enchant, @NotNull EventPriority priority) { + return enchant.getFishingPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull PlayerFishEvent event) { + return new EquipmentSlot[] {event.getHand()}; + } + + @Override + public boolean useEnchant(@NotNull PlayerFishEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull FishingEnchant enchant, int level) { + return enchant.onFishing(event, item, level); + } + }; + + public static final DataGather INTERACT = new DataGather<>() { + + @NotNull + @Override + public LivingEntity getEntity(@NotNull PlayerInteractEvent event) { + return event.getPlayer(); + } + + @Override + public boolean checkPriority(@NotNull InteractEnchant enchant, @NotNull EventPriority priority) { + return enchant.getInteractPriority() == priority; + } + + @NotNull + @Override + public EquipmentSlot[] getEnchantSlots(@NotNull PlayerInteractEvent event) { + return new EquipmentSlot[]{event.getHand()}; + } + + @Override + public boolean useEnchant(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull InteractEnchant enchant, int level) { + return enchant.onInteract(event, entity, item, level); + } + }; +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java new file mode 100644 index 0000000..ec0b241 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/registry/wrapper/WrappedEvent.java @@ -0,0 +1,56 @@ +package su.nightexpress.excellentenchants.enchantment.registry.wrapper; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Event; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.plugin.EventExecutor; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; +import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; + +public class WrappedEvent implements Listener, EventExecutor { + + //private final ExcellentEnchants plugin; + private final EventPriority priority; + private final Class eventClass; + private final Class enchantClass; + private final DataGather dataGather; + + public WrappedEvent(@NotNull ExcellentEnchants plugin, + @NotNull EventPriority priority, + @NotNull Class eventClass, + @NotNull Class enchantClass, + @NotNull DataGather dataGather) { + //this.plugin = plugin; + this.priority = priority; + this.eventClass = eventClass; + this.enchantClass = enchantClass; + this.dataGather = dataGather; + } + + @Override + public void execute(@NotNull Listener listener, @NotNull Event bukkitEvent) { + if (!this.eventClass.isAssignableFrom(bukkitEvent.getClass())) return; + + E event = this.eventClass.cast(bukkitEvent); + LivingEntity entity = this.dataGather.getEntity(event); + if (entity == null) return; + + this.dataGather.getEnchants(event, this.enchantClass, entity).forEach((item, enchants) -> { + enchants.forEach(((enchant, level) -> { + if (!this.dataGather.checkPriority(enchant, this.priority)) return; + if (!enchant.isAvailableToUse(entity)) return; + if (enchant.isOutOfCharges(item)) return; + if (this.dataGather.useEnchant(event, entity, item, enchant, level)) { + enchant.consumeChargesNoUpdate(item, level); + } + })); + if (Config.ENCHANTMENTS_CHARGES_ENABLED.get()) { + EnchantUtils.updateChargesDisplay(item); + } + }); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPriority.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPriority.java deleted file mode 100644 index 533ddc8..0000000 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantPriority.java +++ /dev/null @@ -1,6 +0,0 @@ -package su.nightexpress.excellentenchants.enchantment.util; - -public enum EnchantPriority { - - LOWEST, LOW, MEDIUM, HIGH, HIGHEST -} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java index c039999..ce33cf3 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java @@ -2,48 +2,41 @@ package su.nightexpress.excellentenchants.enchantment.util; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.lang.LangManager; -import su.nexmedia.engine.utils.CollectionsUtil; import su.nexmedia.engine.utils.EntityUtil; import su.nexmedia.engine.utils.ItemUtil; import su.nexmedia.engine.utils.PDCUtil; -import su.nexmedia.engine.utils.random.Rnd; import su.nightexpress.excellentenchants.ExcellentEnchantsAPI; import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned; import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant; import su.nightexpress.excellentenchants.config.Config; -import su.nightexpress.excellentenchants.config.ObtainSettings; -import su.nightexpress.excellentenchants.enchantment.EnchantPopulator; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.type.ObtainType; -import su.nightexpress.excellentenchants.tier.Tier; +import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; public class EnchantUtils { public static final NamespacedKey KEY_LORE_SIZE = new NamespacedKey(ExcellentEnchantsAPI.PLUGIN, "lore_size"); + private static final String META_PROJECTILE_WEAPON = "sourceWeapon"; private static boolean busyBreak = false; @@ -101,107 +94,6 @@ public class EnchantUtils { return item.getType() == Material.ENCHANTED_BOOK || Stream.of(EnchantmentTarget.values()).anyMatch(target -> target.includes(item)); } - // TODO Move in populator class - - public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType, @Nullable World world) { - AtomicBoolean status = new AtomicBoolean(false); - - var population = getPopulationCandidates(item, obtainType, world); - - if (obtainType == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK) { - if (Config.ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS.get() && !population.isEmpty()) { - getAll(item).keySet().forEach(enchantment -> remove(item, enchantment)); - } - } - - population.forEach((enchantment, level) -> { - if (add(item, enchantment, level, false)) { - status.set(true); - } - }); - - if (status.get()) { - updateDisplay(item); - } - - return status.get(); - } - - @NotNull - public static Set populateFilter(@NotNull Set enchants, - @NotNull ObtainType obtainType, @Nullable ItemStack item) { - Set set = enchants.stream() - .filter(enchant -> enchant.getObtainChance(obtainType) > 0) - .filter(enchant -> item == null || enchant.canEnchantItem(item)) - .collect(Collectors.toCollection(HashSet::new)); - set.removeIf(enchant -> obtainType == ObtainType.ENCHANTING && (enchant.isTreasure() || enchant.isCursed())); - return set; - } - - @NotNull - public static Map getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType, - @Nullable World world) { - return getPopulationCandidates(item, obtainType, new HashMap<>(), (enchant) -> enchant.generateLevel(obtainType), world); - } - - @NotNull - public static Map getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType, - @NotNull Map enchantsPrepared, - @NotNull Function levelFunc, - @Nullable World world) { - Map enchantsToAdd = new HashMap<>(enchantsPrepared); - - ObtainSettings settings = Config.getObtainSettings(obtainType).orElse(null); - if (settings == null || !Rnd.chance(settings.getEnchantsCustomGenerationChance())) return enchantsToAdd; - - int enchMax = settings.getEnchantsTotalMax(); - int enchRoll = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax()); - - EnchantPopulator populator = new EnchantPopulator(obtainType, item); - - // Try to populate as many as possible. - while (!populator.isEmpty() && enchRoll > 0) { - // Limit reached. - if (enchantsToAdd.size() >= enchMax) break; - - Tier tier = populator.getTierByChance(); - if (tier == null) break; // no tiers left. - - ExcellentEnchant enchant = populator.getEnchantByChance(tier); - // Remove entire tier if no enchants can be selected. - if (enchant == null) { - populator.purge(tier); - continue; - } - - // Remove disabled world enchants. - if (world != null && enchant.isDisabledInWorld(world)) { - populator.purge(tier, enchant); - continue; - } - - // Remove conflicting enchants. - if (enchantsToAdd.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) { - populator.purge(tier, enchant); - continue; - } - - // Level generation failed. - int level = levelFunc.apply(enchant); - if (level < enchant.getStartLevel()) { - populator.purge(tier, enchant); - continue; - } - - // All good! - populator.purge(tier, enchant); - enchantsToAdd.put(enchant, level); - enchRoll--; - } - - return enchantsToAdd; - } - public static boolean add(@NotNull ItemStack item, @NotNull Enchantment enchantment, int level, boolean force) { if (!force && !enchantment.canEnchantItem(item)) return false; @@ -417,12 +309,17 @@ public class EnchantUtils { map.put(clazz.cast(excellent), level); }); - return CollectionsUtil.sort(map, Comparator.comparing(p -> p.getKey().getPriority(), Comparator.reverseOrder())); + return map;//CollectionsUtil.sort(map, Comparator.comparing(p -> p.getKey().getPriority(), Comparator.reverseOrder())); } @NotNull public static Map getEnchantedEquipment(@NotNull LivingEntity entity) { - Map equipment = EntityUtil.getEquippedItems(entity); + return getEnchantedEquipment(entity, EquipmentSlot.values()); + } + + @NotNull + public static Map getEnchantedEquipment(@NotNull LivingEntity entity, @NotNull EquipmentSlot... slots) { + Map equipment = EntityUtil.getEquippedItems(entity, slots); equipment.entrySet().removeIf(entry -> { ItemStack item = entry.getValue(); EquipmentSlot slot = entry.getKey(); @@ -445,8 +342,15 @@ public class EnchantUtils { @NotNull public static Map> getEquipped(@NotNull LivingEntity entity, @NotNull Class clazz) { + return getEquipped(entity, clazz, EquipmentSlot.values()); + } + + @NotNull + public static Map> getEquipped(@NotNull LivingEntity entity, + @NotNull Class clazz, + @NotNull EquipmentSlot... slots) { Map> map = new HashMap<>(); - getEnchantedEquipment(entity).values().forEach(item -> { + getEnchantedEquipment(entity, slots).values().forEach(item -> { map.computeIfAbsent(item, k -> new LinkedHashMap<>()).putAll(getExcellents(item, clazz)); }); return map; @@ -455,6 +359,7 @@ public class EnchantUtils { public static void updateEquippedEffects(@NotNull LivingEntity entity) { getEquipped(entity, PassiveEnchant.class).forEach((item, enchants) -> { enchants.forEach((enchant, level) -> { + if (!enchant.isAvailableToUse(entity)) return; if (enchant instanceof Potioned potioned) { if (enchant.isOutOfCharges(item)) return; if (enchant.onTrigger(entity, item, level)) { @@ -465,4 +370,19 @@ public class EnchantUtils { EnchantUtils.updateChargesDisplay(item); }); } + + public static void setSourceWeapon(@NotNull Projectile projectile, @Nullable ItemStack item) { + if (item == null) return; + + projectile.setMetadata(META_PROJECTILE_WEAPON, new FixedMetadataValue(ExcellentEnchantsAPI.PLUGIN, item)); + } + + @Nullable + public static ItemStack getSourceWeapon(@NotNull Projectile projectile) { + return projectile.hasMetadata(META_PROJECTILE_WEAPON) ? (ItemStack) projectile.getMetadata(META_PROJECTILE_WEAPON).get(0).value() : null; + } + + public static void removeSourceWeapon(@NotNull Projectile projectile) { + projectile.removeMetadata(META_PROJECTILE_WEAPON, ExcellentEnchantsAPI.PLUGIN); + } } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java index c20da53..604c102 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/PlaceholderHook.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.utils.StringUtil; import su.nightexpress.excellentenchants.ExcellentEnchantsAPI; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; -import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; +import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry; public class PlaceholderHook { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolHook.java b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolHook.java index de94899..a4f5ba5 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolHook.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/hook/impl/ProtocolHook.java @@ -13,8 +13,8 @@ import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.ExcellentEnchantsAPI; -import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.config.Config; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.*; diff --git a/NMS/pom.xml b/NMS/pom.xml index 50c9ef7..730d361 100644 --- a/NMS/pom.xml +++ b/NMS/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 diff --git a/V1_17_R1/pom.xml b/V1_17_R1/pom.xml index e48bc89..73ed7ae 100644 --- a/V1_17_R1/pom.xml +++ b/V1_17_R1/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.5.8 + 3.5.9 diff --git a/V1_18_R2/pom.xml b/V1_18_R2/pom.xml index 2a21e2c..5b2a71f 100644 --- a/V1_18_R2/pom.xml +++ b/V1_18_R2/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.5.8 + 3.5.9 diff --git a/V1_19_R3/pom.xml b/V1_19_R3/pom.xml index 26bd766..4068d37 100644 --- a/V1_19_R3/pom.xml +++ b/V1_19_R3/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.5.8 + 3.5.9 diff --git a/V1_20_R1/pom.xml b/V1_20_R1/pom.xml index 5813cfc..28e0214 100644 --- a/V1_20_R1/pom.xml +++ b/V1_20_R1/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.5.8 + 3.5.9 diff --git a/V1_20_R2/pom.xml b/V1_20_R2/pom.xml index a3ffdf1..84b4c86 100644 --- a/V1_20_R2/pom.xml +++ b/V1_20_R2/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.5.8 + 3.5.9 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.5.8 + 3.5.9 diff --git a/pom.xml b/pom.xml index 965af82..284537e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ su.nightexpress.excellentenchants ExcellentEnchants pom - 3.5.8 + 3.5.9 Core NMS