Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.muffincolor.objects;
- import org.bukkit.Bukkit;
- import org.bukkit.entity.ArmorStand;
- import org.bukkit.scheduler.BukkitRunnable;
- import ru.muffincolor.configs.Settings;
- import ru.muffincolor.main.Main;
- public class Box {
- private Main plugin = Main.plugin;
- private ArmorStand stand;
- private ChestBox chestBox;
- private int check;
- public Box(ArmorStand stand, ChestBox chestBox) {
- this.stand = stand;
- this.chestBox = chestBox;
- check++;
- int task1 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new FirstStepAnimation(stand, true), 0, 1);
- Bukkit.getScheduler().runTaskLater(plugin, () -> {
- Bukkit.getScheduler().cancelTask(task1);
- int task2 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new SecondStepAnimation(stand), 0, 1);
- Bukkit.getScheduler().runTaskLater(plugin, () -> {
- Bukkit.getScheduler().cancelTask(task2);
- int task3 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new ThirdStepAnimation(stand), 0, 1);
- Bukkit.getScheduler().runTaskLater(plugin, () -> endAnimationTaskForArmorStands(task3), Settings.rotationTime * 20L + 40L);
- }, 16);
- }, 25);
- }
- private void endAnimationTaskForArmorStands(int task) {
- new BukkitRunnable() {
- @Override
- public void run() {
- Bukkit.getScheduler().cancelTask(task);
- chestBox.passengers.get(stand).remove();
- stand.remove();
- }
- }.runTaskLater(plugin, 25);
- }
- private static class FirstStepAnimation extends BukkitRunnable {
- private ArmorStand stand;
- private double y;
- private boolean dirrection;
- private FirstStepAnimation(ArmorStand stand, boolean dir) {
- this.stand = stand;
- this.y = stand.getVelocity().getBlockY();
- this.dirrection = dir;
- Bukkit.broadcastMessage("1");
- }
- @Override
- public void run() {
- stand.setVelocity(stand.getVelocity().setZ(0));
- stand.setVelocity(stand.getVelocity().setY(dirrection ? y + 0.05 : y - 0.05));
- stand.setVelocity(stand.getVelocity().setX(0));
- }
- }
- private static class SecondStepAnimation extends BukkitRunnable {
- private ArmorStand stand;
- private SecondStepAnimation(ArmorStand stand) {
- this.stand = stand;
- double x = stand.getVelocity().getBlockX();
- double z = stand.getVelocity().getBlockZ();
- Bukkit.broadcastMessage("2");
- }
- @Override
- public void run() {
- stand.setVelocity(stand.getVelocity().setZ(0.068));
- stand.setVelocity(stand.getVelocity().setY(0));
- stand.setVelocity(stand.getVelocity().setX(0.022));
- }
- }
- private static class ThirdStepAnimation extends BukkitRunnable {
- private ArmorStand stand;
- private double angle = 360;
- private double x;
- private double z;
- private ThirdStepAnimation(ArmorStand stand) {
- this.stand = stand;
- this.x = stand.getVelocity().getBlockX();
- this.z = stand.getVelocity().getBlockZ();
- Bukkit.broadcastMessage("3");
- }
- @Override
- public void run() {
- double newX = x - 0.04 * Math.sin(angle);
- double newZ = z - 0.04 * Math.cos(angle);
- angle = angle - Math.PI / 45;
- stand.setVelocity(stand.getVelocity().setX(newX));
- stand.setVelocity(stand.getVelocity().setY(0));
- stand.setVelocity(stand.getVelocity().setZ(newZ));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement