Colored Nametags?

Discussion in 'Plugin Development' started by FadedMystery, Jan 3, 2014.

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

    FadedMystery

    I was wondering how you could do colored nametags. I do not like TagAPI at ALL and I am not good with Packets. If you could help me out that would be great. Thanks in advanced. ;)
     
  2. Offline

    Zenok

    You need import the class colors, and in the event of sending a message in the chat change the name to show the player.
     
  3. Offline

    FadedMystery

    Zenok I don't know what your talking about. Importing "class colors"? Like ChatColor? Sending a message? Are you talking about sending a message to a player with... colors? ._.
     
  4. Offline

    Zenok



    You mean add a tag before the name? Example: [Moderator] Playerusername
     
  5. Offline

    xize

    FadedMystery I think the only possibillity is using the scoreboard api to change the nametag maybe it could be done through packets but I don't know but what you could do is trying to look at tag api's source code;)
     
  6. Offline

    FadedMystery

    No.

    Zenok No.

    xize Yea, I looked around it. It seemed confusing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    Garris0n

    1. Don't triple post.
    2. Seeing as there's a super-easy-to-use library (TagAPI), if you don't want to use it you should learn to use packets/nms to do it yourself. You could also use the scoreboard API, but that won't allow you to change a nametag per-player unless you use scoreboard packets.
     
  8. Offline

    FadedMystery

    Garris0n
    1. I didn't mean to triple post. My internet was being slow, so I spammed the post button.
    2. Don't be so harsh about everything.
    3. I came here to ask about it. Not to be complained about it to.
     
    AguilaAudaz likes this.
  9. Offline

    Garris0n

    Look through the TagAPI source and see how they did it.
     
  10. Offline

    Zenok

    So, sorry
     
  11. Offline

    FadedMystery

    Zenok Its fine. Do just didn't know what I was talking about, sorry if I sounded harsh ._.

    Garris0n Can you tell me where in the TagAPI source it was done? Theres a lot of packages/classes.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  12. Offline

    Garris0n

    Well...technically all of it. It might be done a bit more complicated than usual to support more than one minecraft version, but in the end the entirety of the code technically "does" it. Look through and try to understand what it's doing I suppose. The gist of the concept seems to be sending a PacketPlayOutNamedEntitySpawn with the id of whatever player's name to change.
     
  13. Offline

    FadedMystery

    Garris0n can I have a link to that code page?
     
  14. Offline

    Garris0n

    It's implemented in a way that the code is spread out, as I said. There's not really an "exact spot" to look, you have to look through the code.
     
  15. Offline

    FadedMystery

    Garris0n Can you give me the spots?
     
  16. Offline

    Jentagh

    A quick Google of "tagapi" returned this Bukkit page as the first result. Upon further examination of the page, you may notice the section entitled "I'm a developer", which contains this handy link. You may notice the code sections scattered throughout. Simply "not liking" TagAPI doesn't really seem like a reason to make things harder upon yourself. You might enjoy this code-block I shall spoonfeed to you.

    Code:
    @EventHandler
      public void onNameTag(PlayerReceiveNameTagEvent event) {
        if(event.getPlayer().getName().equals("mbaxter")){
        event.setTag("Notch");
      }
    }
    Furthermore, there are links to all the documentation on this page. You're welcome.

    As a point of interest, it's not very fun to help people who aren't willing to help themselves.

    Above post ^_^

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  17. Offline

    ShearsSheep

  18. Offline

    Drkmaster83

    Asking people to find the code that will make a plugin work is exactly like asking them to feed the code. If you don't learn how to look through classes and see how they work (through referencing other classes), you'll never know how to reverse engineer a plugin. There's also something called a Java Decompiler, you should Google it. It enables you to decompile a JAR file into its .java sources.

    Despite the slight rant above, there are packets being sent involving PacketPlayOutNamedEntitySpawn and I'm sure PacketPlayOutDestroyEntity. Do research on these packets, their payloads, and also do research on how to send packets yourself. This is what is required if you don't want to rely on an external dependency. It's the harder way, but I consider it to be the less-of-a-hassle way.

    The OP clearly said the he does not like TagAPI and does not want to use it. Therefore, he offered the option of requiring help with sending packets. This is the code you should have spoon-fed him (if any at all), as he said he doesn't want to use TagAPI.

    Both of you, don't get offended if I come off as crass or rude. I'm just stating it how it is and what needs to be accomplished for this post to be resolved.

    Edit: As an alternative, FadedMystery, you can learn more about Scoreboards and Teams and send the colored nametags by adding colored prefixes and suffixes to these Teams and adding the players into the teams, much like NameTagEdit or ColoredTags.
     
  19. Offline

    Fr33styler

    the most easy way is to use namtagedit, is aleardy maked and you can set how you want and of course he use packet and reflection and will work with all version :D
     
  20. Offline

    FadedMystery

    Jentagh I know that, but I wanted to use that so it would only show to certain people. Which I was unable to do.

    Drkmaster83 Ill look into the Packets, I was just asking for help.

    Code:java
    1. String oldName = p.getName();
    2.  
    3. EntityPlayer changingName = ((CraftPlayer) p).getHandle();
    4.  
    5. changingName.displayName = color + p.getName();
    6.  
    7. if(show != p) {
    8.  
    9. ((CraftPlayer) show).getHandle().playerConnection.sendPacket(new PacketPlayOutNamedEntitySpawn(changingName));
    10.  
    11. }
    12.  
    13. changingName.displayName = oldName;
    14.  

    Drkmaster83 this is what I got now. It didn't work :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  21. Offline

    Drkmaster83

    Keep in mind that when you're sending a PacketPlayOutNamedEntitySpawn, you're sending a new name that CANNOT be more than 16 characters. If it is, it will crash the client.
    I haven't played with this packet much (no necessity to), but this should work:
    Code:
    String color = "ยง4";
    Player originalPlayer;
    color += originalPlayer.getName();
    if(color.length() > 16) color = color.substring(0, 15);
    for(Player p : Bukkit.getOnlinePlayers())
    {
      ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutNamedEntitySpawn(color));
    }
    
     
  22. Offline

    xTrollxDudex

    Drkmaster83
    Wouldn't the packet's position need to be updated as the player moves, as well as using PacketPlayOutDestroyEntity?

    (Do not send to the hidden player, this kicks him with "Cannot interact with yourself" or "Illegal stance". Something like that)
     
  23. Offline

    Drkmaster83

    I'm pretty sure on the PacketPlayOutDestroyEntity, as I recollect running through MD/DC source code and seeing that packet... However, I'm pretty sure that it wouldn't need to be updated with the player's location, as 1). That'd be a bit choppy and 2). It's spawning an entity which should basically be assigned to the player.
    Again, not sure, haven't done much work with this packet.
     
  24. Offline

    FadedMystery

    :/ Whatever, Ill just not include nametags.
     
  25. Offline

    Drkmaster83

    Either way, if you do decide to use them, I recommend a Scoreboard system.
     
Thread Status:
Not open for further replies.

Share This Page