FlashyReese / CommandAliases

Alternate short commands for complex commands
MIT License
25 stars 6 forks source link

Tellraw JSON keeps failing #41

Closed kmm569 closed 1 year ago

kmm569 commented 1 year ago

I am trying to write a custom /help command, and keep coming to an issue when using the /tellraw command. I keep getting the following error: com.mojang.brigadier.exceptions.CommandSyntaxException: Expected whitespace to end one argument, but found trailing data at position 79: ...":" HELP",<--[HERE]

My JSON has all the quotes escaped properly, and I have searched through past issues as well as anything general I could find with a google search, but I'm not sure where it is going wrong.

This is the JSON I am trying to use:

["",{"text":"=-=-=-=","color":"#D87C14"},{"text":" HELP","bold":true,"color":"gold"},{"text":" =-=-=-=","color":"#D87C14"},{"text":"\n"},{"text":"Select a command to\nget more help","color":"blue"},{"text":"\n"},{"text":"=-=-=-=-=-=-=-=-=-=","color":"#D87C14"},{"text":"\n"},{"text":"/home","color":"yellow"},{"text":" - Set up and teleport to saved locations","color":"gray"},{"text":"\n"},{"text":"/new","color":"yellow"},{"text":" - See the newest information about the server","color":"gray"},{"text":"\n"},{"text":"/warp","color":"yellow"},{"text":" - Warp to popular locations across the world","color":"gray"},{"text":"\n"},{"text":"/spawn","color":"yellow"},{"text":" - Teleport back to world spawn","color":"gray"},{"text":"\n"},{"text":"=-=-=-=-=-=-=-=-=-=","color":"#D87C14"},{"text":"\n"},{"text":"Choose an option below to see\ncommands for that group","color":"blue"},{"text":"\n"},{"text":"=-=-=-=-=-=-=-=-=-=","color":"#D87C14"},{"text":"\n"},{"text":"[Member] [Trusted] [Admin]","color":"aqua"}]

Escaped version:

[\"\",{\"text\":\"=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\" HELP\",\"bold\":true,\"color\":\"gold\"},{\"text\":\" =-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"Select a command to\nget more help\",\"color\":\"blue\"},{\"text\":\"\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"/home\",\"color\":\"yellow\"},{\"text\":\" - Set up and teleport to saved locations\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"/new\",\"color\":\"yellow\"},{\"text\":\" - See the newest information about the server\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"/warp\",\"color\":\"yellow\"},{\"text\":\" - Warp to popular locations across the world\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"/spawn\",\"color\":\"yellow\"},{\"text\":\" - Teleport back to world spawn\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"Choose an option below to see\ncommands for that group\",\"color\":\"blue\"},{\"text\":\"\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"[Member] [Trusted] [Admin]\",\"color\":\"aqua\"}]

I have tried removing spaces in the text string near where the error is happening, but I still continue to get the same error. I am not sure where I am going wrong here.

Full file:

{
  "schemaVersion": 1,
  "commandMode": "COMMAND_CUSTOM",
  "command": "help",
  "permission": 0,
  "actions": [
    {
      "command": "tellraw $executor_name() [{\"text\":\"=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"HELP\",\"bold\":true,\"color\":\"gold\"},{\"text\":\"=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"Select a command to\nget more help\",\"color\":\"blue\"},{\"text\":\"\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"/home\",\"color\":\"yellow\"},{\"text\":\" - Set up and teleport to saved locations\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"/new\",\"color\":\"yellow\"},{\"text\":\" - See the newest information about the server\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"/warp\",\"color\":\"yellow\"},{\"text\":\" - Warp to popular locations across the world\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"/spawn\",\"color\":\"yellow\"},{\"text\":\" - Teleport back to world spawn\",\"color\":\"gray\"},{\"text\":\"\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"Choose an option below to see\ncommands for that group\",\"color\":\"blue\"},{\"text\":\"\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\n\"},{\"text\":\"[Member] [Trusted] [Admin]\",\"color\":\"aqua\"}]",
      "commandType":"SERVER"
    }
  ]
}
kmm569 commented 1 year ago

Note: I was able to get the same functionality by assigning the JSON text to a database value, and calling that instead of hardcoding it into the custom help command

FlashyReese commented 1 year ago

I escaped the original JSON you provided, and it seems to works as intended

{
  "schemaVersion": 1,
  "commandMode": "COMMAND_CUSTOM",
  "command": "help",
  "permission": 0,
  "actions": [
    {
      "command": "tellraw $executor_name() [\"\",{\"text\":\"=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\" HELP\",\"bold\":true,\"color\":\"gold\"},{\"text\":\" =-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\\n\"},{\"text\":\"Select a command to\\nget more help\",\"color\":\"blue\"},{\"text\":\"\\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\\n\"},{\"text\":\"/home\",\"color\":\"yellow\"},{\"text\":\" - Set up and teleport to saved locations\",\"color\":\"gray\"},{\"text\":\"\\n\"},{\"text\":\"/new\",\"color\":\"yellow\"},{\"text\":\" - See the newest information about the server\",\"color\":\"gray\"},{\"text\":\"\\n\"},{\"text\":\"/warp\",\"color\":\"yellow\"},{\"text\":\" - Warp to popular locations across the world\",\"color\":\"gray\"},{\"text\":\"\\n\"},{\"text\":\"/spawn\",\"color\":\"yellow\"},{\"text\":\" - Teleport back to world spawn\",\"color\":\"gray\"},{\"text\":\"\\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\\n\"},{\"text\":\"Choose an option below to see\\ncommands for that group\",\"color\":\"blue\"},{\"text\":\"\\n\"},{\"text\":\"=-=-=-=-=-=-=-=-=-=\",\"color\":\"#D87C14\"},{\"text\":\"\\n\"},{\"text\":\"[Member] [Trusted] [Admin]\",\"color\":\"aqua\"}]",
      "commandType":"SERVER"
    }
  ]
}

image

It appears that you didn't escape the \ for \n image

FlashyReese commented 1 year ago

My suggestion is to use an online tool like https://www.freeformatter.com/json-escape.html on your original JSON then paste it into the command field.