package me.sashegdev.blackknife; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.entity.BlockDisplay; import org.bukkit.entity.Display; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataType; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; public class DiamondAttack { public static boolean tryUse(Player p, TensionManager tension) { if (tension.getTP(p) < 25f) { p.sendActionBar(net.kyori.adventure.text.Component.text("Need 10% TP").color(net.kyori.adventure.text.format.NamedTextColor.RED)); return false; } tension.setTP(p, tension.getTP(p) - 25f); Location eye = p.getEyeLocation(); Vector dir = eye.getDirection().normalize(); Location spawn = eye.clone().add(dir.clone().multiply(1.5)); BlockDisplay crystal = p.getWorld().spawn(spawn, BlockDisplay.class, d -> { d.setBlock(Material.AMETHYST_BLOCK.createBlockData()); d.setBrightness(new Display.Brightness(15, 15)); d.setViewRange(64); }); p.getWorld().playSound(spawn, Sound.BLOCK_AMETHYST_BLOCK_PLACE, 1f, 0.9f); p.getWorld().playSound(spawn, Sound.BLOCK_AMETHYST_BLOCK_CHIME, 1f, 1.5f); Vector vel = dir.clone().multiply(1.5); BlackKnifePlugin plugin = BlackKnifePlugin.getPlugin(BlackKnifePlugin.class); new BukkitRunnable() { @Override public void run() { if (!crystal.isValid() || crystal.isDead()) { cancel(); return; } Location cur = crystal.getLocation(); Location nl = cur.clone().add(vel); Location next = nl.clone().add(vel); boolean hitBlock = next.getBlock().isSolid(); if (hitBlock) { Location expl = cur.clone().add(vel.clone().normalize().multiply(-0.1)); crystal.teleport(expl); crystal.remove(); cancel(); expl.getWorld().spawnParticle(Particle.EXPLOSION, expl, 1); expl.getWorld().playSound(expl, Sound.ENTITY_GENERIC_EXPLODE, 1f, 1.2f); Vector[] dirs = { new Vector(1,0,0), new Vector(-1,0,0), new Vector(0,0,1), new Vector(0,0,-1), new Vector(1,0,1).normalize(), new Vector(-1,0,1).normalize(), new Vector(1,0,-1).normalize(), new Vector(-1,0,-1).normalize() }; for (Vector d : dirs) { BlockDisplay shard = p.getWorld().spawn(expl, BlockDisplay.class, s -> { s.setBlock(Material.MEDIUM_AMETHYST_BUD.createBlockData()); s.setBrightness(new Display.Brightness(15, 15)); s.setViewRange(64); }); Vector sv = d.clone().multiply(0.4); new BukkitRunnable() { @Override public void run() { if (!shard.isValid()) { cancel(); return; } Location cur2 = shard.getLocation(); Location n2 = cur2.clone().add(sv); if (n2.getBlock().isSolid()) { Location expl2 = cur2.clone().add(sv.clone().normalize().multiply(-0.1)); shard.teleport(expl2); shard.remove(); cancel(); return; } shard.teleport(n2); n2.getWorld().spawnParticle(Particle.CRIT, n2, 1, 0.05, 0.05, 0.05, 0); for (var ent : n2.getWorld().getNearbyEntities(n2, 0.7, 0.7, 0.7, e -> e instanceof LivingEntity && e != p)) { LivingEntity le = (LivingEntity) ent; le.getPersistentDataContainer().set(SwoonHandler.MAGIC_DAMAGE, PersistentDataType.BYTE, (byte) 1); le.damage(2.0, p); shard.remove(); cancel(); break; } for (Player pl : n2.getWorld().getNearbyPlayers(n2, 0.9)) { if (pl == p) continue; double d2 = pl.getLocation().add(0, 1, 0).distanceSquared(n2); if (d2 > 0.25 && d2 < 0.81) { BlackKnifePlugin.getPlugin(BlackKnifePlugin.class).getTension().addTP(pl, 2.5f, "DODGE +1%"); pl.getWorld().spawnParticle(Particle.DUST, pl.getLocation().add(0, 0.25, 0), 25, 0.5, 0.05, 0.5, 0, new Particle.DustOptions(Color.fromRGB(255, 255, 255), 0.15f)); } } if (shard.getTicksLived() > 40) { shard.remove(); cancel(); } } }.runTaskTimer(plugin, 1L, 1L); } return; } crystal.teleport(nl); crystal.getWorld().spawnParticle(Particle.END_ROD, nl, 1, 0.05, 0.05, 0.05, 0); crystal.getWorld().spawnParticle(Particle.DUST, nl, 1, 0, 0, 0, 0, new Particle.DustOptions(Color.fromRGB(180, 0, 255), 1f)); boolean hit = false; for (var ent : nl.getWorld().getNearbyEntities(nl, 0.7, 0.7, 0.7, e -> e instanceof LivingEntity && e != p)) { LivingEntity le = (LivingEntity) ent; le.getPersistentDataContainer().set(SwoonHandler.MAGIC_DAMAGE, PersistentDataType.BYTE, (byte) 1); le.damage(5.0, p); hit = true; break; } for (Player pl : nl.getWorld().getNearbyPlayers(nl, 0.9)) { if (pl == p) continue; double d = pl.getLocation().add(0, 1, 0).distanceSquared(nl); if (d > 0.25 && d < 0.81) { BlackKnifePlugin.getPlugin(BlackKnifePlugin.class).getTension().addTP(pl, 2.5f, "DODGE +1%"); pl.getWorld().spawnParticle(Particle.DUST, pl.getLocation().add(0, 0.25, 0), 25, 0.5, 0.05, 0.5, 0, new Particle.DustOptions(Color.fromRGB(255, 255, 255), 0.15f)); } } if (hit) { Location expl = nl.clone(); crystal.remove(); cancel(); expl.getWorld().spawnParticle(Particle.EXPLOSION, expl, 1); expl.getWorld().playSound(expl, Sound.ENTITY_GENERIC_EXPLODE, 1f, 1.2f); Vector[] dirs = { new Vector(1,0,0), new Vector(-1,0,0), new Vector(0,0,1), new Vector(0,0,-1), new Vector(1,0,1).normalize(), new Vector(-1,0,1).normalize(), new Vector(1,0,-1).normalize(), new Vector(-1,0,-1).normalize() }; for (Vector d : dirs) { BlockDisplay shard = p.getWorld().spawn(expl, BlockDisplay.class, s -> { s.setBlock(Material.MEDIUM_AMETHYST_BUD.createBlockData()); s.setBrightness(new Display.Brightness(15, 15)); s.setViewRange(64); }); Vector sv = d.clone().multiply(0.4); new BukkitRunnable() { @Override public void run() { if (!shard.isValid()) { cancel(); return; } Location cur2 = shard.getLocation(); Location n2 = cur2.clone().add(sv); if (n2.getBlock().isSolid()) { Location expl2 = cur2.clone().add(sv.clone().normalize().multiply(-0.1)); shard.teleport(expl2); shard.remove(); cancel(); return; } shard.teleport(n2); shard.getWorld().spawnParticle(Particle.CRIT, n2, 1, 0.05, 0.05, 0.05, 0); for (var ent : n2.getWorld().getNearbyEntities(n2, 0.7, 0.7, 0.7, e -> e instanceof LivingEntity && e != p)) { LivingEntity le = (LivingEntity) ent; le.getPersistentDataContainer().set(SwoonHandler.MAGIC_DAMAGE, PersistentDataType.BYTE, (byte) 1); le.damage(2.0, p); shard.remove(); cancel(); break; } for (Player pl : n2.getWorld().getNearbyPlayers(n2, 0.9)) { if (pl == p) continue; double d2 = pl.getLocation().add(0, 1, 0).distanceSquared(n2); if (d2 > 0.25 && d2 < 0.81) { BlackKnifePlugin.getPlugin(BlackKnifePlugin.class).getTension().addTP(pl, 2.5f, "DODGE +1%"); pl.getWorld().spawnParticle(Particle.DUST, pl.getLocation().add(0, 0.25, 0), 25, 0.5, 0.05, 0.5, 0, new Particle.DustOptions(Color.fromRGB(255, 255, 255), 0.15f)); } } if (shard.getTicksLived() > 40) { shard.remove(); cancel(); } } }.runTaskTimer(plugin, 1L, 1L); } } else if (crystal.getTicksLived() > 60) { crystal.remove(); cancel(); } } }.runTaskTimer(plugin, 1L, 1L); return true; } }