Util [ProtocolLib] Setting: Player Count Message

Discussion in 'Resources' started by mrgreen33gamer, Dec 21, 2014.

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

    mrgreen33gamer

    Hi there! I haven't seen a tutorial out there, other than 1 that got removed, but I decided that I want to spread my joy to people that need it the most! Anyway, what I introduce to you is setting the Player Count Message. Hovering over the players online and replacing it with a customized message, in other words.

    You're going to need, of course, ProtocolLib: http://dev.bukkit.org/bukkit-plugins/protocollib

    Anyway, here is the basic code:

    Code:java
    1.  
    2.  
    3. @Override
    4. public void onEnable(){
    5. final List<WrappedGameProfile> names = new ArrayList<WrappedGameProfile>();
    6. names.add(new WrappedGameProfile("1", ChatColor.LIGHT_PURPLE + "This is message 1!"));
    7. names.add(new WrappedGameProfile("2", ChatColor.GREEN + "This is message 2!"));
    8. //If you want to add more message, copy 'names.add(new WrappedGameProfile("number", "ur message"));'
    9. //Make sure that 'number' goes in order. Instance:
    10. //names.add(new WrappedGameProfile("1", ChatColor.LIGHT_PURPLE + "This is message 1!"));
    11. //names.add(new WrappedGameProfile("2", ChatColor.GREEN + "This is message 2!"));
    12. //names.add(new WrappedGameProfile("3", ChatColor.GREEN + "This is message 3!"));
    13. //names.add(new WrappedGameProfile("4", ChatColor.GREEN + "This is message 4!"));
    14. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL,
    15. Arrays.asList(PacketType.Status.Server.OUT_SERVER_INFO), ListenerOptions.ASYNC) {
    16. @Override
    17. public void onPacketSending(PacketEvent event) {
    18. event.getPacket().getServerPings().read(0).setPlayers(names);
    19. }
    20. });
    21. }
    22.  
    23.  


    Let's get down to what it all means and understanding it!

    This will get the protocol library and it will add a packet listener so we can add our message and send the packets!

    Code:java
    1.  
    2. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL,
    3. Arrays.asList(PacketType.Status.Server.OUT_SERVER_INFO), ListenerOptions.ASYNC) {
    4. });
    5.  


    Next, we want to add some messages for our packet! So we want to create a list! This will add the messages to the player count:

    Code:java
    1.  
    2. final List<WrappedGameProfile> names = new ArrayList<WrappedGameProfile>();
    3. names.add(new WrappedGameProfile("1", ChatColor.LIGHT_PURPLE + "This is message 1!"));
    4. names.add(new WrappedGameProfile("2", ChatColor.GREEN + "This is message 2!"));
    5. //If you want to add more message, copy 'names.add(new WrappedGameProfile("number", "ur message"));'
    6. //Make sure that 'number' goes in order. Instance:
    7. //names.add(new WrappedGameProfile("1", ChatColor.LIGHT_PURPLE + "This is message 1!"));
    8. //names.add(new WrappedGameProfile("2", ChatColor.GREEN + "This is message 2!"));
    9. //names.add(new WrappedGameProfile("3", ChatColor.GREEN + "This is message 3!"));
    10. //names.add(new WrappedGameProfile("4", ChatColor.GREEN + "This is message 4!"));
    11.  


    Now, we have to run the event so that your players can receive the message!
    Code:java
    1.  
    2. @Override
    3. public void onPacketSending(PacketEvent event) {
    4. event.getPacket().getServerPings().read(0).setPlayers(names);
    5. }
    6.  


    Once you have copied and pasted the code and edited it they way you wanted it. Install ProtocolLib to your Plugin by following these steps:

    ONLY WORKS FOR ECLIPSE!

    1. Right click your plugin name
    2. Click: Properties
    3. Click the section: Java Build Path
    4. Now click the button to the right named: Add External JARs...
    5. Now select the ProtocolLib that you have stored on your computer
    6. Click Open.
    7. Then click OK.

    Once you have exported your file to the server, insure that you have installed ProtocolLib to the server, as well.

    Now you are ready to go!

    If you have any errors. Please tell me in the comments. If this was helpful, leave a like :D!
    If you have noticed any issues with my code or any grammar mistakes or anything that should be added, please inform me in the comments!

    Thanks for reading!

    ~mrgreen33gamer
     
    EpicMinerMan321 and ChipDev like this.
  2. Offline

    teej107

  3. Offline

    mrgreen33gamer

    @teej107 This qualifies as a HELPFUL post. Not a question.
     
    ChipDev likes this.
  4. Offline

    teej107

    @mrgreen33gamer Solved threads are meant to be helpful to everybody. You do a search on a problem and then find a thread that had your problem that is solved. You follow its suggestions and you too get your problem solved. You don't need to create a resource for a solved thread because now that I think about it, it's like a duplicate post but in a different section TBH.
     
    mrgreen33gamer likes this.
  5. Offline

    mrgreen33gamer

    @teej107 Sorry. But I thought that since more people come here for resources, I could add this and it would get a little more views to help people. Other than looking at a 'question' section, I may pursue.
     
  6. Offline

    ChipDev

    Wow, It works :D Awesome tutorial ,thanks!
     
  7. Offline

    LucasZZZ

    Thanks for the code!
     
    Last edited: Oct 13, 2015
Thread Status:
Not open for further replies.

Share This Page