package net.divinitystudios.runecraft.tasks; import net.divinitystudios.runecraft.GeoUtils; import net.divinitystudios.runecraft.runes.Rune; import net.divinitystudios.runecraft.wrappers.*; //TODO: wards. public class FlightField extends TimedRuneTask { private int radius; private int count; private double offsetX; private double offsetY; private double offsetZ; private RuneParticles runeParticles; private RuneSound runeSound; private float volume; private float pitch; private double extra; private int red; private int green; private int blue; private int size; public FlightField(RuneEntity runeEntity, Location location, int radius, RuneParticles runeParticles, int count, double offsetX, double offsetY, double offsetZ, double extra, int red, int green, int blue, int size, RuneSound runeSound, float volume, float pitch, Rune rune){ this.runeEntity = runeEntity; this.location = location; this.radius = radius; this.rune = rune; this.runeParticles = runeParticles; this.count = count; this.offsetX = offsetX; this.offsetY = offsetY; this.offsetZ = offsetZ; this.runeSound = runeSound; this.volume = volume; this.pitch = pitch; this.extra = extra; this.red = red; this.green = green; this.blue = blue; this.size = size; scheduleDelayedTask(this, 0); } @Override public void run() { if (runeEntity.isPlayer()) { RunePlayer player = new RunePlayer(runeEntity.getUUID(), ""); if (!player.isFlightAllowed() && !player.isCreative() && !player.isSpectator() && flightRadiusCheck(player, this)) { player.sendTitle("", "You feel weightless.", 20, 2 * 20, 20); player.setFly(true); final RunePlayer flyer = player; final FlightField field = this; final int[] offset = {0}; TimedRuneTask canceller = new TimedRuneTask() { @Override public void run() { if (!flightRadiusCheck(flyer, field)) { scheduleDelayedTask(new TimedRuneTask() { @Override public void run() { if (!flightRadiusCheck(flyer, field)) { flyer.setFly(false); flyer.sendTitle("", "You feel heavy.", 20, 2 * 20, 20); // Gravity reminds you it's a law. flyer.stopSound(runeSound); } } }, 40); } else { if (++offset[0] == 5) { offset[0] = 0; // flyer.playParticle(runeParticles, count, offsetX, offsetY, offsetZ, extra, red, green, blue, size); flyer.playSound(runeSound, volume, pitch); } scheduleDelayedTask(this, 5); } } }; scheduleDelayedTask(canceller, 5); } } } private boolean flightRadiusCheck(RunePlayer flyer, FlightField instance){ if(!flyer.isOnline() || !rune.isIntact()) return false; return instance.getLocation().getDistance(flyer.getLocation()) != -1 && GeoUtils.sphereCheck(instance.getLocation(), flyer.getLocation().bump(-1, 0, -1), radius);//instance.getLocation().getDistance(flyer.getLocation()) <= instance.radius; } }