Solved Manipulate Armorstands created by Packets

Discussion in 'Spigot Plugin Development' started by IronMan59, Mar 8, 2020.

  1. How can I get the bukkit entity or a nms way to manipulate an armorstand that I've sent through the
    PacketPlayOutSpawnEntityLiving. I need to be able to rotate it for the type of plugin I'm making. Any responses would be appreciated, I can send code but I'm not sure how much good that will do.
     
  2. FrostedSnowman

    Resource Staff

    You should have an entity id which you'll need to use to manipulate the armorstand through other packets that require an entity id. For example, if your armorstand gets assigned an entity id of 3, you'll need to specify '3' for other packets which require an entity id.

    If you show your code & how you spawn the entity, we can help you more.
     
  3. Here is my code. I'm not sure what else to do.
    Code (Text):
    lse if (e.getItemDrop().getItemStack().getType().name().contains("PICK")) {
                        if (wormholeRegion.contains(loc)) {
                            if (vulcanPrisons.energyMethods.isFull(item)) {
                                Player p = e.getPlayer();

                               WorldServer s = ((CraftWorld) loc.getWorld()).getHandle(); //not really besides despawning it which found nothing
                                EntityArmorStand middleStand = new EntityArmorStand(s);
                                middleStand.setLocation(-28.5, 31, -29.5, 0, 0);
                                middleStand.setCustomName(item.getItemMeta().getDisplayName());
                                middleStand.setCustomNameVisible(true);
                                middleStand.setGravity(false);
                                middleStand.setArms(true);
                                middleStand.setRightArmPose(new Vector3f(-90, 0, 0));
                                middleStand.setInvisible(false);
                                PacketPlayOutSpawnEntityLiving spawnP = new PacketPlayOutSpawnEntityLiving(middleStand);
                                PacketPlayOutEntityEquipment EquipP = new PacketPlayOutEntityEquipment(middleStand.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP);
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP);

                                DataWatcher dataWatcher = middleStand.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata = new PacketPlayOutEntityMetadata(middleStand.getId(), dataWatcher, false);

                                //- First Enchant
                                EntityArmorStand eS1 = new EntityArmorStand(s);
                                eS1.setLocation(-30.5, 33, -23.5, 0, 0);
                                //   eS1.setCustomName(item.getItemMeta().getDisplayName());
                                eS1.setCustomNameVisible(true);
                                eS1.setGravity(false);
                                eS1.setArms(true);
                                eS1.setInvisible(false);

                                PacketPlayOutSpawnEntityLiving spawnP1 = new PacketPlayOutSpawnEntityLiving(eS1);
                                //PacketPlayOutEntityEquipment EquipP1 = new PacketPlayOutEntityEquipment(eS1.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP1);
                                //((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP1);

                                DataWatcher dataWatcher1 = eS1.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata1 = new PacketPlayOutEntityMetadata(eS1.getId(), dataWatcher1, false);

                                EntityArmorStand eS2 = new EntityArmorStand(s);
                                eS2.setLocation(-25.5, 33, -24.5, 0, 0);
                                //eS2.setCustomName(item.getItemMeta().getDisplayName());
                                eS2.setCustomNameVisible(true);
                                eS2.setGravity(false);
                                eS2.setArms(true);
                                eS2.setInvisible(false);
                                PacketPlayOutSpawnEntityLiving spawnP2 = new PacketPlayOutSpawnEntityLiving(eS2);
                                //PacketPlayOutEntityEquipment EquipP2 = new PacketPlayOutEntityEquipment(eS2.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP2);
                               // ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP2);

                                DataWatcher dataWatcher2 = eS2.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata2 = new PacketPlayOutEntityMetadata(eS2.getId(), dataWatcher2, false);

                                EntityArmorStand eS3 = new EntityArmorStand(s);
                                eS3.setLocation(-23.5, 33, -29.5, 0, 0);
                                //eS3.setCustomName(item.getItemMeta().getDisplayName());
                                eS3.setCustomNameVisible(true);
                                eS3.setGravity(false);
                                eS3.setArms(true);
                                eS3.setInvisible(false);
                                PacketPlayOutSpawnEntityLiving spawnP3 = new PacketPlayOutSpawnEntityLiving(eS3);
                               // PacketPlayOutEntityEquipment EquipP3 = new PacketPlayOutEntityEquipment(eS3.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP3);
                                //((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP3);

                                DataWatcher dataWatcher3 = eS3.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata3 = new PacketPlayOutEntityMetadata(eS3.getId(), dataWatcher3, false);

                                EntityArmorStand eS4 = new EntityArmorStand(s);
                                eS4.setLocation(-25.5, 33, -34.5, 0, 0);
                                //eS4.setCustomName(item.getItemMeta().getDisplayName());
                                eS4.setCustomNameVisible(true);
                                eS4.setGravity(false);
                                eS4.setArms(true);
                                eS4.setInvisible(false);
                                PacketPlayOutSpawnEntityLiving spawnP4 = new PacketPlayOutSpawnEntityLiving(eS4);
                                //PacketPlayOutEntityEquipment EquipP4 = new PacketPlayOutEntityEquipment(eS4.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP4);
                                //((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP4);

                                DataWatcher dataWatcher4 = eS4.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata4 = new PacketPlayOutEntityMetadata(eS4.getId(), dataWatcher4, false);

                                EntityArmorStand eS5 = new EntityArmorStand(s);
                                eS5.setLocation(-30.5, 33, -34.5, 0, 0);
                                //eS5.setCustomName(item.getItemMeta().getDisplayName());
                                eS5.setCustomNameVisible(true);
                                eS5.setGravity(false);
                                eS5.setArms(true);
                                eS5.setInvisible(false);
                                PacketPlayOutSpawnEntityLiving spawnP5 = new PacketPlayOutSpawnEntityLiving(eS5);
                                //PacketPlayOutEntityEquipment EquipP5 = new PacketPlayOutEntityEquipment(eS5.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP5);
                                //((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP5);

                                DataWatcher dataWatcher5 = eS5.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata5 = new PacketPlayOutEntityMetadata(eS5.getId(), dataWatcher5, false);

                                EntityArmorStand eS6 = new EntityArmorStand(s);
                                eS6.setLocation(-33.5, 33, -29.5, 0, 0);
                                //eS6.setCustomName(item.getItemMeta().getDisplayName());
                                eS6.setCustomNameVisible(true);
                                eS6.setGravity(false);
                                eS6.setArms(true);
                                eS6.setInvisible(false);
                                PacketPlayOutSpawnEntityLiving spawnP6 = new PacketPlayOutSpawnEntityLiving(eS6);
                               // PacketPlayOutEntityEquipment EquipP6 = new PacketPlayOutEntityEquipment(eS6.getId(), 0, CraftItemStack.asNMSCopy(item));
                                ((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(spawnP6);
                                //((CraftPlayer) e.getPlayer()).getHandle().playerConnection.sendPacket(EquipP6);

                                DataWatcher dataWatcher6 = eS6.getDataWatcher();
                                PacketPlayOutEntityMetadata metadata6 = new PacketPlayOutEntityMetadata(eS6.getId(), dataWatcher6, false);

                                new BukkitRunnable() {
                                    double rad = 0;
                                    int i = 0;

                                    @Override
                                    public void run() {
                                        if (i <= 300) {
                                            i++;
                                            if (rad < Math.toRadians(360)) {
                                                //dataWatcher.watch(10, new Vector3f(-100, (float) Math.toDegrees(rad),0));
                                                rad += 0.3; //increase to have head rotate faster.
                                            } else {
                                                //dataWatcher.watch(10, new Vector3f(-100, (float) Math.toDegrees(rad),0));
                                                rad = 0;
                                            }
                                            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(metadata);
                                        }
                                    }
                                }.runTaskTimer(vulcanPrisons, 0L, 1L);
                                //p.openInventory(Enchanter.menu(item));
                                //p.getInventory().remove(item);

                            } else e.setCancelled(true);
     
  4. Bump. Still needing solution.
     
  5. PacketPlayOutEntityLook
     
  6. I believe I was using the wrong approach to this. I can just use normal armorstands and destroy them with packets for all the people who I don’t want to see them. Solved?