Помогите [РЕШЕНО] Как заставить ArmorStand двигаться

  • Автор темы Автор темы AlbertV
  • Дата начала Дата начала
Статус
Закрыто для дальнейших ответов.

AlbertV

Активный участник
Пользователь
Баллы
66
Имя в Minecraft
Lingue
Всем привет! Хочу заставить Armor Stand двигаться вперед. В бакките такого не нашел.
 
Получилось! И последний вопрос, какие надо использовать эвенты, когда армор стенд рядом с живым объектом и блоками?
Смотри ссорцы ThrowSwords, там такое есть). Иветы юзай только тогда когда на арморстенд пытаются повесить броню или поджечь.
Код:
List<Entity> ne = (List<Entity>)ArmorStand.getLocation().getWorld().getNearbyEntities(frontlocation, 0.05, 0.05, 0.05);
for (Entity e : ne) {
if (e instanceof Player && e.equals((Object)p) || e instanceof ArmorStand || e instanceof Item || !(e instanceof LivingEntity)) continue;
p.damage((double)5, (LivingEntity)e);
}
 
Смотри ссорцы ThrowSwords, там такое есть). Иветы юзай только тогда когда на арморстенд пытаются повесить броню или поджечь.
Код:
List<Entity> ne = (List<Entity>)ArmorStand.getLocation().getWorld().getNearbyEntities(frontlocation, 0.05, 0.05, 0.05);
for (Entity e : ne) {
if (e instanceof Player && e.equals((Object)p) || e instanceof ArmorStand || e instanceof Item || !(e instanceof LivingEntity)) continue;
p.damage((double)5, (LivingEntity)e);
}
Не работает(
Код:
@EventHandler
public void onIntercat(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(player.getItemInHand() != null && player.getItemInHand().getType() == Material.DIAMOND_SWORD) {
            Location loc = player.getLocation();

            ArmorStand stand = loc.getWorld().spawn(loc, ArmorStand.class);
            stand.setVisible(false);
            stand.setGravity(true);
            stand.setArms(true);
            stand.setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
            int animate = Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getInstance(), new Animate(stand), 0, 1);
            player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 1, 1);

            BukkitRunnable runnable = new BukkitRunnable() {
                private int i = 0;
                @Override
                public void run() {
                    stand.setVelocity(player.getLocation().getDirection());
                    List<Entity> ne = (List<Entity>)stand.getLocation().getWorld().getNearbyEntities(loc, 0.05, 0.05, 0.05);
                    for (Entity all : ne) {
                        if (all instanceof Player && all.equals((Object)player) || all instanceof ArmorStand || all instanceof Item || !(all instanceof LivingEntity)) continue;
                        player.damage((double)5, (LivingEntity)all);
                    }
                    i++;
                    if(i >= 30) {
                        this.cancel();
                        stand.remove();
                    }
                }
            };
            runnable.runTaskTimer(Main.getInstance(), 0L, 0L);
            new EventUtil(Main.getInstance()) {
                @EventHandler
                public void onQuit(PlayerQuitEvent e) {
                    runnable.cancel();
                }
            };

            new BukkitRunnable() {

                @Override
                public void run() {
                    Bukkit.getScheduler().cancelTask(animate);
                    stand.remove();
                }
            }.runTaskLater(Main.getInstance(), 100);
        }
    }
}
 
Все проблему нашел и устранил!
Код:
public class TestListener implements Listener {
    @EventHandler
    public void onIntercat(PlayerInteractEvent e) {
        Player player = e.getPlayer();
        if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if(player.getItemInHand() != null && player.getItemInHand().getType() == Material.DIAMOND_SWORD) {
                Location loc = player.getLocation();

                ArmorStand stand = loc.getWorld().spawn(loc, ArmorStand.class);
                stand.setVisible(false);
                stand.setArms(true);
                stand.setGravity(true);
                stand.setItemInHand(new ItemStack(Material.DIAMOND_SWORD));
                int animate = Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getInstance(), new Animate(stand), 0, 1);
                player.playSound(player.getLocation(), Sound.BAT_TAKEOFF, 1, 1);

                BukkitRunnable runnable = new BukkitRunnable() {
                    private int i = 0;
                    @Override
                    public void run() {
                        stand.setVelocity(player.getLocation().getDirection());
                        List<Entity> ne = (List<Entity>)stand.getLocation().getWorld().getNearbyEntities(stand.getLocation(), 1, 1, 1);
                        for (Entity all : ne) {
                            if (all instanceof Player && all.equals((Object)player) || all instanceof ArmorStand || all instanceof Item || !(all instanceof LivingEntity)) continue;
                            ((LivingEntity) all).setHealth(0.0D);
                            stand.remove();
                            stand.playEffect(EntityEffect.DEATH);
                        }
                        stand.playEffect(EntityEffect.DEATH);
                        i++;
                        if(i >= 100) {
                            this.cancel();
                            stand.remove();
                        }
                    }
                };
                runnable.runTaskTimer(Main.getInstance(), 0L, 0L);
                new EventUtil(Main.getInstance()) {
                    @EventHandler
                    public void onQuit(PlayerQuitEvent e) {
                        runnable.cancel();
                    }
                };

                new BukkitRunnable() {

                    @Override
                    public void run() {
                        Bukkit.getScheduler().cancelTask(animate);
                        stand.remove();
                    }
                }.runTaskLater(Main.getInstance(), 100);
            }
        }
    }
}
Всем спасибо за помощь!
 
Статус
Закрыто для дальнейших ответов.
Назад
Верх