Rename entity using packets

Discussion in 'Spigot Plugin Development' started by YuuTheDev, Aug 7, 2018.

  1. Hey, I want to know how can I rename a entity using packets?
     
  2. PacketPlayOutEntityMetadata
     
  3. I am pretty sure you do not need to use packets, you can probably just use entity.setCustomName(String str);
     
  4. I'm tring to do client-side holograms, so nope I won't use that :I
     
  5. Can you give an example about that packet?
     
  6. Still not solved help pls
     
    • Useful Useful x 1
  7. There are enough examples on how to rename entities by packets by googling.

    Use the meta packet & look into wikivg on how to use the metadata to rename the entity.
     
  8. Why do I ask you all this without a google research? Of course I did. And I couldn't find an example useful, I found this but doesn't work.
    Code (Java):
    WrappedDataWatcher watcher = new WrappedDataWatcher();
    watcher.setEntity(e);

    WrappedDataWatcher.Serializer booleanSerializer = WrappedDataWatcher.Registry.get(Boolean.class);
    WrappedDataWatcher.Serializer stringSerializer = WrappedDataWatcher.Registry.get(String.class);
                         
    watcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, stringSerializer), "Yeni isim");
     watcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, booleanSerializer), true);
                         
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
    packet.getIntegers().write(0, e.getEntityId());
    packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
                         
    ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet);
    Make helpful answers please.
     
  9. I haven't tested this, but I believe you can use something along the lines of the following:
    Code (Text):
    EntityArmorStand armorStand = new EntityArmorStand(worldServer);
    armorStand.setCustomName(new ChatComponentText("Your Custome Name"));
    PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(armorStand.getId(), armorStand.getDataWatcher(), false);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(metadataPacket);
     
    The armorstand.setCustomName() method basically sets the Entity's custom name in its DataWatcher object (found here at index 2). Then we create a new PacketPlayOutEntityMetadata with the appropriate parameters (the last parameter tells the packet constructor whether or not you want to resend all entity metadata or just metadata that is new) and then send it to the specified client.
     
  10. Have you made sure that the packet doesn't demand any other fields?

    And while I don't remember exactly, I think some versions are using different indexing (watcher objects.)

    My personal recommendation would be to build your system on a packet adapter rather then firing a packet. You'll need to keep track of removed, created, teleported etc holograms (including when a player leaves the range/server.)

    Setup a packet adapter for the metadata packet, resend it by simply setting the custom name to anything - intercept the packet and done.
     
  11. But I want to rename an entity that already spawned.
     
  12. if this is for pre 1.13 just use "setCustomName" with a string object for EntityArmorStand.
    if this is for 1.13, you need to invoke setCustomName with IChatBaseComponent as an argument. You can instantiate IChatBaseComponent object using IChatBaseComponent.ChatSerializer.b(String) method.
     
    • Like Like x 1
  13. Nope, it's for 1.12.2 :(
     
  14. The code I gave you in my previous post on this thread is what you need (1.12.2 or 1.13). Did you even try it?
     
  15. Like I said, you can just invoke setCustomName with string. That’s what I use for 1.12.2.
     

Share This Page