Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.styria.rankup.maquinas;
- import org.bukkit.scheduler.*;
- import org.bukkit.entity.*;
- import org.bukkit.*;
- import org.bukkit.block.*;
- import org.bukkit.craftbukkit.v1_8_R3.*;
- import net.minecraft.server.v1_8_R3.*;
- public class MaquinaAnimation extends BukkitRunnable
- {
- private Maquina maquina;
- private ArmorStand a;
- private ArmorStand b;
- private Location center;
- private int tick;
- public MaquinaAnimation(final Maquina m) {
- this.tick = 0;
- this.maquina = m;
- this.center = m.getBlock().getLocation().clone().add(0.5, 0.5, 0.5);
- }
- public void run() {
- final Block block = this.maquina.getBlock();
- if (block != null && block.getChunk().isLoaded()) {
- if (this.a == null || this.a.isDead()) {
- this.a = this.createOrbitable();
- }
- if (this.b == null || this.b.isDead()) {
- this.b = this.createOrbitable();
- }
- final double angle = this.tick * 1.8;
- final double sin = Math.sin(Math.toRadians(angle));
- final double cos = Math.cos(Math.toRadians(angle));
- final double radius = 1.0;
- final int i = Math.min(100, this.tick % 200) - Math.max(0, this.tick % 200 - 100);
- final int multiplier = (this.tick % 400 <= 200) ? 1 : -1;
- final double noise = i * 0.004 * multiplier;
- final Location al = this.center.clone().add(sin * radius, -1.0 + noise, cos * radius);
- al.setYaw((float)(angle * 2.0 % 360.0));
- this.a.teleport(al);
- this.sendParticle(al);
- final Location bl = this.center.clone().add(-sin * radius, -1.0 - noise, -cos * radius);
- bl.setYaw((float)(-angle * 2.0 % 360.0));
- this.b.teleport(bl);
- this.sendParticle(bl);
- }
- else {
- this.maquina.stopAnimation();
- }
- ++this.tick;
- }
- private void sendParticle(final Location al) {
- ((CraftWorld)al.getWorld()).getHandle().addParticle(EnumParticle.FIREWORKS_SPARK, al.getX(), al.getY(), al.getZ(), 0.0, 0.0, 0.0, new int[] { 1 });
- }
- public ArmorStand createOrbitable() {
- final ArmorStand $ = (ArmorStand)this.center.getWorld().spawn(this.center, (Class)ArmorStand.class);
- $.setHelmet(this.maquina.getDrop());
- $.setMaxHealth(6.0);
- $.setMarker(false);
- $.setVisible(false);
- $.setSmall(true);
- $.setGravity(false);
- return $;
- }
- public synchronized void cancel() throws IllegalStateException {
- super.cancel();
- this.remove(this.a, this.b);
- final ArmorStand armorStand = null;
- this.b = armorStand;
- this.a = armorStand;
- }
- private void remove(final ArmorStand... arr) {
- for (final ArmorStand $ : arr) {
- if ($ != null) {
- if (!$.getLocation().getChunk().isLoaded()) {
- $.getLocation().getChunk().load();
- }
- $.remove();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement