danik159

Untitled

Aug 18th, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package me.chickenstyle.luckyblocks.utilsfolder;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.Material;
  5. import org.bukkit.entity.ArmorStand;
  6. import org.bukkit.entity.EntityType;
  7. import org.bukkit.inventory.ItemStack;
  8. import org.bukkit.scheduler.BukkitRunnable;
  9. import org.bukkit.util.EulerAngle;
  10. import org.bukkit.util.Vector;
  11.  
  12.  
  13.  
  14.  
  15. public class TestAnimation extends BukkitRunnable {
  16.  
  17. ArmorStand stand;
  18. Location loc;
  19.  
  20. int ticks = 0;
  21. boolean runOnce = false;
  22.  
  23.  
  24. @SuppressWarnings("deprecation")
  25. public TestAnimation(Location loc) {
  26. loc.add(0.5,0,0);
  27. stand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
  28.  
  29.  
  30. stand.setArms(true);
  31. stand.setVisible(true);
  32. stand.setGravity(false);
  33. // 1.493 * Math.pi
  34. stand.setRightArmPose(new EulerAngle(-(Math.PI / 2), -0.69, 0));
  35. stand.setItemInHand(new ItemStack(Material.COAL));
  36. this.loc = loc;
  37.  
  38. }
  39.  
  40. @Override
  41. public void run() {
  42. if (ticks < 100) {
  43. ticks++;
  44. double t = ((double) ticks%40) * Math.PI / 20;
  45. stand.teleport(getLocationAroundCircle(loc, 1, t));
  46. } else {
  47. stand.remove();
  48. cancel();
  49. return;
  50. }
  51. }
  52.  
  53. private Location getLocationAroundCircle(Location center, double radius, double angleInRadian) {
  54. double x = center.getX() + radius * Math.cos(angleInRadian);
  55. double z = center.getZ() + radius * Math.sin(angleInRadian);
  56. double y = center.getY();
  57.  
  58. Location loc = new Location(center.getWorld(), x, y, z);
  59. Vector difference = center.toVector().clone().subtract(loc.toVector());
  60. loc.setDirection(difference);
  61.  
  62. return loc;
  63. }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment