Tab menu

Discussion in 'Spigot Plugin Development' started by bys1, May 18, 2016.

  1. I'm searching for a good tutorial to set text in a player's tab menu.
    I found something on hypixel but didn't understand anything of it.
    If you know a good tutorial, please post it here.
     
  2. What have you tried?
     
    • Like Like x 1
  3. I tried to find a tutorial
    That's a joke, right?
     
  4. Why would it be? Scroll down to the "Developers" section. There's javadocs and everything.
     
    • Agree Agree x 1
  5. The fact of the matter is, that there's no API for setting the header / footer.

    Unless you want to mess with NMS code, this is an option you should think about taking.
    Heck, there's a config option for TitleManager to turn off all features, so all you've got it just the API.
     
  6. I don't want a resource or an API, I asked for a good tutorial
     
  7. wrong place use wikis
     
  8. This is not at all the wrong place, he's asking for someone, to either give him a link to a tutorial or give him a tutorial on how to set the header and footer of the tab menu.

    On a completely different note, I don't believe there's a tutorial for this on the Wiki anyways, due to the fact that the Bukkit and Spigot API doesn't provide such functionality.
     
    • Like Like x 2
  9. Or you could simply modify the content of the tab list packets. I dont get why everyone wants to mess around with that unsafe nms.

    Im not good at creating documentation or tutorials, but I guess I could try. It doesnt hurt anyone.
    Let me explain you how you would do it using protocollib, a library for intercepting/modifying packets. I personally prefer protocollib because it is pretty reliable.
    Alright, lets get started:

    First, we need to know what we are dealing with. To understand the content/meaning of each client/server -side packet, we need to delve into the client/server code. Fortunately, people already did that for us and made a detailed explanation on this website: http://wiki.vg/Main_Page
    You need to know that there are wrapper classes for each packet, found on this github page: https://github.com/dmulloy2/PacketWrapper
    We wont use a wrapper for this packet, since it is pretty easy to modify and thus we dont need to use that this time. I just wanted to mention it in case you stumble against modifying/sending packets you dont know the content of.
    These wrapper classes already serve as "template" for each packet, allowing us to focus on our actual work instead of implementing the packet first.
    This packet updates the header and footer of our tablist. To change the header and footer, we would simply send a update packet to each player online:
    Code (Text):
    public void setHeaderAndFooter(String header, String footer, Player player)
        {
            PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER);
            packet.getChatComponents().write(0, WrappedChatComponent.fromText(header));
            packet.getChatComponents().write(1, WrappedChatComponent.fromText(footer));
         
            try
            {
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
            }
            catch (InvocationTargetException e)
            {
                this.getLogger().info("Failed to update header/footer");
            }
        }
    Notice that this method will update the header/footer. This means you need to override the default tablist after the player joins. You could also listen for any header/footer packets and simply modify the content by creating a packetlistener.
     
  10. What you're doing there is sending a packet using ProtocolLib, which is just doing the dirty NMS work for you.
     
  11. Though I never touched any nms code :p Also, that is the purpose of protocollib: To provide a wrapper and library for packet modification/interception. I dont think that this is a bad thing
     
    • Agree Agree x 1
  12. Yes, however, he mentioned that he didn't want to use an API.

    I don't think ProtocolLib is bad either and I'd personally rather use that rather than NMS, (unless I'm making a public plugin). That being said I don't think NMS is bad either, nor do I feel like it's unsafe, like you said earlier. The only time it's unsafe is if, you're trying to write version independent code, which might cause it break during updates.
     
  13. Well, I just showed one possible implementation. I am not here to spoonfeed code, I could have also removed the protocollib code. It doesnt change anything. You just send an header/footer packet to the player. The api doesnt matter. I just love protocollib, thats why I used that in my example.

    Which happens quite often actually :p
     
    • Like Like x 1