DevSrSouza/KotlinBukkitAPI

eventFlow causing listeners to be unregistered

Closed this issue · 13 comments

Hi, I am new to Kotlin and the KotlinBukkitAPI, so it's entirely possible this issue is being caused by a misunderstanding of Kotlin or this API. I am not new to Java or Spigot plugins, and have been working with them for a few years now.

I have a plugin that registers listeners during the LifecycleEvent.ENABLE phase, namely:

events {
    event<EntityPortalEnterEvent> {
        logger.info("Hello from EntityPortalEnterEvent!")
    }
    event<PlayerPortalEvent> {
        // [... some code...]
        pluginCoroutineScope.launch {
            val changedWorldEvent = withTimeoutOrNull(5000) {
                eventFlow<PlayerChangedWorldEvent>(priority = EventPriority.HIGHEST)
                    .filter { it.player == player }
                    .onEach { delay(1000) }
                    .first()
            } ?: return@launch
            // [... do some stuff with changedWorldEvent...]
            // [ !!! ]
        }
    }
}

Here's my problem: every time the eventFlow finishes and the code reaches the [ !!! ], every listener in my plugin is unregistered, and I don't know why. If I comment out the eventFlow code, the listeners are NOT unregistered.

I confirmed this by creating a command:

command("spl") {
    executor {
        EntityPortalEnterEvent.getHandlerList().registeredListeners.forEach { sender.sendMessage("L: $it") }
    }
}

Executing this command before going through a portal correctly returns 1 registered listener for the EntityPortalEnterEvent. Then after I go through a portal and trigger the PlayerPortalEvent and eventFlow, the command returns nothing, meaning the listener was unregistered.

Any help would be appreciated.

Hi, I will try to reproduce it.

HI @bermudalocket, can you test this last build?

http://jenkins.devsrsouza.com.br/job/KotlinBukkitAPI/123/

Is already publish in the repositories, if you are compilation do not work, use changing in your dependency configuration, this will always retrieve the lastest versions.

dependencies {
    compileOnly("br.com.devsrsouza.kotlinbukkitapi:core:0.2.0-SNAPSHOT") {
        isChanging = true
    }
}

configurations.all {
    resolutionStrategy.cacheChangingModulesFor(120, "seconds")
}

Thanks @DevSrSouza. Forgive me, I am rusty with Gradle. Should I also set the architecture and serialization dependencies to 0.2.0-SNAPSHOT? I'm running into an exception with core set to 0.2.0-SNAPSHOT and the rest set to 0.1.0-SNAPSHOT:

java.lang.NoClassDefFoundError: org/snakeyaml/engine/v2/exceptions/MarkedYamlEngineException
	at com.charleskorn.kaml.Yaml.decodeFromString(Yaml.kt:36) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.serialization.interceptor.impl.StringFormatInterceptor.decodeFromString(StringFormatInterceptor.kt:19) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.serialization.SerializationConfig.loadFromFile(SerializationConfig.kt:62) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.serialization.SerializationConfig.load(SerializationConfig.kt:40) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.serialization.architecture.impl.ConfigLifecycle.onPluginEnable(ConfigLifecycle.kt:41) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.serialization.architecture.impl.ConfigLifecycle.invoke(ConfigLifecycle.kt:33) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.serialization.architecture.impl.ConfigLifecycle.invoke(ConfigLifecycle.kt:22) ~[?:?]
	at br.com.devsrsouza.kotlinbukkitapi.architecture.KotlinPlugin.onEnable(KotlinPlugin.kt:63) ~[?:?]
	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[patched_1.16.2.jar:git-Paper-186]

EDIT: was able to resolve this exception by adding kaml as a dependency:

implementation("com.charleskorn.kaml:kaml:0.22.0")

Testing the newest version of KBAPI now.

EDIT2: working perfectly now, thank you!

Yes you should update all your KotlinBukkitAPI dependencies to 0.2.0-SNAPSHOT.

About the implementation("com.charleskorn.kaml:kaml:0.22.0"), I will check it out, because should not be required.

Hey @bermudalocket, can you test this last build without using implementation("com.charleskorn.kaml:kaml:0.22.0")?

http://jenkins.devsrsouza.com.br/job/KotlinBukkitAPI/125/

EDIT: Check this new section at the documentation: https://github.com/DevSrSouza/KotlinBukkitAPI/wiki/Getting-Started#preventing-conflicts-important

The exception is gone using the latest version.

I do get this error when trying to set everything to version 0.2.0-SNAPSHOT:

Execution failed for task ':compileKotlin'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not find br.com.devsrsouza.kotlinbukkitapi:architecture:0.2.0-SNAPSHOT.

Yes, Architecture is not needed anymore in 0.2.0 and in the latest builds from 0.1.0, now is build in inside the Core, and it extensions like Config is leveraged by the other modules, in the case for Config, the Serialization module.

The issue was fixed, hope I help migrating to 0.2.0 as well :D.

I will close the issue for now, if you find any issue, please summit a new one, this helps the project alot.

Running into a related issue this morning :). The error:

[12:00:33 ERROR]: java.lang.NoSuchMethodError: 'void br.com.devsrsouza.kotlinbukkitapi.extensions.event.ExEventKt.unregisterAllListeners(org.bukkit.event.Listener)'

I don't understand why the plugin is trying to call this method. I do not have 0.1.0-SNAPSHOT in the dependencies or on the server anymore. On the server I have the KBAPI jar for build 125.

This doesn't happen on my development server, only production. But they're both using the same version of my plugin and the same version of KBAPI.

@bermudalocket Do you have the full stacktrace for this error?
Plz also check if you do not have two KotlinBukkitAPI in your production server, and check if you are not embedding KotlinBukkitAPI inside your plugin or any other that you could be using KotlinBukkitAPI.

@DevSrSouza Unfortunately that is the entire error. It doesn't print a stack trace with it.

Hey @bermudalocket , I create a discord, is faster to give support, can you join it to we configure it out?

https://discord.gg/HhucBqk

I figured it out. I had another plugin that had 0.1.0-SNAPSHOT shaded into it. Not sure why there wasn't a plugin conflict error during startup! I joined your Discord anyway, just in case ;)

Thanks for the help!