Custom player count message without ProtocolLib

Discussion in 'Plugin Development' started by FroznMine, Aug 19, 2014.

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

    FroznMine

    Hi community,

    I got a 'small' question about packets etc. ;)

    I know that there are libraries like ProtocolLib or PacketLib, which allow you to modify the player count message in the server list, which you see, when you hover the current online players.

    Is there anyway to do this without any external libraries? I'm not a Java beginner, kind of intermediate, so I think I will understand the code, when there is some.

    I think it has something todo with the net.minecraft.server.ServerPing class, but I don't know how to send a packet or anything else, because I don't got a CraftPlayer which I could send something. Is that right or totally wrong?

    I don't got the time to read through the source code of one of this libraries. If someone can reply with the specific code I would be VERY HAPPY :D

    Thanks for your help

    FroznMine
     
    GrandmaJam likes this.
  2. Offline

    xTrollxDudex

  3. Offline

    FroznMine

    I searched it but I didn't find anything like this. Because of that I asked. :)

    Anyway: Thanks for your answer. I'm going to test if it works for me.
     
  4. Offline

    FroznMine

    I finally tested the code you were showing me, but it produces an error:
    It looks like that has been replaced with something else, cause "t" is just an Integer. I think that's not correct. :)

    So here is my solution of this, for anybody else who needs it:

    1. I found out, that you have to replace
    Code:java
    1. t = MinecraftServer.class.getDeclaredField("t");

    with
    Code:java
    1. t = MinecraftServer.class.getDeclaredField("u");


    Of course you can rename the field to "u" or anything else.


    2. You also have to change the world from which you getHandle() twice.

    If you want to use a world, which you load with i.e. Multiverse you get an exception when starting the server, because he doesn't know the world at this moment. To use Multiverse-loaded-worlds make a schedueled task with one tick delay like this:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,
    2. new Runnable() {
    3. public void run() {
    4. CustomPlayer cp = new CustomPlayer(new PlayerInteractManager(((CraftWorld) Bukkit.getServer().getWorld("Hauptwelt")).getHandle()));
    5. list.add(cp);
    6. }
    7. }, 1);


    That makes the new CustomPlayer instance after the complete server started, and then the worlds should be loaded.

    3. Because of the new UUID system you have to replace one String when creating a new GameProfile

    When you create a new CustomPlayer you call the cunstructor of EntityPlayer, which needed a GameProfile which looked like that
    Code:java
    1. new GameProfile("aRandomString", "test")

    now for the UUIDs you have to change this to something else like
    Code:java
    1. new GameProfile(UUID.randomUUID(), "test")


    That should work. Hope I could help :)

    By the way: Is there a better way to get new UUIDs?

    FroznMine
     
  5. Offline

    FroznMine

    Now that problem is solved I got a new one:

    I can make custom players with individual names, but when I want to join the server, I get an error, that the received string is too long (54>16). I think that has to do with the minecraft limitations, but on other servers there are even longer names in this list.

    What I do:

    On enable: I create a string list with all custom names. With one tick delay I create players from this names. That all works and the players are shown in the list.

    On player join: I iterate through all online players and get their names. Then I compare this names to that from the list. If they are equal the fake player gets hidden to the new joined and he can't see the fake player in the tab list.

    That works with short names, but not with too long. How do I get this working?
     
  6. Offline

    FroznMine

    Just want to ask, if really nobody knows a solution.
     
  7. Offline

    FroznMine

    Bumping, if there is somebody still on this forums^^
     
  8. Offline

    Zandor300

    You can do this using the ServerListPingEvent.
     
  9. Offline

    FroznMine

    Sure? What I want to do is display a text instead of the online players if you hover over the online players number.

    In the ServerListPingEvent you get an iterator, but you can't add something to an iterator. That's why it's an iterator and not a list...
     
    GrandmaJam likes this.
  10. Offline

    Zandor300

    Then I read your first post wrong :)
     
  11. Offline

    FroznMine

    No problem :D

    Anybody else an idea?
     
Thread Status:
Not open for further replies.

Share This Page