How to add a wool helmet without actually adding it and overhead name change?

Discussion in 'Plugin Development' started by Lookatmego, Aug 21, 2012.

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

    Lookatmego

    Hey there,

    We have been developing a plugin lately and I have been looking to add a feature, pretty much for each team im trying to add a wool as helmet which enemies are red and friendlies are green but Im trying to place this wool without it actually being there and actually setting the helmet as the wool. I was wondering if its possible by intercepting the packets sent and how exactly that would work? Also if there is a way to change the color of overhead names of players?
     
  2. Unless I missed something. This is not possible.

    But I'm insterested in other people's thoughts.
     
  3. Offline

    Mr Burkes

    This is probably possible, but it seems very impractical. Unless you are extremely good with packets and MC server network structure, I wouldn't bother.
     
  4. Offline

    Lookatmego

    Ye I was thinking it would be the packets sent to clients and modifying them. I was just wondering tho, cuz if there was a easier way I would do it but Im not gonna get into packet modification right now.:D
     
  5. Offline

    Mr Burkes

    Welp, if you look into packet modification, don't come to me :D I don't know jack when it gets to that.
     
  6. Offline

    Lookatmego

    Aha alright ill keep that in mind good sir:D
     
  7. Offline

    rjVapes

    With packets you could probably get it to appear to other people as if the player is wearing wool, but I don't think you'd be able to have the player themselves think so, as it's probably setup client side based on their inventory.

    Like, if you have 2 players, A and B, and you want A to appear to have wool on his head.
    The server tells B "A has wool on his head." and B believe him and A is unchanged
    If the server tells A "You have wool on your head" that same packet would probably be done in the same way that you'd actually edit his inventory.
     
  8. Offline

    Lookatmego

    Yea i was going for what you said just seeing other players with it,its just a way to tell whos on your team and whos enemy but still be able to use armour. Thats why I didnt want to set their helmet as wool.
     
  9. Offline

    turqmelon

  10. Offline

    Lookatmego

    oh wow I hadn't seen that before. Alright cool just wanted I needed thank you
     
  11. Offline

    turqmelon

    No problem. :)
     
  12. Offline

    MrFigg

    I just made a post here that is related to this. I don't know if it will work but it's a start.
     
  13. Offline

    MrFigg

    Lookatmego

    Breakthrough. I found it. Here's what I did:
    Code:
    import net.minecraft.server.Packet5EntityEquipment;
     
    import org.bukkit.DyeColor;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.craftbukkit.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.material.Wool;
     
        // Later in the command
     
        Player player = // got this from command sender
     
        DyeColor dye = DyeColor.WHITE;
     
        for(Player playerInWorld : getServer().getOnlinePlayers()) {
            if(!playerInWorld.equals(player)) {
                ((CraftPlayer) playerInWorld).getHandle().netServerHandler.sendPacket(new Packet5EntityEquipment(((CraftPlayer) player).getEntityId(), 4, new CraftItemStack(new Wool(dye).toItemStack(1)).getHandle()));
            }
        }
    This goes through all the players on the server and tells them that the current player has a white wool block on their head.

    Now to actually use this you'd have to add listeners for when the player changes his headgear or changes worlds and resend the packet, but this proves it can be done. Though I never really doubted it could.

    I'm totally using this myself.
     
Thread Status:
Not open for further replies.

Share This Page