diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java index 73e64a1a..58edaf96 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/TypeSet.java @@ -4,6 +4,7 @@ import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.comp.interaction.InteractionType; import io.lumine.mythic.lib.damage.AttackMetadata; import io.lumine.mythic.lib.damage.DamageType; +import io.lumine.mythic.lib.player.PlayerMetadata; import io.lumine.mythic.lib.version.VersionSound; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; @@ -17,6 +18,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; import java.util.Random; @@ -26,12 +28,13 @@ public enum TypeSet { * Slashing weapons deal damage in a cone behind the player's initial * target, which makes it a deadly AoE weapon for warriors */ - SLASHING((attack, damager, target, weapon) -> { - if (!MMOItems.plugin.getConfig().getBoolean("item-ability.slashing.enabled") || damager.isOnCooldown(CooldownType.SET_TYPE_ATTACK)) + SLASHING((attack, attacker, attackerData, target, weapon) -> { + if (!MMOItems.plugin.getConfig().getBoolean("item-ability.slashing.enabled") + || attackerData.isOnCooldown(CooldownType.SET_TYPE_ATTACK)) return; - damager.applyCooldown(CooldownType.SET_TYPE_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.slashing.cooldown")); - Location loc = attack.getPlayer().getLocation().clone().add(0, 1.3, 0); + attackerData.applyCooldown(CooldownType.SET_TYPE_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.slashing.cooldown")); + Location loc = attacker.getPlayer().getLocation().clone().add(0, 1.3, 0); final double a1 = (loc.getYaw() + 90) / 180 * Math.PI, p = -loc.getPitch() / 180 * Math.PI; for (double r = 1; r < 5; r += .3) @@ -40,10 +43,10 @@ public enum TypeSet { for (Entity entity : MMOUtils.getNearbyChunkEntities(loc)) if (entity.getLocation().distanceSquared(loc) < 40 - && attack.getPlayer().getEyeLocation().getDirection() - .angle(entity.getLocation().subtract(attack.getPlayer().getLocation()).toVector()) < Math.PI / 3 - && UtilityMethods.canTarget(attack.getPlayer(), entity, InteractionType.OFFENSE_ACTION) && !entity.equals(target)) - attack.attack((LivingEntity) entity, attack.getDamage().getDamage() * .4, DamageType.WEAPON, DamageType.PHYSICAL); + && attacker.getPlayer().getEyeLocation().getDirection() + .angle(entity.getLocation().subtract(attacker.getPlayer().getLocation()).toVector()) < Math.PI / 3 + && UtilityMethods.canTarget(attacker.getPlayer(), entity, InteractionType.OFFENSE_ACTION) && !entity.equals(target)) + attacker.attack((LivingEntity) entity, attack.getDamage().getDamage() * .4, DamageType.WEAPON, DamageType.PHYSICAL); }), /** @@ -52,12 +55,13 @@ public enum TypeSet { * increased which makes it a perfect 'double or nothing' weapon for * assassins */ - PIERCING((attack, damager, target, weapon) -> { - if (!MMOItems.plugin.getConfig().getBoolean("item-ability.piercing.enabled") || damager.isOnCooldown(CooldownType.SET_TYPE_ATTACK)) + PIERCING((attack, attacker, attackerData, target, weapon) -> { + if (!MMOItems.plugin.getConfig().getBoolean("item-ability.piercing.enabled") + || attackerData.isOnCooldown(CooldownType.SET_TYPE_ATTACK)) return; - damager.applyCooldown(CooldownType.SET_TYPE_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.piercing.cooldown")); - Location loc = attack.getPlayer().getLocation().clone().add(0, 1.3, 0); + attackerData.applyCooldown(CooldownType.SET_TYPE_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.piercing.cooldown")); + Location loc = attacker.getPlayer().getLocation().clone().add(0, 1.3, 0); final double a1 = (loc.getYaw() + 90) / 180 * Math.PI, p = -loc.getPitch() / 180 * Math.PI; for (double r = 1; r < 5; r += .3) @@ -65,42 +69,41 @@ public enum TypeSet { loc.getWorld().spawnParticle(Particle.CRIT, loc.clone().add(Math.cos(a + a1) * r, Math.sin(p) * r, Math.sin(a + a1) * r), 0); for (Entity entity : MMOUtils.getNearbyChunkEntities(loc)) - if (!entity.equals(target) && entity.getLocation().distanceSquared(attack.getPlayer().getLocation()) < 40 - && attack.getPlayer().getEyeLocation().getDirection() - .angle(entity.getLocation().toVector().subtract(attack.getPlayer().getLocation().toVector())) < Math.PI / 12 - && UtilityMethods.canTarget(attack.getPlayer(), entity, InteractionType.OFFENSE_ACTION)) - attack.attack((LivingEntity) entity, attack.getDamage().getDamage() * .6, DamageType.WEAPON, DamageType.PHYSICAL); + if (!entity.equals(target) && entity.getLocation().distanceSquared(attacker.getPlayer().getLocation()) < 40 + && attacker.getPlayer().getEyeLocation().getDirection() + .angle(entity.getLocation().toVector().subtract(attacker.getPlayer().getLocation().toVector())) < Math.PI / 12 + && UtilityMethods.canTarget(attacker.getPlayer(), entity, InteractionType.OFFENSE_ACTION)) + attacker.attack((LivingEntity) entity, attack.getDamage().getDamage() * .6, DamageType.WEAPON, DamageType.PHYSICAL); }), /** * Blunt weapons are like 1.9 sweep attacks. They damage * all enemies nearby and apply a slight knockback */ - BLUNT((attack, damager, target, weapon) -> { + BLUNT((attack, attacker, attackerData, target, weapon) -> { final Random random = new Random(); float pitchRange = 0.7f + random.nextFloat() * (0.9f - 0.7f); + final double bluntPower; if (MMOItems.plugin.getConfig().getBoolean("item-ability.blunt.aoe.enabled") - && !damager.isOnCooldown(CooldownType.SPECIAL_ATTACK)) { + && !attackerData.isOnCooldown(CooldownType.SPECIAL_ATTACK) + && (bluntPower = attacker.getStat("BLUNT_POWER")) > 0) { - damager.applyCooldown(CooldownType.SPECIAL_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.blunt.aoe.cooldown")); + attackerData.applyCooldown(CooldownType.SPECIAL_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.blunt.aoe.cooldown")); target.getWorld().playSound(target.getLocation(), Sound.BLOCK_ANVIL_LAND, 0.6f, pitchRange); target.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, target.getLocation().add(0, 1, 0), 0); - double bluntPower = attack.getStat("BLUNT_POWER"); - if (bluntPower > 0) { - double bluntRating = weapon.requireNonZero(attack.getStat("BLUNT_RATING"), - MMOItems.plugin.getConfig().getDouble("default.blunt-rating")) / 100; - for (Entity entity : target.getNearbyEntities(bluntPower, bluntPower, bluntPower)) - if (UtilityMethods.canTarget(attack.getPlayer(), entity, InteractionType.OFFENSE_ACTION) && !entity.equals(target)) - attack.attack((LivingEntity) entity, attack.getDamage().getDamage() * bluntRating, DamageType.WEAPON, DamageType.PHYSICAL); - } + final double bluntRating = weapon.requireNonZero(attacker.getStat("BLUNT_RATING"), + MMOItems.plugin.getConfig().getDouble("default.blunt-rating")) / 100; + for (Entity entity : target.getNearbyEntities(bluntPower, bluntPower, bluntPower)) + if (UtilityMethods.canTarget(attacker.getPlayer(), entity, InteractionType.OFFENSE_ACTION) && !entity.equals(target)) + attacker.attack((LivingEntity) entity, attack.getDamage().getDamage() * bluntRating, DamageType.WEAPON, DamageType.PHYSICAL); } if (MMOItems.plugin.getConfig().getBoolean("item-ability.blunt.stun.enabled") - && !damager.isOnCooldown(CooldownType.SPECIAL_ATTACK) + && !attackerData.isOnCooldown(CooldownType.SPECIAL_ATTACK) && random.nextDouble() < MMOItems.plugin.getConfig().getDouble("item-ability.blunt.stun.chance") / 100) { - damager.applyCooldown(CooldownType.SPECIAL_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.blunt.stun.cooldown")); + attackerData.applyCooldown(CooldownType.SPECIAL_ATTACK, MMOItems.plugin.getConfig().getDouble("item-ability.blunt.stun.cooldown")); target.getWorld().playSound(target.getLocation(), VersionSound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR.toSound(), 1, 2); target.removePotionEffect(PotionEffectType.SLOW); target.removePotionEffect(PotionEffectType.BLINDNESS); @@ -148,8 +151,8 @@ public enum TypeSet { return attackHandler != null; } - public void applyAttackEffect(AttackMetadata attackMeta, PlayerData damager, LivingEntity target, Weapon weapon) { - attackHandler.apply(attackMeta, damager, target, weapon); + public void applyAttackEffect(AttackMetadata attackMeta, PlayerMetadata attacker, PlayerData attackerData, LivingEntity target, Weapon weapon) { + attackHandler.apply(attackMeta, attacker, attackerData, target, weapon); } public String getName() { @@ -158,6 +161,6 @@ public enum TypeSet { @FunctionalInterface interface SetAttackHandler { - void apply(AttackMetadata attack, PlayerData damager, LivingEntity target, Weapon weapon); + void apply(@NotNull AttackMetadata attack, @NotNull PlayerMetadata attacker, @NotNull PlayerData attackerData, @NotNull LivingEntity target, @NotNull Weapon weapon); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java index f75600b0..b7505f72 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/interaction/weapon/Weapon.java @@ -4,6 +4,7 @@ import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.flags.CustomFlag; import io.lumine.mythic.lib.damage.AttackMetadata; +import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.api.interaction.UseItem; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData.CooldownType; @@ -12,6 +13,7 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; @@ -41,12 +43,9 @@ public class Weapon extends UseItem { * @return If the attack was cast successfully */ public boolean checkAndApplyWeaponCosts() { - if (checkWeaponCosts(null)) { - applyWeaponCosts(0, null); - return true; - } - - return false; + if (!checkWeaponCosts(null)) return false; + applyWeaponCosts(0, null); + return true; } /** @@ -84,15 +83,12 @@ public class Weapon extends UseItem { public void applyWeaponCosts(double attackDelay, @Nullable CooldownType cooldown) { double manaCost = getNBTItem().getStat("MANA_COST"); - if (manaCost > 0) - playerData.getRPG().giveMana(-manaCost); + if (manaCost > 0) playerData.getRPG().giveMana(-manaCost); double staminaCost = getNBTItem().getStat("STAMINA_COST"); - if (staminaCost > 0) - playerData.getRPG().giveStamina(-staminaCost); + if (staminaCost > 0) playerData.getRPG().giveStamina(-staminaCost); - if (cooldown != null) - getPlayerData().applyCooldown(cooldown, attackDelay); + if (cooldown != null) getPlayerData().applyCooldown(cooldown, attackDelay); } /** @@ -100,10 +96,11 @@ public class Weapon extends UseItem { * targeted attacks since the vanilla attack bar already does that. * * @param attackMeta The attack being performed + * @param attacker The player attacker * @param target The attack target * @return If the attack is successful, or if it was canceled otherwise */ - public boolean handleTargetedAttack(AttackMetadata attackMeta, LivingEntity target) { + public boolean handleTargetedAttack(AttackMetadata attackMeta, @NotNull PlayerMetadata attacker, LivingEntity target) { // Handle weapon mana and stamina costs ONLY if (!checkAndApplyWeaponCosts()) @@ -111,7 +108,7 @@ public class Weapon extends UseItem { // Handle item set attack effects if (getMMOItem().getType().getItemSet().hasAttackEffect() && !getNBTItem().getBoolean("MMOITEMS_DISABLE_ATTACK_PASSIVE")) - getMMOItem().getType().getItemSet().applyAttackEffect(attackMeta, playerData, target, this); + getMMOItem().getType().getItemSet().applyAttackEffect(attackMeta, attacker, playerData, target, this); return true; } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java index 8d8682da..1c9bd17a 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java @@ -129,7 +129,7 @@ public class ItemUse implements Listener { return; } - if (!weapon.handleTargetedAttack(event.getAttack(), event.getEntity())) { + if (!weapon.handleTargetedAttack(event.getAttack(), event.getAttacker(), event.getEntity())) { event.setCancelled(true); return; }