Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- import org.bukkit.Location;
- import java.util.List;
- import java.util.stream.Collectors;
- public class StandWheel {
- private Player player;
- private ArmorStand armorStand;
- private Plugin plugin;
- private BukkitRunnable runnable;
- private int currentYaw = 0;
- /*
- * Скорость вращения
- * Чем меньше число тем быстрее
- */
- private int wheelSpeed = 1;
- /*
- * Расстояние на котором будет крутиться
- * ArmorStand вокруг игрока
- * в блоках
- */
- private double wheelDistance = 2f;
- /*
- * Расстояние от стенда на котором сущности
- * будут отлетать от него
- */
- private double punchDistance = 1;
- /*
- * Сила с которой стенд будет пинаться
- */
- private double punchPower = 2;
- public StandWheel(Player player, ArmorStand armorStand, Plugin plugin) {
- this.player = player;
- this.armorStand = armorStand;
- armorStand.setGravity(false);
- this.plugin = plugin;
- }
- public void start() {
- if (runnable == null) {
- runnable = new BukkitRunnable() {
- @Override
- public void run() {
- Location playerLocation = player.getLocation().clone();
- playerLocation.setPitch(0);
- playerLocation.setYaw(currentYaw += 20);
- Vector appendLocation = playerLocation
- .getDirection()
- .clone()
- .normalize()
- .multiply(wheelDistance);
- playerLocation.add(appendLocation);
- armorStand.teleport(playerLocation);
- List<Entity> entities = playerLocation.getWorld().getEntities()
- .stream()
- .filter(entity -> entity.getLocation().distance(playerLocation) <= punchDistance && entity != player && entity != armorStand)
- .collect(Collectors.toList());
- for (Entity entity : entities) {
- Vector punchVector = entity
- .getLocation()
- .clone()
- .subtract(playerLocation.clone())
- .toVector()
- .normalize()
- .multiply(punchPower);
- entity.setVelocity(punchVector);
- }
- }
- };
- }
- runnable.runTaskTimer(plugin, 0, wheelSpeed);
- }
- public void stop() {
- if (runnable != null && !runnable.isCancelled()) runnable.cancel();
- }
- public Player getPlayer() {
- return player;
- }
- public void setPlayer(Player player) {
- this.player = player;
- }
- public ArmorStand getArmorStand() {
- return armorStand;
- }
- public void setArmorStand(ArmorStand armorStand) {
- this.armorStand = armorStand;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment