small api change; fixed an issue with melee attacks

This commit is contained in:
Indyuce 2021-10-29 19:13:34 +02:00
parent fcb39c9681
commit 6aabc21835
10 changed files with 140 additions and 139 deletions

View File

@ -52,7 +52,7 @@ public class Staff extends UntargetedWeapon {
StaffSpirit spirit = StaffSpirit.get(getNBTItem());
if (spirit != null) {
spirit.getAttack().handle(attackMeta, getNBTItem(), attackDamage, range);
spirit.getAttack().handle(attackMeta, getNBTItem(), range);
return;
}

View File

@ -12,16 +12,17 @@ import org.bukkit.Particle;
public class LightningSpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), VersionSound.ENTITY_FIREWORK_ROCKET_BLAST.toSound(), 2, 2);
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), VersionSound.ENTITY_FIREWORK_ROCKET_BLAST.toSound(), 2, 2);
Location loc = attackMeta.getDamager().getEyeLocation();
MMORayTraceResult trace = MythicLib.plugin.getVersion().getWrapper().rayTrace(attackMeta.getDamager(), range,
entity -> MMOUtils.canTarget(attackMeta.getDamager(), entity, InteractionType.OFFENSE_ACTION));
if (trace.hasHit())
attackMeta.applyEffectsAndDamage(nbt, trace.getHit());
trace.draw(loc, attackMeta.getDamager().getEyeLocation().getDirection(), 2,
loc1 -> loc1.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, loc1, 0));
}
Location loc = attackMeta.getDamager().getEyeLocation();
MMORayTraceResult trace = MythicLib.plugin.getVersion().getWrapper().rayTrace(attackMeta.getDamager(), range,
entity -> MMOUtils.canTarget(attackMeta.getDamager(), entity, InteractionType.OFFENSE_ACTION));
if (trace.hasHit())
attackMeta.applyEffectsAndDamage(nbt, trace.getHit());
trace.draw(loc, attackMeta.getDamager().getEyeLocation().getDirection(), 2,
loc1 -> loc1.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, loc1, 0));
}
}

View File

@ -18,42 +18,42 @@ import java.util.List;
public class ManaSpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
new BukkitRunnable() {
final Vector vec = attackMeta.getDamager().getEyeLocation().getDirection().multiply(.4);
final Location loc = attackMeta.getDamager().getEyeLocation();
int ti = 0;
final double r = .2;
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
new BukkitRunnable() {
final Vector vec = attackMeta.getDamager().getEyeLocation().getDirection().multiply(.4);
final Location loc = attackMeta.getDamager().getEyeLocation();
int ti = 0;
final double r = .2;
public void run() {
if (ti++ > range)
cancel();
public void run() {
if (ti++ > range)
cancel();
if (ti % 2 == 0)
loc.getWorld().playSound(loc, Sound.BLOCK_SNOW_BREAK, 2, 2);
List<Entity> targets = MMOUtils.getNearbyChunkEntities(loc);
for (int j = 0; j < 3; j++) {
loc.add(vec);
if (loc.getBlock().getType().isSolid()) {
cancel();
break;
}
if (ti % 2 == 0)
loc.getWorld().playSound(loc, Sound.BLOCK_SNOW_BREAK, 2, 2);
List<Entity> targets = MMOUtils.getNearbyChunkEntities(loc);
for (int j = 0; j < 3; j++) {
loc.add(vec);
if (loc.getBlock().getType().isSolid()) {
cancel();
break;
}
for (double item = 0; item < Math.PI * 2; item += Math.PI / 3.5) {
Vector vec = MMOUtils.rotateFunc(new Vector(r * Math.cos(item), r * Math.sin(item), 0), loc);
if (random.nextDouble() <= .6)
loc.getWorld().spawnParticle(Particle.REDSTONE, loc.clone().add(vec), 1, new Particle.DustOptions(Color.AQUA, 1));
}
for (Entity target : targets)
if (MMOUtils.canTarget(attackMeta.getDamager(), loc, target, InteractionType.OFFENSE_ACTION)) {
attackMeta.applyEffectsAndDamage(nbt, (LivingEntity) target);
loc.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, loc, 0);
cancel();
return;
}
}
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
}
for (double item = 0; item < Math.PI * 2; item += Math.PI / 3.5) {
Vector vec = MMOUtils.rotateFunc(new Vector(r * Math.cos(item), r * Math.sin(item), 0), loc);
if (random.nextDouble() <= .6)
loc.getWorld().spawnParticle(Particle.REDSTONE, loc.clone().add(vec), 1, new Particle.DustOptions(Color.AQUA, 1));
}
for (Entity target : targets)
if (MMOUtils.canTarget(attackMeta.getDamager(), loc, target, InteractionType.OFFENSE_ACTION)) {
attackMeta.applyEffectsAndDamage(nbt, (LivingEntity) target);
loc.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, loc, 0);
cancel();
return;
}
}
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
}
}

View File

@ -18,7 +18,7 @@ import java.util.List;
public class NetherSpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
new BukkitRunnable() {
final Vector vec = attackMeta.getDamager().getEyeLocation().getDirection().multiply(.3);
final Location loc = attackMeta.getDamager().getEyeLocation();

View File

@ -9,7 +9,7 @@ import java.util.Random;
public interface StaffAttackHandler {
static final Random random = new Random();
void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range);
void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range);
default Location getGround(Location loc) {
for (int j = 0; j < 20; j++) {

View File

@ -16,35 +16,35 @@ import org.bukkit.util.Vector;
public class SunfireSpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
new BukkitRunnable() {
final Location target = getGround(attackMeta.getDamager().getTargetBlock(null, (int) range * 2).getLocation()).add(0, 1.2, 0);
final double a = random.nextDouble() * Math.PI * 2;
final Location loc = target.clone().add(Math.cos(a) * 4, 10, Math.sin(a) * 4);
final Vector vec = target.toVector().subtract(loc.toVector()).multiply(.015);
double ti = 0;
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
new BukkitRunnable() {
final Location target = getGround(attackMeta.getDamager().getTargetBlock(null, (int) range * 2).getLocation()).add(0, 1.2, 0);
final double a = random.nextDouble() * Math.PI * 2;
final Location loc = target.clone().add(Math.cos(a) * 4, 10, Math.sin(a) * 4);
final Vector vec = target.toVector().subtract(loc.toVector()).multiply(.015);
double ti = 0;
public void run() {
loc.getWorld().playSound(loc, Sound.BLOCK_FIRE_AMBIENT, 2, 2);
for (int j = 0; j < 4; j++) {
ti += .015;
loc.add(vec);
loc.getWorld().spawnParticle(Particle.FLAME, loc, 0, .03, 0, .03, 0);
if (ti >= 1) {
loc.getWorld().spawnParticle(Particle.FLAME, loc, 24, 0, 0, 0, .12);
loc.getWorld().spawnParticle(Particle.SMOKE_NORMAL, loc, 24, 0, 0, 0, .12);
loc.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, loc, 0);
loc.getWorld().playSound(loc, VersionSound.ENTITY_FIREWORK_ROCKET_BLAST.toSound(), 2, 2);
for (Entity target : MMOUtils.getNearbyChunkEntities(loc))
if (MMOUtils.canTarget(attackMeta.getDamager(), target, InteractionType.OFFENSE_ACTION) && target.getLocation().distanceSquared(loc) <= 9)
attackMeta.applyEffectsAndDamage(nbt, (LivingEntity) target);
cancel();
break;
}
}
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
}
public void run() {
loc.getWorld().playSound(loc, Sound.BLOCK_FIRE_AMBIENT, 2, 2);
for (int j = 0; j < 4; j++) {
ti += .015;
loc.add(vec);
loc.getWorld().spawnParticle(Particle.FLAME, loc, 0, .03, 0, .03, 0);
if (ti >= 1) {
loc.getWorld().spawnParticle(Particle.FLAME, loc, 24, 0, 0, 0, .12);
loc.getWorld().spawnParticle(Particle.SMOKE_NORMAL, loc, 24, 0, 0, 0, .12);
loc.getWorld().spawnParticle(Particle.EXPLOSION_LARGE, loc, 0);
loc.getWorld().playSound(loc, VersionSound.ENTITY_FIREWORK_ROCKET_BLAST.toSound(), 2, 2);
for (Entity target : MMOUtils.getNearbyChunkEntities(loc))
if (MMOUtils.canTarget(attackMeta.getDamager(), target, InteractionType.OFFENSE_ACTION) && target.getLocation().distanceSquared(loc) <= 9)
attackMeta.applyEffectsAndDamage(nbt, (LivingEntity) target);
cancel();
break;
}
}
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
}
}

View File

@ -16,32 +16,32 @@ import org.bukkit.util.Vector;
public class ThunderSpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
new BukkitRunnable() {
final Location target = getGround(attackMeta.getDamager().getTargetBlock(null, (int) range * 2).getLocation()).add(0, 1.2, 0);
final double a = random.nextDouble() * Math.PI * 2;
final Location loc = target.clone().add(Math.cos(a) * 4, 10, Math.sin(a) * 4);
final Vector vec = target.toVector().subtract(loc.toVector()).multiply(.015);
double ti = 0;
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
new BukkitRunnable() {
final Location target = getGround(attackMeta.getDamager().getTargetBlock(null, (int) range * 2).getLocation()).add(0, 1.2, 0);
final double a = random.nextDouble() * Math.PI * 2;
final Location loc = target.clone().add(Math.cos(a) * 4, 10, Math.sin(a) * 4);
final Vector vec = target.toVector().subtract(loc.toVector()).multiply(.015);
double ti = 0;
public void run() {
loc.getWorld().playSound(loc, VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 2, 2);
for (int j = 0; j < 4; j++) {
ti += .015;
loc.add(vec);
loc.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, loc, 0, .03, 0, .03, 0);
if (ti >= 1) {
loc.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, loc, 24, 0, 0, 0, .12);
loc.getWorld().playSound(loc, VersionSound.ENTITY_FIREWORK_ROCKET_BLAST.toSound(), 2, 2);
for (Entity target : MMOUtils.getNearbyChunkEntities(loc))
if (MMOUtils.canTarget(attackMeta.getDamager(), target, InteractionType.OFFENSE_ACTION) && target.getLocation().distanceSquared(loc) <= 9)
attackMeta.applyEffectsAndDamage(nbt, (LivingEntity) target);
cancel();
}
}
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
}
public void run() {
loc.getWorld().playSound(loc, VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 2, 2);
for (int j = 0; j < 4; j++) {
ti += .015;
loc.add(vec);
loc.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, loc, 0, .03, 0, .03, 0);
if (ti >= 1) {
loc.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, loc, 24, 0, 0, 0, .12);
loc.getWorld().playSound(loc, VersionSound.ENTITY_FIREWORK_ROCKET_BLAST.toSound(), 2, 2);
for (Entity target : MMOUtils.getNearbyChunkEntities(loc))
if (MMOUtils.canTarget(attackMeta.getDamager(), target, InteractionType.OFFENSE_ACTION) && target.getLocation().distanceSquared(loc) <= 9)
attackMeta.applyEffectsAndDamage(nbt, (LivingEntity) target);
cancel();
}
}
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
}
}

View File

@ -12,24 +12,24 @@ import org.bukkit.util.Vector;
public class VoidSpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
Vector vec = attackMeta.getDamager().getEyeLocation().getDirection();
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
ShulkerBullet shulkerBullet = (ShulkerBullet) attackMeta.getDamager().getWorld().spawnEntity(attackMeta.getDamager().getLocation().add(0, 1, 0), EntityType.valueOf("SHULKER_BULLET"));
shulkerBullet.setShooter(attackMeta.getDamager());
new BukkitRunnable() {
double ti = 0;
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
Vector vec = attackMeta.getDamager().getEyeLocation().getDirection();
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_WITHER_SHOOT, 2, 2);
ShulkerBullet shulkerBullet = (ShulkerBullet) attackMeta.getDamager().getWorld().spawnEntity(attackMeta.getDamager().getLocation().add(0, 1, 0), EntityType.valueOf("SHULKER_BULLET"));
shulkerBullet.setShooter(attackMeta.getDamager());
new BukkitRunnable() {
double ti = 0;
public void run() {
ti += .1;
if (shulkerBullet.isDead() || ti >= range / 4) {
shulkerBullet.remove();
cancel();
}
shulkerBullet.setVelocity(vec);
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
MMOItems.plugin.getEntities().registerCustomEntity(shulkerBullet, new Shulker_Missile.ShulkerMissileEntityData(attackMeta, nbt));
}
public void run() {
ti += .1;
if (shulkerBullet.isDead() || ti >= range / 4) {
shulkerBullet.remove();
cancel();
}
shulkerBullet.setVelocity(vec);
}
}.runTaskTimer(MMOItems.plugin, 0, 1);
MMOItems.plugin.getEntities().registerCustomEntity(shulkerBullet, new Shulker_Missile.ShulkerMissileEntityData(attackMeta, nbt));
}
}

