Yamakaja / commanditems

Assign commands to items
https://www.spigotmc.org/resources/command-items.42556/
MIT License
9 stars 15 forks source link

Using a curly bracket inside a command #16

Closed simonfruehauf closed 4 years ago

simonfruehauf commented 4 years ago

Using a { or } inside a command, e.g. entitydata @e[type=minecraft:creeper,distance=..1] {NoAI:1} does not successfully execute. The error logged is Caused by: java.lang.RuntimeException: Attempt to access undefined local 'NoAI:1"'!. It seems that curly brackets inside quotation marks do not get escaped correctly, even if using a .

Yamakaja commented 4 years ago

You can use a backslash ( \, written in configs as \\) to escape the leading curly bracket.

So your command should look like this: entitydata @e[type=minecraft:creeper,distance=..1] \\{NoAI:1}

In case that doesn't help, try a single backslash: entitydata @e[type=minecraft:creeper,distance=..1] \{NoAI:1}

simonfruehauf commented 4 years ago

The first solution (\\) gives me a console error , the second one (\) a chat error .

EDIT: nevermind, it worked after restarting the server a couple times.

simonfruehauf commented 4 years ago

I've been trying something else, in this case this "execute as {player} at @s run setblock ^ ^ ^ minecraft:chest\\{LootTable:"minecraft:chests/simple_dungeon"\\}" command, escaping the curly brackets, but that throws an error. Escaping the colon : and the double quotes inside the command also gives the same error.

Yamakaja commented 4 years ago
simonfruehauf commented 4 years ago

Even when just escaping the opening i get this error.

[15:34:51] [Server thread/INFO]: Failed to read the configuration:
[15:34:51] [Server thread/INFO]: while scanning a plain scalar
 in 'reader', line 193, column 125:
     ...  ^ minecraft:chest\\{LootTable:"minecraft:chests/simple_dungeon"}" }
                                         ^
found unexpected ':'
 in 'reader', line 193, column 134:
     ... aft:chest\\{LootTable:"minecraft:chests/simple_dungeon"}" }
                                         ^
Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.

 at [Source: (File); line: 193, column: 7]
 at [Source: (File); line: 193, column: 7] (through reference chain: me.yamakaja.commanditems.data.CommandItemsConfig["items"]->java.util.LinkedHashMap["creep"]->me.yamakaja.commanditems.data.ItemDefinition["actions"]->java.lang.Object[][0])

The lack of space is intentional (the original command is setblock ^ ^ ^ minecraft:chest\\{LootTable:"minecraft:chests/simple_dungeon"}"), which works without issue when used in the console.

Yamakaja commented 4 years ago

Yeah, you need to pay attention to your quotes (You can’t use double-quotes inside of double quotes without escaping them).

I‘d suggest replacing your outer quotes with ’ and then replacing \\ with a single \

simonfruehauf commented 4 years ago

Thank you very much!