How to cancel PacketPlayOutEntityDestroy?

Discussion in 'Spigot Plugin Help' started by Siga, Jul 11, 2021.

  1. I have written a code that makes if a player is 15 blocks from an armor stand, it hides for him. Unfortunately, I don't know how to make it visible again.
    My code:
    Code (Text):
    @Override
                public void run() {
                for(Player all : Bukkit.getServer().getOnlinePlayers()) {
                    Location loc = all.getLocation();
                    List<Entity> nearbyEntites = (List<Entity>) loc.getWorld().getNearbyEntities(loc, 15, 15, 15);
                    for(Entity en : loc.getWorld().getEntities()) {
                    if(en.getType() == EntityType.ARMOR_STAND) {
                        if(nearbyEntites.contains(en))
                        {
                        //Show ArmorStand
                        }
                        else
                        {
                        PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(en.getEntityId());
                        ((CraftPlayer) all).getHandle().playerConnection.sendPacket(packet);
                        }
                            }
                        }
                    }
                }
     
  2. There is a thread asking about PacketPlayOutEntitySpawn which sounds like it would spawn an entity. Here is the thread if you want to look at it.
     
  3. Thanks, but I don't know what exactly to enter in PacketPlayOutSpawnEntity.
    Here is my current code:
    Code (Text):
    @Override
                public void run() {
                for(Player all : Bukkit.getServer().getOnlinePlayers()) {
                    Location loc = all.getLocation();
                    List<Entity> nearbyEntites = (List<Entity>) loc.getWorld().getNearbyEntities(loc, 15, 15, 15);
                    for(Entity en : loc.getWorld().getEntities()) {
                    if(en.getType() == EntityType.ARMOR_STAND) {
                        if(!nearbyEntites.contains(en))
                        {
                            PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(en.getEntityId());
                            ((CraftPlayer) all).getHandle().playerConnection.sendPacket(packet);
                        }
                        else
                        {
                            PacketPlayOutSpawnEntity packet1 = new PacketPlayOutSpawnEntity(null, en.getEntityId()); //Doesn't works
                            ((CraftPlayer) all).getHandle().playerConnection.sendPacket(packet1);
                        }
                            }
                        }
                    }
                }
     
    #3 Siga, Jul 12, 2021
    Last edited: Jul 12, 2021