The bug
Because commands in a function are trimmed by java.lang.String#trim
, greedy strings cannot contain trailing spaces (U+0000
.. U+0020
) in a function.
Affected commands
/advancement grant <targets> only <advancement> <criterion>
/advancement revoke <targets> only <advancement> <criterion>
/say <message>
How to reproduce
Install the datapack in Attachments.
/function mc-174587:test
→ ❌ revoked
, the criterion "criterion with a trailing space "
is not granted correctly.
mc-174587/advancement/test.json
{ "criteria": { "criterion with a trailing space ": { "trigger": "minecraft:impossible" } } }
mc-174587/functions/test.mcfunction
advancement grant @s only mc-174587:test criterion with a trailing space execute if entity @s[advancements={mc-174587:test=true}] run say granted execute if entity @s[advancements={mc-174587:test=false}] run say revoked
Linked issues
relates to 1
Attachments
Comments 4
Fixed in 23w31a. I have just noticed that we can include trailing spaces in a function by writing spaces followed by \ and leaving the next line empty as follows:
advancement grant @s only mc-174587:test criterion with a trailing space \
execute if entity @s[advancements={mc-174587:test=true}] run say granted
execute if entity @s[advancements={mc-174587:test=false}] run say revoked
→ ✔ granted
That's not fixed, that's a workaround; lines still cannot end with spaces. Your function's line ends with a "continue on next line", not a trailing space.
Yes, indeed, this is just making it non-trailing by guarding the trailing spaces with a \. It doesn't seem right that trailing trim and greedy strings coexist, but when such a purely syntactic workaround emerges, this issue might be considered as a feature request, like MC-264999. I'd like to leave the decision to the moderators and developers.
Partially fixed in 23w31a, thanks to macros. We can now generate commands that start and/or end with spaces as follows:
Load the following macro
mc-174587:macro
Run the following command
→ ✔ granted
Considering the overhead of macros, I would also like this to be achievable with just a function though.