Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.12 KB | None | 0 0
  1. package br.com.styria.rankup.maquinas;
  2.  
  3. import org.bukkit.scheduler.*;
  4. import org.bukkit.entity.*;
  5. import org.bukkit.*;
  6. import org.bukkit.block.*;
  7. import org.bukkit.craftbukkit.v1_8_R3.*;
  8. import net.minecraft.server.v1_8_R3.*;
  9.  
  10. public class MaquinaAnimation extends BukkitRunnable
  11. {
  12.     private Maquina maquina;
  13.     private ArmorStand a;
  14.     private ArmorStand b;
  15.     private Location center;
  16.     private int tick;
  17.    
  18.     public MaquinaAnimation(final Maquina m) {
  19.         this.tick = 0;
  20.         this.maquina = m;
  21.         this.center = m.getBlock().getLocation().clone().add(0.5, 0.5, 0.5);
  22.     }
  23.    
  24.     public void run() {
  25.         final Block block = this.maquina.getBlock();
  26.         if (block != null && block.getChunk().isLoaded()) {
  27.             if (this.a == null || this.a.isDead()) {
  28.                 this.a = this.createOrbitable();
  29.             }
  30.             if (this.b == null || this.b.isDead()) {
  31.                 this.b = this.createOrbitable();
  32.             }
  33.             final double angle = this.tick * 1.8;
  34.             final double sin = Math.sin(Math.toRadians(angle));
  35.             final double cos = Math.cos(Math.toRadians(angle));
  36.             final double radius = 1.0;
  37.             final int i = Math.min(100, this.tick % 200) - Math.max(0, this.tick % 200 - 100);
  38.             final int multiplier = (this.tick % 400 <= 200) ? 1 : -1;
  39.             final double noise = i * 0.004 * multiplier;
  40.             final Location al = this.center.clone().add(sin * radius, -1.0 + noise, cos * radius);
  41.             al.setYaw((float)(angle * 2.0 % 360.0));
  42.             this.a.teleport(al);
  43.             this.sendParticle(al);
  44.             final Location bl = this.center.clone().add(-sin * radius, -1.0 - noise, -cos * radius);
  45.             bl.setYaw((float)(-angle * 2.0 % 360.0));
  46.             this.b.teleport(bl);
  47.             this.sendParticle(bl);
  48.         }
  49.         else {
  50.             this.maquina.stopAnimation();
  51.         }
  52.         ++this.tick;
  53.     }
  54.    
  55.     private void sendParticle(final Location al) {
  56.         ((CraftWorld)al.getWorld()).getHandle().addParticle(EnumParticle.FIREWORKS_SPARK, al.getX(), al.getY(), al.getZ(), 0.0, 0.0, 0.0, new int[] { 1 });
  57.     }
  58.    
  59.     public ArmorStand createOrbitable() {
  60.         final ArmorStand $ = (ArmorStand)this.center.getWorld().spawn(this.center, (Class)ArmorStand.class);
  61.         $.setHelmet(this.maquina.getDrop());
  62.         $.setMaxHealth(6.0);
  63.         $.setMarker(false);
  64.         $.setVisible(false);
  65.         $.setSmall(true);
  66.         $.setGravity(false);
  67.         return $;
  68.     }
  69.    
  70.     public synchronized void cancel() throws IllegalStateException {
  71.         super.cancel();
  72.         this.remove(this.a, this.b);
  73.         final ArmorStand armorStand = null;
  74.         this.b = armorStand;
  75.         this.a = armorStand;
  76.     }
  77.    
  78.     private void remove(final ArmorStand... arr) {
  79.         for (final ArmorStand $ : arr) {
  80.             if ($ != null) {
  81.                 if (!$.getLocation().getChunk().isLoaded()) {
  82.                     $.getLocation().getChunk().load();
  83.                 }
  84.                 $.remove();
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement