Changing the a players name tag :: Similar to TagAPI

Discussion in 'Plugin Development' started by Cjbolt, Oct 22, 2012.

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

    Cjbolt

    Hello, I'm trying to change the color of a players name tag in-game, similar to TagAPI. The only reason I'm not currently using TagAPI is become I'm stubborn and simply just want to know how to do it, and not rely on other plugins. I'm fairly new to coding, and this might be a complex task, but any help is greatly appreciated. I found this link: http://forums.bukkit.org/threads/tutorial-teams-name-color-and-wool-hats-asigned-to-player.80835/

    This was pretty helpful, but I still don't quite understand it, especially when I try out the code that is listed and I receive errors.
    Code:
        private void applyTeam(Player p, String team){
            String oldName = p.getName();
            EntityPlayer changingName = ((CraftPlayer) p).getHandle();
            if(team.equalsIgnoreCase("red")){
                changingName.name = red.toString()+p.getName();
            }else
    ANY input at all on this topic that is relevant to name tags and changing the players name tag color is very much appreciated.
     
  2. Offline

    Tirelessly

    You need to reference craftbukkit to use that code. Just call the method.
     
  3. Offline

    Cjbolt

    Tirelessly
    I'm going to need a little bit more help then that. I apologize, but as I said earlier I'm a little new to coding.
     
  4. Offline

    Tirelessly

    Ok, so when you first make a new java project you go into the build path and add bukkit.jar, I assume. You're going to need to reference craftbukkit.jar as well. Yes, they are different. Then you're going to need to import some things, your IDE can help you there. Do you understand calling a method?
     
  5. Offline

    ZeusAllMighty11

    You're going to need a knowledge of sending, and destroying packets as well.
     
  6. Offline

    Cjbolt

    Tirelessly
    Oh alright, I only referenced bukkit.jar, didn't realize I would need to reference both in this case. & yes I understand calling the method, thanks.

    ZeusAllMighty11
    Where can I learn about the packets that are sent/received?
     
  7. Offline

    Comphenix

    You're best bet is always reading the Minecraft source code (either by using MCP or by using JD-GUI on craftbukkit.jar).

    There are some resources available, if you're uncomfortable reading the obfuscated source code. You can get a list of every sent and received packet by going to Minecraft Coalition, and if you're wondering which packets are sent AFTER the one you're overriding, you may get some use of the diagrams I drew in my thread about ProtocolLib.

    For instance, by looking at the diagrams you'll notice that #20 Spawned Named Entity is always followed by a few #5 Entity Equipment-packets (this is on the second diagram to the left). So if you send a #20 packet, you must also send the corresponding #5 packets. Otherwise the player will have no armor.
    [​IMG]
     
    Cjbolt likes this.
  8. Offline

    Cjbolt

    Comphenix
    That diagram link was very helpful for understanding the general idea of packets, thanks for that. Packets are completely new to me, so I may have to mess around a little bit before I can even grasp how to use them correctly, in the meantime, would you happen to know any plugins that use packets and offer source code? I'll be looking for some just so I can see how they're used.

    Thanks again!
     
  9. Offline

    Comphenix

    Well, I've written a number of example plugins that use packets on the ProtocolLib page. They all use ProtocolLib, of course, but that might actually be a plus of you just want to get an overview on how it works in general. You can also look at the plugins that are using ProtocolLib.

    This is a relatively advanced topic, though. Sending new packets aren't terribly complicated, but as soon as you start intercepting packets in either direction, things get messy really fast. Especially if you want to stay compatible with other Bukkit plugins.

    Sure, implementing something yourself can be a very useful learning experience, but I wouldn't recommend using a custom solution in a public plugin. You should at least check that it's compatible popular plugins such as Orebfuscator, TagAPI, ect. Especially if you're also intercepting packets, and not just sending your own.
     
  10. Offline

    Cjbolt

    Comphenix
    That's probably good programming etiquette, but I planned on making the majority of the plugins my server uses. If I do decided to release the plugin to the public (as I naturally should because the community here is wonderful), I'll make sure everything is working and compatible as well.

    I'm quite unfamiliar with packets though so it might be a while for that.

    Also, might be a silly question, but if I were to shortcut all this and just reference TagAPI, would I have to download TagAPI into my plugins folder as well?
     
  11. Offline

    Comphenix

    Yes. You have to add it to your build path, along with your CraftBukkit plugin folder. :)
     
  12. Offline

    Cjbolt

    Thanks for all the help, very much appreciated. I think for now I'm going to use TagAPI and then reference your ProtocolLib page so I can slowly teach my self packets. Followed as well ;D
     
    Comphenix likes this.
  13. Offline

    chaseoes

    TagAPI is open source. :|
     
  14. Offline

    Cjbolt

    chaseoes
    If so, please link the source code as I cannot find it.
     
  15. Offline

    chaseoes

    Cjbolt likes this.
  16. Offline

    morshu9001

    Well I tried that... Did not work at all.
     
Thread Status:
Not open for further replies.

Share This Page