Advertisement
Lisenochek

Untitled

Nov 4th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. package ru.muffincolor.objects;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.entity.ArmorStand;
  5. import org.bukkit.scheduler.BukkitRunnable;
  6. import ru.muffincolor.configs.Settings;
  7. import ru.muffincolor.main.Main;
  8.  
  9. public class Box {
  10.  
  11. private Main plugin = Main.plugin;
  12.  
  13. private ArmorStand stand;
  14. private ChestBox chestBox;
  15. private int check;
  16.  
  17. public Box(ArmorStand stand, ChestBox chestBox) {
  18. this.stand = stand;
  19. this.chestBox = chestBox;
  20. check++;
  21. int task1 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new FirstStepAnimation(stand, true), 0, 1);
  22.  
  23. Bukkit.getScheduler().runTaskLater(plugin, () -> {
  24. Bukkit.getScheduler().cancelTask(task1);
  25. int task2 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new SecondStepAnimation(stand), 0, 1);
  26. Bukkit.getScheduler().runTaskLater(plugin, () -> {
  27. Bukkit.getScheduler().cancelTask(task2);
  28. int task3 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new ThirdStepAnimation(stand), 0, 1);
  29. Bukkit.getScheduler().runTaskLater(plugin, () -> endAnimationTaskForArmorStands(task3), Settings.rotationTime * 20L + 40L);
  30. }, 16);
  31. }, 25);
  32. }
  33.  
  34. private void endAnimationTaskForArmorStands(int task) {
  35. new BukkitRunnable() {
  36. @Override
  37. public void run() {
  38. Bukkit.getScheduler().cancelTask(task);
  39. chestBox.passengers.get(stand).remove();
  40. stand.remove();
  41. }
  42. }.runTaskLater(plugin, 25);
  43. }
  44.  
  45. private static class FirstStepAnimation extends BukkitRunnable {
  46.  
  47. private ArmorStand stand;
  48. private double y;
  49. private boolean dirrection;
  50.  
  51. private FirstStepAnimation(ArmorStand stand, boolean dir) {
  52. this.stand = stand;
  53. this.y = stand.getVelocity().getBlockY();
  54. this.dirrection = dir;
  55. Bukkit.broadcastMessage("1");
  56. }
  57.  
  58. @Override
  59. public void run() {
  60. stand.setVelocity(stand.getVelocity().setZ(0));
  61. stand.setVelocity(stand.getVelocity().setY(dirrection ? y + 0.05 : y - 0.05));
  62. stand.setVelocity(stand.getVelocity().setX(0));
  63. }
  64. }
  65.  
  66. private static class SecondStepAnimation extends BukkitRunnable {
  67.  
  68. private ArmorStand stand;
  69.  
  70. private SecondStepAnimation(ArmorStand stand) {
  71. this.stand = stand;
  72. double x = stand.getVelocity().getBlockX();
  73. double z = stand.getVelocity().getBlockZ();
  74. Bukkit.broadcastMessage("2");
  75. }
  76.  
  77. @Override
  78. public void run() {
  79. stand.setVelocity(stand.getVelocity().setZ(0.068));
  80. stand.setVelocity(stand.getVelocity().setY(0));
  81. stand.setVelocity(stand.getVelocity().setX(0.022));
  82. }
  83. }
  84.  
  85. private static class ThirdStepAnimation extends BukkitRunnable {
  86.  
  87. private ArmorStand stand;
  88. private double angle = 360;
  89. private double x;
  90. private double z;
  91.  
  92. private ThirdStepAnimation(ArmorStand stand) {
  93. this.stand = stand;
  94. this.x = stand.getVelocity().getBlockX();
  95. this.z = stand.getVelocity().getBlockZ();
  96. Bukkit.broadcastMessage("3");
  97. }
  98.  
  99. @Override
  100. public void run() {
  101. double newX = x - 0.04 * Math.sin(angle);
  102. double newZ = z - 0.04 * Math.cos(angle);
  103. angle = angle - Math.PI / 45;
  104.  
  105. stand.setVelocity(stand.getVelocity().setX(newX));
  106. stand.setVelocity(stand.getVelocity().setY(0));
  107. stand.setVelocity(stand.getVelocity().setZ(newZ));
  108. }
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement