Solved Entity Equipment packet

Discussion in 'Plugin Development' started by welsar55, Dec 14, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    welsar55

    I really need help to know how to make it look like someone is wearing diamond armor to some but not everyone so I went to this packet... I know i have to do something like this
    Code:java
    1. PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment();

    but besides that nothing. I need a bit of help so I was wondering if there was a guide for packets but it does not look like it so can someone please help me understand packets
     
  2. Offline

    TeeePeee

    Packets are completely NMS, meaning there is no easy way to use them with Bukkit, only a semi-complicated way with Craftbukkit.

    Essentially, you will have to go through the code for the specific packet you want on the Craftbukkit GitHub to determine the required parameters. If you don't provide it with proper parameters, the client will crash when you send it the packet. You may need to use Reflection to apply some parameters.

    Once you've applied all the parameters, you'll need to send it to the players you want. To do this, you must obtain the EntityPlayer version of the Bukkit Player by casting and using CraftPlayer#getHandle. With the EntityPlayer, you can use EntityPlayer#sendPacket(packet) to send the packet you have constructed.
     
  3. welsar55 What TeeePeee said isn't completly true (about the packet sending) . Let's first take a look at the PacketPlayOutEntityEquipment. When taking a look at the class file we see 3 fields:
    a - The id of the entity the changes are applied to.
    b - The changed slot; item in hand, helmet, body etc...
    c - the itemstack.

    Since the packet requires those 3 parameters in the constructor and it looks like you're not going to use reflection for this it will be even easier to do this. Just do this:
    Code:java
    1. PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(player.getEntityID(), <slot between 0 and 4>, CraftItemStack.asNMSCopy(bukkit itemstack here));

    To send the packet just do:
    Code:java
    1. ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);

    This should do the job.

    Edit:
    Here are the values for the slots:
    0 - item in hand
    1 - helmet
    2 - body armor
    3 - pants
    4 - boots

    Also TeeePeee Clients won't necessarily crash when sending a wrong formatted packet. I don't believe the client would crash with a wrong formatted entity equipment packet (it may, but I've never had it :) ) But indeed, better safe than sorry.
     
    TeeePeee and welsar55 like this.
  4. Offline

    welsar55

  5. Offline

    TeeePeee

    CaptainBern
    Damn, I was so close to the right sending method for packets xP Operating on memory is tough in a pinch. Also thanks for clearing this up - I was tight for time and couldn't do the question justice. I'm glad you stepped in.
     
    CaptainBern likes this.
Thread Status:
Not open for further replies.

Share This Page