JorelAli / CommandAPI

A Bukkit/Spigot API for the command UI introduced in Minecraft 1.13
https://commandapi.jorel.dev
MIT License
535 stars 67 forks source link

Paper 1.20.6 onLoad not working #603

Closed FabianKoder closed 1 month ago

FabianKoder commented 1 month ago

CommandAPI version

9.5.3

Minecraft version

1.20.6

Are you shading the CommandAPI?

Yes

What I did

onLoad():

CommandAPI.onLoad(new CommandAPIBukkitConfig(this));

onEnable():

CommandAPI.onEnable();

What actually happened

I immediately receive the following error in the load lifecycle:

[XXX] Error initializing plugin 'xxx-jar-with-dependencies.jar' in folder 'plugins\.paper-remapped' (Is it up to date?)
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    dev/jorel/commandapi/nms/NMS_1_20_R4.lambda$reloadDataPacks$14(Lnet/minecraft/server/MinecraftServer$ReloadableResources;Ljava/util/Collection;Lnet/minecraft/server/MinecraftServer$ReloadableResources;)V @205: invokevirtual
  Reason:
    Type 'net/minecraft/server/packs/resources/CloseableResourceManager' (current frame, stack[1]) is not assignable to 'net/minecraft/server/packs/resources/MultiPackResourceManager'
  Current Frame:
    bci: @205
    flags: { }
    locals: { 'dev/jorel/commandapi/nms/NMS_1_20_R4', 'net/minecraft/server/MinecraftServer$ReloadableResources', 'java/util/Collection', 'net/minecraft/server/MinecraftServer$ReloadableResources', 'java/util/Collection', 'com/google/common/collect/ImmutableList', 'java/util/ArrayList' }
    stack: { 'net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplateManager', 'net/minecraft/server/packs/resources/CloseableResourceManager' }
  Bytecode:
    0000000: 2ab6 01a2 c000 3eb4 06a8 b607 da2a b601
    0000010: a2c0 003e 2bb5 06a8 2ab6 01a2 c000 3eb4
    0000020: 07dc b607 df2a b601 a2c0 003e b606 bf2c
    0000030: b607 e22a b601 a2c0 003e b606 bfb6 06c5
    0000040: 3a04 1904 b807 e83a 05bb 037b 592a b601
    0000050: a2c0 003e b606 bfb6 06e0 b706 c83a 0619
    0000060: 0619 0559 b806 7557 ba07 ee00 00b9 07f2
    0000070: 0200 572a b601 a2c0 003e b606 ccbb 06d4
    0000080: 59bb 06da 5919 0519 06b7 07f5 2ab6 01a2
    0000090: c000 3eb6 06cc b906 d201 00b6 07f9 b707
    00000a0: fcb9 0800 0200 2ab6 01a2 c000 3eb4 06a8
    00000b0: b606 acb6 0803 2ab6 01a2 c000 3eb6 0807
    00000c0: 2ab6 01a2 c000 3eb4 06a8 b608 0bb6 0811
    00000d0: b1

        at xxx-jar-with-dependencies.jar/dev.jorel.commandapi.CommandAPIVersionHandler.getPlatform(CommandAPIVersionHandler.java:69) ~[xxx-jar-with-dependencies.jar:?]
        at xxx-jar-with-dependencies.jar/dev.jorel.commandapi.CommandAPI.onLoad(CommandAPI.java:112) ~[xxx-jar-with-dependencies.jar:?]
        at xxx-jar-with-dependencies.jar/net.xxx.minecraft.plugins.xxx.XXX.onLoad(XXX.kt:23) ~[xxx-jar-with-dependencies.jar:?]
        at io.papermc.paper.plugin.storage.ServerPluginProviderStorage.processProvided(ServerPluginProviderStorage.java:59) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at io.papermc.paper.plugin.storage.ServerPluginProviderStorage.processProvided(ServerPluginProviderStorage.java:18) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at io.papermc.paper.plugin.storage.SimpleProviderStorage.enter(SimpleProviderStorage.java:39) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler.enter(LaunchEntryPointHandler.java:36) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:532) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:286) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1136) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:323) ~[paper-1.20.6.jar:1.20.6-149-6e71f41]
        at java.base/java.lang.Thread.run(Thread.java:1570) ~[?:?]

Obviously an error on enabling the plugin occurs afterwards; java.lang.IllegalStateException: Tried to access CommandAPIHandler instance, but it was null! Are you using CommandAPI features before calling CommandAPI#onLoad?

What should have happened

No error on load

Server logs and CommandAPI config

No response

Other

Probably has something to do with remapping/no relocation of the NMS classes in PaperMC 1.20.6+

willkroboth commented 1 month ago

I believe the specific error here happens when Paper thinks your plugin is Spigot-mapped, but the code in your jar is actually Mojang-mapped. Paper tries to remap what it thinks is Spigot-mapped code, but the code is already Mojang-mapped, so it gets double remapped and messes up the bytecode, causing that error. The full server log could help verify this theory, though things matching this have come up before.

If you want your plugin to be Spigot-mapped, you should use the commandapi-bukkit-shade dependency. If you want your plugin to be Mojang-mapped, you should use the commandapi-bukkit-shade-mojang-mapped dependency. Note that if you use a plugin.yml, Paper will assume your plugin is Spigot-mapped. If you use a paper-plugin.yml, Paper will assume your plugin is Mojang-mapped. If you would like Paper to treat your plugin differently than it assumes by default, you can declare your mappings in the manifest file, which Paper's documentation describes how to do here: https://docs.papermc.io/paper/dev/project-setup#plugin-remapping.

Looking beyond this specific issue, a lot of developers have had trouble with this before, so it might be useful to add more details about the different mappings to the setup instructions found in the CommandAPI's documentation here (https://commandapi.jorel.dev/9.5.2/setup_shading.html#shading-with-maven).

FabianKoder commented 1 month ago

Thank you very much for the fast response - the missing entry in the manifest was indeed the issue. I think adding a short notice regarding this topic in the docs wouldn't hurt (Even though it's technically not CommandAPI related).

DerEchtePilz commented 1 month ago

Because this is solved, I would close this issue.