Solved Attaching leads to armor stands.

Discussion in 'Spigot Plugin Development' started by xlis1, May 4, 2017.

Thread Status:
Not open for further replies.
  1. im attempting to attach a lead to an armor stand to create balloons, but you cant attach leads to armorstands, so i summon a bat have the armorstand ride it and attach the lead to the bat, but the bat wont move. help?



    Code (Text):
    else if ((player).getInventory().getItemInMainHand().getType() == Material.LEASH
                    && event.getAction() == Action.RIGHT_CLICK_AIR) {
                Bat bat = (Bat) player.getWorld().spawnEntity(player.getLocation(), EntityType.BAT);
                bat.setAI(false);
                bat.setAwake(true);
                ArmorStand as = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);
                //Pig as = (Pig) player.getWorld().spawnEntity(player.getLocation(), EntityType.PIG);
                bat.setPassenger(as);
                bat.setLeashHolder(player);
                new BukkitRunnable() {
                    public void run() {
                        if ((bat.isLeashed())) {
                            Vector vec = bat.getVelocity();
                            if (as.getLocation().getBlockY() < player.getLocation().getY() + 5) {
                            bat.setVelocity(new Vector(vec.getX(), 0.10, vec.getZ()));
                            }
                            bat.setFallDistance(0);
                        }
                        else if (bat.isDead() || as.isDead()) {
                            bat.remove();
                            as.remove();
                            this.cancel();
                        }
                        else {
                            as.remove();
                            this.cancel();
                        }
                    }
                }.runTaskTimer(this.getInstance(), 0, 1);
            }
     
Thread Status:
Not open for further replies.