Files
src
build.gradle
settings.gradle
Code
4 149
src/main/java/com/kodari/orbitalwarden/OrbitalWardenPlugin.java
package com.kodari.orbitalwarden;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
public final class OrbitalWardenPlugin extends JavaPlugin implements CommandExecutor {
private static final int CHARGE_TICKS = 40;
private static final double BLAST_RADIUS = 5.0;
private static final double BLAST_DAMAGE = 18.0;
@Override
public void onEnable() {
getCommand("orbitalwarden").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length != 1) {
sender.sendMessage("&cUsage: /orbitalwarden <player>");
return true;
}
Player target = Bukkit.getPlayerExact(args[0]);
if (target == null) {
sender.sendMessage("&cThat player is not online.");
return true;
}
Location strikeLocation = target.getLocation().getBlock().getLocation().add(0.5, 0, 0.5);
sender.sendMessage("&5Orbital Warden cannon locked onto &d" + target.getName() + "&5!");
target.sendMessage("&cAn orbital Warden cannon has locked onto your position!");
XSound.matchXSound("ENTITY_WARDEN_HEARTBEAT").ifPresent(sound -> sound.play(target));
new OrbitalStrike(strikeLocation).runTaskTimer(this, 0L, 1L);
return true;
}
private final class OrbitalStrike extends BukkitRunnable {
private final Location center;
private int elapsedTicks;
private OrbitalStrike(Location center) {
this.center = center;
}
@Override
public void run() {
World world = center.getWorld();
if (world == null) {
cancel();
return;
}
double progress = Math.min(1.0, (double) elapsedTicks / CHARGE_TICKS);
double beamY = center.getY() + 2 + (world.getMaxHeight() - center.getY() - 2) * (1.0 - progress);
Location beamPoint = new Location(world, center.getX(), beamY, center.getZ());
XParticle.of("END_ROD").ifPresent(particle -> world.spawnParticle(particle.get(), beamPoint, 8));
if (elapsedTicks % 4 == 0) {
XParticle.of("SOUL_FIRE_FLAME").ifPresent(particle -> {
for (int i = 0; i < 12; i++) {
double angle = Math.PI * 2 * i / 12;
Location point = center.clone().add(Math.cos(angle) * 2.5, 0.2, Math.sin(angle) * 2.5);
world.spawnParticle(particle.get(), point, 2);
}
});
}
if (elapsedTicks++ >= CHARGE_TICKS) {
detonate(world);
cancel();
}
}
private void detonate(World world) {
XParticle.of("SONIC_BOOM").ifPresent(particle -> world.spawnParticle(particle.get(), center, 1));
XParticle.of("SOUL_FIRE_FLAME").ifPresent(particle -> world.spawnParticle(particle.get(), center, 50, 1.5, 0.8, 1.5));
for (Player player : world.getPlayers()) {
if (player.getLocation().distanceSquared(center) <= 24 * 24) {
XSound.matchXSound("ENTITY_WARDEN_SONIC_BOOM").ifPresent(sound -> sound.play(player));
}
}
for (Entity entity : world.getNearbyEntities(center, BLAST_RADIUS, 3.0, BLAST_RADIUS)) {
if (!(entity instanceof LivingEntity living)) {
continue;
}
living.damage(BLAST_DAMAGE);
Vector knockback = living.getLocation().toVector().subtract(center.toVector());
knockback.setY(0);
if (knockback.lengthSquared() < 0.01) {
knockback = new Vector(0, 0, 0);
} else {
knockback.normalize();
}
living.setVelocity(knockback.multiply(1.4).setY(0.85));
}
}
}
}