1. Этот сайт использует файлы cookie. Продолжая пользоваться данным сайтом, Вы соглашаетесь на использование нами Ваших файлов cookie. Узнать больше.
  2. Вы находитесь в сообществе Rubukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на различные языки плагины наших коллег из других стран.
    Скрыть объявление
Скрыть объявление
В преддверии глобального обновления, мы проводим исследования, которые помогут нам сделать опыт пользования форумом ещё удобнее. Помогите нам, примите участие!

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

Тема в разделе "Разработка плагинов для новичков", создана пользователем AlbertV, 30 авг 2018.

Статус темы:
Закрыта.
  1. Grazy

    Grazy Активный участник Пользователь

    Баллы:
    76
    Имя в Minecraft:
    Prost
    Смотри ссорцы 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);
    }
    
     
  2. Автор темы
    AlbertV

    AlbertV Активный участник Пользователь

    Баллы:
    66
    Имя в Minecraft:
    Lingue
    Не работает(
    Код:
    @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);
            }
        }
    }
    
     
  3. Автор темы
    AlbertV

    AlbertV Активный участник Пользователь

    Баллы:
    66
    Имя в Minecraft:
    Lingue
    Все проблему нашел и устранил!
    Код:
    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);
                }
            }
        }
    }
    
    Всем спасибо за помощь!
     
  4. Автор темы
    AlbertV

    AlbertV Активный участник Пользователь

    Баллы:
    66
    Имя в Minecraft:
    Lingue
    Тема закрыта.
     
Статус темы:
Закрыта.

Поделиться этой страницей