WesJD / AnvilGUI

Capture user input in Minecraft through an anvil GUI in under 20 lines of code
MIT License
463 stars 111 forks source link

NoClassDefFoundError on 1.20.6 #330

Open UsainSrht opened 1 month ago

UsainSrht commented 1 month ago

Just upgraded server version and anvilgui and now I can't use it.

Version

This server is running Paper version 1.20.6-112-master@347bbe3 (2024-05-26T22:17:48Z) (Implementing API version 1.20.6-R0.1-SNAPSHOT) You are running the latest version Previous version: 1.20.6-90-b149584 (MC: 1.20.6)

Error

[08:11:23 WARN]: java.lang.NoClassDefFoundError: Could not initialize class me.usainsrht.sccore.anvilgui.AnvilGUI
[08:11:23 WARN]:        at SCCore-1.3.2.jar//me.usainsrht.sccore.anvilgui.AnvilGUI$Builder.<init>(AnvilGUI.java:400)
[08:11:23 WARN]:        at SCClaims-1.0.7.jar//me.usainsrht.scclaims.commands.ClaimCommand.execute(ClaimCommand.java:70)
[08:11:23 WARN]:        at io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand.run(BukkitCommandNode.java:86)
[08:11:23 WARN]:        at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73)
[08:11:23 WARN]:        at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:31)
[08:11:23 WARN]:        at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:19)
[08:11:23 WARN]:        at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8)
[08:11:23 WARN]:        at net.minecraft.commands.execution.CommandQueueEntry.execute(CommandQueueEntry.java:5)
[08:11:23 WARN]:        at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:103)
[08:11:23 WARN]:        at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:442)
[08:11:23 WARN]:        at net.minecraft.commands.Commands.performCommand(Commands.java:349)
[08:11:23 WARN]:        at net.minecraft.commands.Commands.performCommand(Commands.java:336)
[08:11:23 WARN]:        at net.minecraft.commands.Commands.performCommand(Commands.java:331)
[08:11:23 WARN]:        at net.minecraft.server.network.ServerGamePacketListenerImpl.performUnsignedChatCommand(ServerGamePacketListenerImpl.java:2202)
[08:11:23 WARN]:        at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$14(ServerGamePacketListenerImpl.java:2176)
[08:11:23 WARN]:        at net.minecraft.server.TickTask.run(TickTask.java:18)
[08:11:23 WARN]:        at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:151)
[08:11:23 WARN]:        at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1511)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:195)
[08:11:23 WARN]:        at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:125)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1488)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1411)
[08:11:23 WARN]:        at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:135)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1377)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1238)
[08:11:23 WARN]:        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:323)
[08:11:23 WARN]:        at java.base/java.lang.Thread.run(Thread.java:1583)
[08:11:23 WARN]: Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: net/minecraft/world/entity/player/EntityHuman [in thread "Server thread"]
[08:11:23 WARN]:        at java.base/java.lang.Class.forName0(Native Method)
[08:11:23 WARN]:        at java.base/java.lang.Class.forName(Class.java:534)
[08:11:23 WARN]:        at java.base/java.lang.Class.forName(Class.java:513)
[08:11:23 WARN]:        at io.papermc.reflectionrewriter.runtime.AbstractDefaultRulesReflectionProxy.forName(AbstractDefaultRulesReflectionProxy.java:68)
[08:11:23 WARN]:        at io.papermc.paper.pluginremap.reflect.PaperReflectionHolder.forName(Unknown Source)
[08:11:23 WARN]:        at SCCore-1.3.2.jar//me.usainsrht.sccore.anvilgui.version.VersionMatcher.match(VersionMatcher.java:43)
[08:11:23 WARN]:        at SCCore-1.3.2.jar//me.usainsrht.sccore.anvilgui.AnvilGUI.<clinit>(AnvilGUI.java:42)
[08:11:23 WARN]:        ... 28 more