View File

@ -13,17 +13,17 @@ import org.bukkit.util.Vector;
public class XRaySpirit implements StaffAttackHandler {
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double attackDamage, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 2, 2);
@Override
public void handle(ItemAttackMetadata attackMeta, NBTItem nbt, double range) {
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 2, 2);
double a = Math.toRadians(attackMeta.getDamager().getEyeLocation().getYaw() + 160);
Location loc = attackMeta.getDamager().getEyeLocation().add(new Vector(Math.cos(a), 0, Math.sin(a)).multiply(.5));
double a = Math.toRadians(attackMeta.getDamager().getEyeLocation().getYaw() + 160);
Location loc = attackMeta.getDamager().getEyeLocation().add(new Vector(Math.cos(a), 0, Math.sin(a)).multiply(.5));
MMORayTraceResult trace = MythicLib.plugin.getVersion().getWrapper().rayTrace(attackMeta.getDamager(), range, entity -> MMOUtils.canTarget(attackMeta.getDamager(), entity, InteractionType.OFFENSE_ACTION));
if (trace.hasHit())
attackMeta.applyEffectsAndDamage(nbt, trace.getHit());
trace.draw(loc, attackMeta.getDamager().getEyeLocation().getDirection(), 2, Color.BLACK);
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 0.40f, 2);
}
MMORayTraceResult trace = MythicLib.plugin.getVersion().getWrapper().rayTrace(attackMeta.getDamager(), range, entity -> MMOUtils.canTarget(attackMeta.getDamager(), entity, InteractionType.OFFENSE_ACTION));
if (trace.hasHit())
attackMeta.applyEffectsAndDamage(nbt, trace.getHit());
trace.draw(loc, attackMeta.getDamager().getEyeLocation().getDirection(), 2, Color.BLACK);
attackMeta.getDamager().getWorld().playSound(attackMeta.getDamager().getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 0.40f, 2);
}
}

View File

@ -8,6 +8,7 @@ import io.lumine.mythic.lib.api.stat.StatMap;
import io.lumine.mythic.lib.comp.target.InteractionType;
import io.lumine.mythic.lib.damage.DamageMetadata;
import io.lumine.mythic.lib.damage.DamageType;
import io.lumine.mythic.lib.damage.MeleeAttackMetadata;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ItemAttackMetadata;
@ -33,7 +34,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -107,8 +107,8 @@ public class ItemUse implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void meleeAttacks(PlayerAttackEvent event) {
// Checks if the target is a damageable entity and if it's a melee attack
if (event.getBukkitCause() != DamageCause.ENTITY_ATTACK || !(event.getEntity() instanceof LivingEntity))
// Checks if it's a melee attack
if (!(event.getAttack() instanceof MeleeAttackMetadata))
return;
/*