1

I'm currently working on a Minecraft OITC plugin for Spigot 1.8.8! ~All written in Kotlin with IntelliJ

While starting off with a simple EventHandler for ItemDrops, I ran into an Issue: Could not pass event PlayerDropItemEvent to RarityOITC v1.0-SNAPSHOT Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics

After some time i figured that my code is probably fine:

My Main Class:

package me.ysheiny.rarityoitc

import me.ysheiny.rarityoitc.handlers.PlayerHandler
import org.bukkit.plugin.java.JavaPlugin

class RarityOITC : JavaPlugin() {

    val prefix = "[&bRarity&dOITC&f]"
    override fun onEnable() {
        // Plugin startup logic
        logger.info("Plugin Enabled!")

        PlayerHandler(this)
    }

    override fun onDisable() {
        // Plugin shutdown logic
        logger.info("Plugin Disabled!")
    }
}

My PlayerHandler:

package me.ysheiny.rarityoitc.handlers

import me.ysheiny.rarityoitc.RarityOITC
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerDropItemEvent

class PlayerHandler(plugin: RarityOITC?) : Listener {
    init {
        Bukkit.getPluginManager().registerEvents(this, plugin)
    }

    @EventHandler
    fun onPlayerDropItem(event: PlayerDropItemEvent)
    {
        event.isCancelled = true
    }
}

I did some research and found there is an exception building the Kotlin Runtime. My project is build with maven in these are my dependencies:

<dependencies>
        <dependency>
            <groupId>com.sample</groupId>
            <artifactId>sample</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/spigot-1.8.8.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-runtime</artifactId>
            <version>1.2.71</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/kotlin-runtime-1.2.71.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

Because of the old version I'm using a local spigot dependency for 1.8.8. Otherwise I have been trying to add the Kotlin runtime by hand too, but the version was to old: Kotlin: API version 1.2 is no longer supported; please, use version 1.3 or greater.

I have no idea what to do. Can someone help me fix this problem?

YSheiny
  • 11
  • 3
  • Any reason you aren't using a more recent version of Kotlin? 1.2 is absolutely ancient. It's on 1.8.10 now. However, if Minecraft plugins require less than JVM 1.8 (I have no idea if they do), then you must keep your Kotlin version below 1.8. If you do update to 1.8.10, `kotlin-stdlib-jdk8` is obsolete and should be replaced with `kotlin-stdlib`. – Tenfour04 Mar 28 '23 at 19:20
  • Thanks, I will try this fix. Actually Minecraft Plugins don't require specific versions of Kotlin. I just wanted to try if it would work, when I add the runtime by hand. The download was just very old. – YSheiny Mar 29 '23 at 05:56
  • I removed the local dependency and changed `kotlin-stdlib-jdk8` to `kotlin-stdlib` but nothing has changed... I really don't know what to do at this point. – YSheiny Mar 29 '23 at 15:18
  • It's still telling you "use version 1.3 or greater"? – Tenfour04 Mar 29 '23 at 16:50
  • No, because it was telling me that for the local dependency. Now it builds normally again with no errors. But as soon as I put the .jar on the server it gives me the error when I drop a item (because that is what the listener is for). – YSheiny Mar 29 '23 at 18:17
  • I think i have to compile it into the .jar somehow, but I have no idea how to do that with maven. – YSheiny Mar 29 '23 at 18:18
  • I don't use Maven for builds, but I think your problem is that your build task is not including dependencies in the output jar. You need that `kotlin-stdlib` dependency included. The others should not be included since they have `system` scope. This might help you with configuring what's included in the build: https://stackoverflow.com/questions/1729054/including-dependencies-in-a-jar-with-maven – Tenfour04 Mar 29 '23 at 18:43
  • Actually, I'm not sure the Kotlin runtime dependency should have system scope, unless Spigot has it built in. Maybe all you need to do is remove `system` from the `kotlin-runtime` dependency. – Tenfour04 Mar 29 '23 at 18:45

1 Answers1

0

I somehow found an solution!

Okay, the thing is: I think I just forgot to update the Artifact which controlled which depedency is build into the jar. So the information was in the pom.xml, but not applied to the actual build.

So for everyone having problems like me. search a solution and alsways remember to update the Artifact in your Project structure.

My dependencies now look like this:

        <dependency>
            <groupId>com.sample</groupId>
            <artifactId>sample</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/spigot-1.8.8.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>

I think the kotlin-runtime wasn't the actual problem. Just change kotlin-stdlib-jdk8 to kotlin-stdlib as recommenden by Tenfour04.

YSheiny
  • 11
  • 3