Code

    public boolean execute(@NotNull CommandSender commandSender, @NotNull String cmd, @NotNull String[] args) {
        if (args.length > 0) {
            if (commandSender instanceof Player player) {
                if (args[0].equalsIgnoreCase("debug") && commandSender.hasPermission("scclaims.command.debug")) {
                    if (args[1].equalsIgnoreCase("anvilgui")) {
                        try {
                            new AnvilGUI.Builder().plugin(SCClaims.getInstance())
                                    .title(args[2])
                                    .itemLeft(new ItemStack(Material.GRASS_BLOCK))
                                    .open(player);
                        } catch (Exception | Error e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
UsainSrht commented 1 month ago

AnvilGUI version: 1.9.4-SNAPSHOT Heres the shade config image

image

mastercake10 commented 1 month ago

Please see #327, this has been discussed before. You need to ensure that Paper remaps your plugin. Unfortunately there is no way to "tell" Paper to only re-map certain classes (i.e. Anvil-GUI classes). Are you using Paperweight?

UsainSrht commented 1 month ago

I am not using paperweight or any nms related things in those plugins.

mastercake10 commented 1 month ago

Check your server log file that your plugin gets remapped by paper.

UsainSrht commented 1 month ago

Deleted the .paper-remapped folder and started the server again, both of my plugins didn't get remapped (SCClaims & SCCore)

mastercake10 commented 1 month ago

What are the contents of the MANIFEST.MF file in your plugin's .jar file?

UsainSrht commented 1 month ago
Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 21
mastercake10 commented 1 month ago

Where is SSCore located? Is it a normal spigot plugin inside the plugins folder? There must be a reason why it doesn't get remapped by Paper.

UsainSrht commented 1 month ago

yes both sccore and scclaims are in plugins folder, they have paper plugin.ymls also i just saw that mentioned in the other issue

mastercake10 commented 1 month ago

Apparently you can't shade the class files of AnvilGUI into a Paper Plugin, it assumes the NMS code to be mojang-mapped, so it doesn't do any remapping, I just asked on their Discord.

You can use my gradle version of AnvilGUI tho that has mojang mappings in it: https://github.com/mastercake10/AnvilGUI/tree/no_relocation

UsainSrht commented 1 month ago

uhh how exactly? system scope?

mastercake10 commented 1 month ago

by building the jar and shading it into your plugin

edit: you can also use the .jar on my repo: https://repo.spaceio.xyz/#browse/browse:maven-public:net%2Fwesjd%2Fanvilgui%2F1.9.5-SNAPSHOT%2F1.9.5-20240510.204921-4%2Fanvilgui-1.9.5-20240510.204921-4.jar

UsainSrht commented 1 month ago

I mean, how is this possible? image image

mastercake10 commented 1 month ago

try this in your pom.xml:

<!-- AnvilGUI -->
<dependency>
    <groupId>net.wesjd</groupId>
    <artifactId>anvilgui</artifactId>
    <version>1.9.5-SNAPSHOT</version>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>
UsainSrht commented 1 month ago

Worked thanks. Are you guys going to publish a separate jar for mojang mappings?

mastercake10 commented 1 month ago

The jar you're using right now (my no-relocation branch) has both mappings in it, so it works on both paper and spigot. I don't know if there is any advantage in distributing two jar files. With both mappings in it, one could target paper and spigot at the same time.

I didn't know that these paper plugins were a thing, so I think I will create a PR soon for my fork.

Lets leave this issue open until its officially resolved.

0dinD commented 1 month ago

@UsainSrht As far as I've understood, you should be able to use the official AnvilGUI version in a Paper plugin as long as you set the paperweight-mappings-namespace to spigot in your MANIFEST.MF file. Have you tried that?

Taken from this information in the dev-announcements channel in the PaperMC Discord server:

Default Mappings Assumption

  • By default, all Spigot/Bukkit plugins will be assumed to be Spigot-mapped if they do not specify their mappings namespace in the manifest. Conversely, all Paper plugins will be assumed to be Mojang-mapped if they do not specify their mappings namespace in the manifest.
  • Spigot-mapped plugins will need to be deobfuscated on first load, Mojang-mapped plugins will not.

Manual Manifest Configuration

  • For more complex setups, you can manually set the paperweight-mappings-namespace attribute in the manifest. Acceptable values are mojang, mojang+yarn (treated the same as mojang), or spigot.

The official AnvilGUI version is only compatible with Spigot-mapped plugins, which is why you will need to configure your manifest manually if you are creating a Paper plugin.

It's probably worth adding this information to the AnvilGUI README, if this solves your issue.

WesJD commented 1 week ago

@UsainSrht did the above solve your issue? if so we should add to README

TrueMB commented 1 day ago

Helped in my case, thank you! Maybe also a helpful Link for anybody, who is running into the same issue: https://docs.papermc.io/paper/dev/project-setup#spigot-mappings