Cannot use /give in a function that is ran by a command block

SpongeForge Version: 1.12.2-2838-7.2.1
Minecraft Version: 12.2.2

I have a function called server:new_player :

give @s minecraft:apple
say gave apple to player

In game I have a command block placed with the following command:

execute @p ~ ~ ~ function server:new_player

What I expect this to do is to run this function for the player that activates the command block (by redstone, don’t know if this matters), and ultimately gives the player an apple and say that the player received the apple.

What actually happens is weird. The /say command will work fine, but the /give command does nothing. Looking at the command block’s previous output it says:

Executed 2 command(s) from function 'server:new_player'

Based on this behavior I’m assuming if a command fails in a function, execution continues to the next command. Whats weird though is if I run the command block’s command in the chat, then it works perfectly.

Wouldn’t the command block select the nearest player, execute at the that player’s location (the triple tilde should represent the player’s location right?), then pass that player into the function as the (@s) target selector?

I have tried using the minecraft: alias for the commands but nothing changes. I also used /which to see if theres any conflicts. I’ve also loaded up a single player world and done the exact same thing and it works, so I’m assuming its a Sponge related problem.

I’m fairly new to command blocks so I might be missing something obvious.

It’s a bug in Sponge, one that I have recently patched. Unfortunately, it hasn’t made itself to our site yet because we’re having intermittent issues with our download API - but rest assured it’s not your fault, and it is going to be in a new buld soon.

For more information: https://github.com/SpongePowered/SpongeCommon/issues/2599

1 Like

Well thats good news to hear, thanks! Got a time estimate? Or should I clone the branch and build Sponge myself if the download is not going to be soon?

Build it yourself if you like, unfortunately couldn’t tell you when the download service might be back in action!

So I cloned and built it (accidentally built SpongeCommon first instead of SpongeForge :upside_down_face:) and it works! Well partially. I upped my function to four commands, and in each of them I used @s for the target selector: /give was the only command that worked.

I switched the other three commands to @p and it works now. I figured I would let you know about it. Those other three commands are plugin commands (from LuckPerms, EconomyLite, and Nucleus).