Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by YuuTheDev, Aug 7, 2018.
Hey, I want to know how can I rename a entity using packets?
I am pretty sure you do not need to use packets, you can probably just use entity.setCustomName(String str);
I'm tring to do client-side holograms, so nope I won't use that :I
Can you give an example about that packet?
Still not solved help pls
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.
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.
WrappedDataWatcher watcher = new WrappedDataWatcher();
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);
Make helpful answers please.
I haven't tested this, but I believe you can use something along the lines of the following:
EntityArmorStand armorStand = new EntityArmorStand(worldServer);
armorStand.setCustomName(new ChatComponentText("Your Custome Name"));
PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(armorStand.getId(), armorStand.getDataWatcher(), false);
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.
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.
But I want to rename an entity that already spawned.
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.
Nope, it's for 1.12.2
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?
Like I said, you can just invoke setCustomName with string. That’s what I use for 1.12.2.