MySoulIsCry

Untitled

Jul 12th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. import org.bukkit.entity.ArmorStand;
  2. import org.bukkit.entity.Entity;
  3. import org.bukkit.entity.Player;
  4. import org.bukkit.plugin.Plugin;
  5. import org.bukkit.scheduler.BukkitRunnable;
  6. import org.bukkit.util.Vector;
  7. import org.bukkit.Location;
  8.  
  9. import java.util.List;
  10. import java.util.stream.Collectors;
  11.  
  12. public class StandWheel {
  13.  
  14. private Player player;
  15. private ArmorStand armorStand;
  16. private Plugin plugin;
  17. private BukkitRunnable runnable;
  18. private int currentYaw = 0;
  19. /*
  20. * Скорость вращения
  21. * Чем меньше число тем быстрее
  22. */
  23. private int wheelSpeed = 1;
  24. /*
  25. * Расстояние на котором будет крутиться
  26. * ArmorStand вокруг игрока
  27. * в блоках
  28. */
  29. private double wheelDistance = 2f;
  30. /*
  31. * Расстояние от стенда на котором сущности
  32. * будут отлетать от него
  33. */
  34. private double punchDistance = 1;
  35. /*
  36. * Сила с которой стенд будет пинаться
  37. */
  38. private double punchPower = 2;
  39.  
  40. public StandWheel(Player player, ArmorStand armorStand, Plugin plugin) {
  41. this.player = player;
  42. this.armorStand = armorStand;
  43. armorStand.setGravity(false);
  44. this.plugin = plugin;
  45. }
  46.  
  47. public void start() {
  48. if (runnable == null) {
  49. runnable = new BukkitRunnable() {
  50. @Override
  51. public void run() {
  52. Location playerLocation = player.getLocation().clone();
  53. playerLocation.setPitch(0);
  54. playerLocation.setYaw(currentYaw += 20);
  55. Vector appendLocation = playerLocation
  56. .getDirection()
  57. .clone()
  58. .normalize()
  59. .multiply(wheelDistance);
  60. playerLocation.add(appendLocation);
  61. armorStand.teleport(playerLocation);
  62.  
  63. List<Entity> entities = playerLocation.getWorld().getEntities()
  64. .stream()
  65. .filter(entity -> entity.getLocation().distance(playerLocation) <= punchDistance && entity != player && entity != armorStand)
  66. .collect(Collectors.toList());
  67. for (Entity entity : entities) {
  68. Vector punchVector = entity
  69. .getLocation()
  70. .clone()
  71. .subtract(playerLocation.clone())
  72. .toVector()
  73. .normalize()
  74. .multiply(punchPower);
  75. entity.setVelocity(punchVector);
  76. }
  77.  
  78. }
  79. };
  80. }
  81. runnable.runTaskTimer(plugin, 0, wheelSpeed);
  82. }
  83.  
  84. public void stop() {
  85. if (runnable != null && !runnable.isCancelled()) runnable.cancel();
  86. }
  87.  
  88. public Player getPlayer() {
  89. return player;
  90. }
  91.  
  92. public void setPlayer(Player player) {
  93. this.player = player;
  94. }
  95.  
  96. public ArmorStand getArmorStand() {
  97. return armorStand;
  98. }
  99.  
  100. public void setArmorStand(ArmorStand armorStand) {
  101. this.armorStand = armorStand;
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment