Solved java.lang.NoClassDefFoundError: net/minecraft/world/level/Level

Discussion in 'Plugin Development' started by FoxinatorDev, Jun 24, 2021.

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

    FoxinatorDev

    A similar error occurred as well with net/minecraft/world/entity/ai/attributes/Attribute. I don't have the slightest clue to how to fix this. I think this has something to do with the remappings. I have made sure that I am running the correct server version (1.17) with /version.

    Full error:
    Code:
    [11:23:29] [Server thread/ERROR]: [SMPCommands] Plugin SMPCommands v1.0 has failed to register events for class smp.entity.EntityNPC because net/minecraft/world/entity/ai/attributes/Attribute does not exist.
    [11:23:29] [Server thread/ERROR]: Error occurred while enabling SMPCommands v1.0 (Is it up to date?)
    java.lang.NoClassDefFoundError: net/minecraft/world/level/Level
            at smp.main.Main.registerEvents(Main.java:202) ~[?:?]
            at smp.main.Main.onEnable(Main.java:46) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:495) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:409) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:608) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:264) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:987) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:307) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at java.lang.Thread.run(Thread.java:831) [?:?]
    Caused by: java.lang.ClassNotFoundException: net.minecraft.world.level.Level
            at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:142) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:99) ~[spigot.jar:3161-Spigot-f773da8-f81f499]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:519) ~[?:?]
            ... 12 more
     
  2. Offline

    KarimAKL

    @FoxinatorDev This seems like a weird error. What is line 202 of smp.main.Main?
     
  3. Offline

    FoxinatorDev

    Code:
     public void registerEvents() {
            Bukkit.getPluginManager().registerEvents(new KloonboatTrait(), this);
            Bukkit.getPluginManager().registerEvents(new CorruptWorld(), this);
    //        Bukkit.getPluginManager().registerEvents(new CustomEntityHandler(), this);
            Bukkit.getPluginManager().registerEvents(new EntityNPC("not_real_npc"), this);
            Bukkit.getPluginManager().registerEvents(new EntityHandlerListeners(), this); // This is the line of error
            Bukkit.getPluginManager().registerEvents(new CustomItem("event_registration", new ItemStack(Material.ACACIA_BOAT), false), this);
            Bukkit.getPluginManager().registerEvents(new EntityYeti.YetiTrait(), this);
            Bukkit.getPluginManager().registerEvents(new ItemUpgradeBook.Events(), this);
            Bukkit.getPluginManager().registerEvents(new ItemUpgradeBookAbility.Events(), this);
            Bukkit.getPluginManager().registerEvents(new CustomItem.Events(), this);
        }
    In EntityHandlerListeners, there is an import net.minecraft.world.level.Level. I am also using remapped-mojang of spigot.
     
  4. Online

    davidclue

    I had the same error before, my problem was Java just decided not to work. I've had a few problems before with Java just not working and wasted lots of hours trying to fix something that was never broken. I had this exact error and deleted the line, then retyped it by hand, did not copy-paste, and then rebuilt the jar. If this doesn't work, try copying the class, deleting it, re-creating the class, and just paste, and then rebuilding the jar.
     
  5. Offline

    FoxinatorDev

    I am still getting the same error. Does the spigot or papermc jar already have both mojang mapped and non mojang mapped classes?
     
  6. Online

    davidclue

    @FoxinatorDev I'm not sure, are you using eclipse by any chance? Try removing java from your build path and re-implementing it, this might work.
     
  7. Offline

    Shqep

    @FoxinatorDev
    NoClassDefFoundError is an error when the JVM tries to load a class that can not be found at runtime, but available at compile time. I decompiled the spigot 1.17 jar and found no classes with the canonical name "net.minecraft.world.level.Level", and neither was "net.minecraft.world.entity.ai.attributes.Attribute" found.
    Are you sure you're using the same .jar or dependency for development & running the server?

    And about @davidclue's solution, this could work too since NoClassDefFoundErrors are usually thrown when there's a mismatch between compile time dependencies & runtime classpaths. You might want to look into this too.
     
  8. Offline

    FoxinatorDev

    I am using IntelliJ.

    I am probably using the wrong .jar for running the server. For development, I used mojang mapped version. Although, whenever I use that .jar to run the server, it breaks every other plugin not using those classes. I don't know how to get both.
     
  9. Offline

    Shqep

    I can propose a fix is that you should convert your stuff back to using the official Bukkit's API, because that's usually the original server file. Spigot, Paper, etc. are forks of Bukkit so prioritizing Bukkit compatibility can somewhat guarantee that your plugins will work on most versions.
    If you're developing based on Spigot's API or Paper's API, you have to know that your plugin might not work on servers running pure Craftbukkit at core.

    And if you really, really, really wanted to use the mojang mapped version, you can shade the ENTIRE dependency jar into your plugin. If you're using Maven, use Maven Shade Plugin. If you're a Gradle guy, use Johnrengelman's Shadow. If you use Ant or basic Java project, take time to learn Maven or Gradle.
    The cons of this would be that the uber jar would contain a lot of classpath conflicts, and you don't even know if anybody else also shadows. This may result in weird runtime problems and errors.
     
    davidclue likes this.
Thread Status:
Not open for further replies.

Share This Page