ProtocolLib kills my respawn packet

Discussion in 'Spigot Plugin Development' started by Nogtail, May 20, 2015.

  1. Nogtail

    Artist

    Note: This is the first time I have used ProtocolLib asynchronously so it is probably some simple noob mistake.

    I am attempting to send a respawn packet (and other packets which follow it) to a player using PlayerList.moveToWorld() (what Player.spigot().respawn() uses internally) however it seems that whenever I have a ProtocolLib async handler listening to the respawn packet the packet mysteriously vanishes.

    I am currently on a different device than my testing code but hopefully this mockup is good enough (may not compile as is): https://gist.github.com/anonymous/570c1f9458e750b1b2d2

    When the handler is started synchronously the packet appears to always reach the player but if it is started asynchronously there seems to be some kind of race condition occurring and the respawn packet only occasionally reaches the player.

    I have modified the client to check if it was a client issue and it seems like the packet never arrives in the NetworkManager, I guess this could be because of being corrupted or unreadable for some reason but I have no idea how Netty handles these things and I have found no error messages.

    Is there anything obvious that I am doing wrong? The debug message always seems to fire but the packet often never gets through and when it does appears to be completely random but seems more common when the client is receiving chunk packets (probably my imagination though). Thanks :)
     
  2. Yes, you should never try listening to clientbound packets async.

    Server sends packets on main thread, and to listen for them async you basicly need to cancel sending and move handling to separate thread, and then send them again. That's what protocollib does. And that doesn't work well.
     
    #2 Shevchik, May 20, 2015
    Last edited: May 20, 2015
  3. joehot200

    Supporter

    So you're modifying packets instead of using the respawn() method in the Spigot API? Is there any speciic reason for this?
     
  4. Respawn packets are sent only from the client to the server. However its save to emulate a client sent that packet to the server.
     
  5. He meant DimensionChange packet, that is used as a respawn packet too.
     
  6. Nogtail

    Artist

    I am unfamiliar with any respawn method other than Player.Spigot.respawn() which requires a players health to be 0. The reason I am listening for the packet is to keep the packet order from changing due to the async listener, as I am modifying other packets which need the respawn packet to come after. If there is a better way to delay packets other than including them in the listener I would love to know about it.

    I am meaning this packet: http://wiki.vg/Protocol#Respawn
     
  7. Nogtail

    Artist