aadnk / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
288 stars 92 forks source link

Unable to connect to server with synchronous event handling #163

Open fvoichick opened 5 years ago

fvoichick commented 5 years ago

Follow this template except for feature requests. Use pastebin when providing /protocol dump and any relevant errors.

Make sure you've done the following:

Debug paste link: https://pastebin.com/TPFuRzU9 (console error message) https://pastebin.com/Ju8N1Xqs (protocol dump)

Description and relevant errors: I created a plugin with the following (Kotlin) code:

package com.voichick.cyclic

import com.comphenix.protocol.PacketType
import com.comphenix.protocol.ProtocolLibrary
import com.comphenix.protocol.events.PacketAdapter
import com.comphenix.protocol.events.PacketEvent
import org.bukkit.plugin.java.JavaPlugin

@Suppress("unused")
class Cyclic : JavaPlugin() {
    override fun onEnable() {
        val listener = object : PacketAdapter(this, PacketType.Play.Server.POSITION) {
            override fun onPacketSending(event: PacketEvent?) {
                logger.info("Sending packet!")
            }
        }
        val manager = ProtocolLibrary.getProtocolManager()
        manager.asynchronousManager.registerAsyncHandler(listener).syncStart()
    }
}

Now, whenever I try to log into the server, there's an error and I'm unable to.

When I make the following replacement:

//      manager.asynchronousManager.registerAsyncHandler(listener).syncStart()
        manager.addPacketListener(listener)

...it works as expected. My understanding is that the two lines above should be fairly equivalent, except that the first one is run synchronously and the second is run asynchronously, but I'm not sure if that's correct. Regardless, I don't think that the code above should prevent players from joining the server.