Skip to content

Executing with RecipeArgument does not work on Spigot #608

@willkroboth

Description

@willkroboth

CommandAPI version

9.5.3

Minecraft version

1.20.6

Are you shading the CommandAPI?

No

What I did

Registered a command that uses the RecipeArgument:

new CommandAPICommand("recipe")
    .withArguments(new RecipeArgument("recipe"))
    .executes(info -> {
        ComplexRecipe recipe = info.args().getUnchecked("recipe");

        assert recipe != null;

        info.sender().sendMessage(recipe.toString());
    })
    .register();

Start server and run recipe minecraft:arrow in the console.

What actually happened

On Spigot, trying to execute the command prints this exception in the console:

>recipe minecraft:arrow
[08:21:15] [Server thread/WARN]: Unexpected exception while parsing console command "recipe minecraft:arrow"
org.bukkit.command.CommandException: Unhandled exception executing 'recipe minecraft:arrow' in org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper(recipe)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:157) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R4.CraftServer.dispatchCommand(CraftServer.java:910) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at org.bukkit.craftbukkit.v1_20_R4.CraftServer.dispatchServerCommand(CraftServer.java:895) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.server.dedicated.DedicatedServer.bq(DedicatedServer.java:427) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:403) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1293) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1064) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:311) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
Caused by: java.lang.NoClassDefFoundError: net/kyori/adventure/key/Key
        at dev.jorel.commandapi.nms.NMS_1_20_R4.getRecipe(NMS_1_20_R4.java:770) ~[?:?]
        at dev.jorel.commandapi.arguments.RecipeArgument.parseArgument(RecipeArgument.java:62) ~[?:?]
        at dev.jorel.commandapi.arguments.RecipeArgument.parseArgument(RecipeArgument.java:35) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.parseArgument(CommandAPIHandler.java:319) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.argsToCommandArgs(CommandAPIHandler.java:291) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.lambda$generateCommand$0(CommandAPIHandler.java:195) ~[?:?]
        at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?]
        at net.minecraft.commands.execution.tasks.ExecuteCommand.a(SourceFile:29) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(SourceFile:13) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.UnboundEntryAction.a(SourceFile:8) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.CommandQueueEntry.a(SourceFile:8) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.ExecutionContext.a(SourceFile:107) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:416) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:338) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.CommandDispatcher.performPrefixedCommand(CommandDispatcher.java:320) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper.execute(VanillaCommandWrapper.java:43) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:150) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        ... 8 more
Caused by: java.lang.ClassNotFoundException: net.kyori.adventure.key.Key
        at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:160) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:112) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?]
        at dev.jorel.commandapi.nms.NMS_1_20_R4.getRecipe(NMS_1_20_R4.java:770) ~[?:?]
        at dev.jorel.commandapi.arguments.RecipeArgument.parseArgument(RecipeArgument.java:62) ~[?:?]
        at dev.jorel.commandapi.arguments.RecipeArgument.parseArgument(RecipeArgument.java:35) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.parseArgument(CommandAPIHandler.java:319) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.argsToCommandArgs(CommandAPIHandler.java:291) ~[?:?]
        at dev.jorel.commandapi.CommandAPIHandler.lambda$generateCommand$0(CommandAPIHandler.java:195) ~[?:?]
        at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?]
        at net.minecraft.commands.execution.tasks.ExecuteCommand.a(SourceFile:29) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(SourceFile:13) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.UnboundEntryAction.a(SourceFile:8) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.CommandQueueEntry.a(SourceFile:8) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.execution.ExecutionContext.a(SourceFile:107) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:416) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:338) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at net.minecraft.commands.CommandDispatcher.performPrefixedCommand(CommandDispatcher.java:320) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at org.bukkit.craftbukkit.v1_20_R4.command.VanillaCommandWrapper.execute(VanillaCommandWrapper.java:43) ~[spigot-1.20.6-R0.1-SNAPSHOT.jar:4195-b-Spigot-f6a4805-6524758]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:150) ~[spigot-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        ... 8 more

What should have happened

On Paper, the command executes successfully:

> recipe minecraft:arrow
[08:25:27 INFO]: ComplexRecipeImpl[key=minecraft:arrow, recipe=org.bukkit.craftbukkit.inventory.CraftShapedRecipe@58e23d20]

Server logs and CommandAPI config

No response

Other

See Discord.

When NMS#getRecipe is called, it tries to load the ComplexRecipeImpl class. ComplexRecipeImpl implements ComplexRecipe, which extends org.bukkit.Keyed. Since commandapi-bukkit-core depends on Folia and Paper API, org.bukkit.Keyed extends net.kyori.adventure.key.Keyed (in spigot-api, org.bukkit.Keyed does not extend anything). net.kyori.adventure.key.Keyed defines the method net.kyori.adventure.key.Key key(), so the compiled bytecode of ComplexRecipeImpl references net.kyori.adventure.key.Key here. So, when NMS#getRecipe tries to load ComplexRecipeImpl, it has to load net.kyori.adventure.key.Key, which doesn't exist on Spigot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingimplemented for next releaseThis has been implemented in the current dev build for the next public release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions