/give Command with a JSON-Book

Discussion in 'Plugin Development' started by xkev320x, Mar 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    xkev320x

    Hey everyone, I have a problem. I want to give the player a book when he joins. The book is formatted with JSON-Text and there's an error when the player joins:
    Code:
    18:16:37
     CONSOLE:
    [INFO] Data tag parsing failed: Unexpected token 't' at: text":"================
    18:16:37
     CONSOLE:
    ","color":"dark_gray"},{"text":" Spielprinzip ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    18:16:38
     CONSOLE:
    ","color":"blue"},{"text":"geht es darum, auf den verschiedenen fliegenden Inseln Items zu sammeln, welche sich in den Truhen befinden. Noch dazu kannst du mit einem von vier Kits starten.","color":"blue"}]","["",{"text":"================
    18:16:38
     CONSOLE:
    ","color":"dark_gray"},{"text":" Regeln ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    18:16:38
     CONSOLE:
    gelten die normalen Serverregeln komplett unverändert. Um diese zu lesen, klicke ","color":"blue"},{"text":"hier","color":"blue","underlined":"true","clickEvent":{"action":"run_command","value":"/lobby"}},{"text":" um zur Lobby zu gelangen und die Serverregeln zu lesen.","color":"blue"}]","["",{"text":"================
    18:16:38
     CONSOLE:
    ","color":"dark_gray"},{"text":" Die Items ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    18:16:38
     CONSOLE:
    3 Arten von Items zu unterscheiden. Die normalen, die, die dir Effekte geben und die, die dem Gegner Effekte geben. Die starken Items, wird man eher seltener finden.","color":"blue"}]","["",{"text":"================
    18:16:38
     CONSOLE:
    ","color":"dark_gray"},{"text":" Die Kits ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    18:16:38
     CONSOLE:
    ingesamt vier Kits, zwei kostenlose, und zwei kaufbare Kits. Du kannst ein Kit kaufen, indem du auf das entsprechende Schild klickst, wie beim Ausrüsten.","color":"blue"}]"
    
    Btw. the text is german ;D So my Code looks like this:
    Code:
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + p.getName() + " minecraft:written_book 1 0 {pages:[\"[\"\",{\"text\":\"================\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"      « \",\"color\":\"dark_gray\"},{\"text\":\"SkyPvP\",\"color\":\"dark_aqua\",\"bold\":\"true\"},{\"text\":\" »\n\",\"color\":\"dark_gray\"},{\"text\":\"================\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"\n\n\n➠ Das Spielprinzip\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"2\"}},{\"text\":\"\n➠ Regeln\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"3\"}},{\"text\":\"\n➠ Die Items\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"4\"}},{\"text\":\"\n➠ Die Kits\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"5\"}},{\"text\":\"\n\n\n(Tipp: Klicke auf die Abschnitte, um schnell zu ihnen zu gelangen.)\",\"color\":\"gray\",\"italic\":\"true\"}]\",\"[\"\",{\"text\":\"================\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"   «\",\"color\":\"dark_gray\"},{\"text\":\" Spielprinzip \",\"color\":\"dark_aqua\",\"bold\":\"true\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"1\"}},{\"text\":\"»\n\",\"color\":\"dark_gray\"},{\"text\":\"================\n\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"In \",\"color\":\"blue\"},{\"text\":\"SkyPvP \",\"color\":\"blue\"},{\"text\":\"geht es darum, auf den verschiedenen fliegenden Inseln Items zu sammeln, welche sich in den Truhen befinden. Noch dazu kannst du mit einem von vier Kits starten.\",\"color\":\"blue\"}]\",\"[\"\",{\"text\":\"================\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"      «\",\"color\":\"dark_gray\"},{\"text\":\" Regeln \",\"color\":\"dark_aqua\",\"bold\":\"true\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"1\"}},{\"text\":\"»\n\",\"color\":\"dark_gray\"},{\"text\":\"================\n\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"In SkyPvP gelten die normalen Serverregeln komplett unverändert. Um diese zu lesen, klicke \",\"color\":\"blue\"},{\"text\":\"hier\",\"color\":\"blue\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/lobby\"}},{\"text\":\" um zur Lobby zu gelangen und die Serverregeln zu lesen.\",\"color\":\"blue\"}]\",\"[\"\",{\"text\":\"================\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"     «\",\"color\":\"dark_gray\"},{\"text\":\" Die Items \",\"color\":\"dark_aqua\",\"bold\":\"true\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"1\"}},{\"text\":\"»\n\",\"color\":\"dark_gray\"},{\"text\":\"================\n\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"Es gibt 3 Arten von Items zu unterscheiden. Die normalen, die, die dir Effekte geben und die, die dem Gegner Effekte geben. Die starken Items, wird man eher seltener finden.\",\"color\":\"blue\"}]\",\"[\"\",{\"text\":\"================\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"     «\",\"color\":\"dark_gray\"},{\"text\":\" Die Kits \",\"color\":\"dark_aqua\",\"bold\":\"true\",\"clickEvent\":{\"action\":\"change_page\",\"value\":\"1\"}},{\"text\":\"»\n\",\"color\":\"dark_gray\"},{\"text\":\"================\n\n\",\"color\":\"gray\",\"bold\":\"true\",\"strikethrough\":\"true\"},{\"text\":\"Es gibt ingesamt vier Kits, zwei kostenlose, und zwei kaufbare Kits. Du kannst ein Kit kaufen, indem du auf das entsprechende Schild klickst, wie beim Ausrüsten.\",\"color\":\"blue\"}]\"],title:§8«§3§lSkyPvP§8»,author:§bPvP-Unlimited}");
    
    I know it's very long, because JSON is a little **** :D I created the command and the only thing I changed was some few additional ' \" ', because it's important and without it, there are errors in eclipse
    I hope you guys can help me..the command is right :/
     
  2. Offline

    adam753

    Obviously your json is invalid. I don't know exactly where and it's hard to tell with all the backslashes in there, but jsonlint.com is a good validator.
    (protip: just like code, if you write it in a file rather than all on one line, it'll be easier to see where errors are..)
     
  3. Offline

    xkev320x

    @adam753 I checked my JSON with the website and the output is
    Code:
    Parse error on line 1:
    { pages: [ \"[
    -----^
    Expecting 'STRING', '}'
    
    And my JSON code in better formatting:
    <Removed>
    Yeah I know with all the backslashes it's hard but it's neccesary
    I hope this helps :)

    <Edited by bwfcwalshy: Removed MediaFire link.>
     
    Last edited by a moderator: Mar 21, 2015
  4. Dann versuch mal {\"pages\":[
     
  5. Offline

    adam753

    @xkev320x
    Yeah it's invalid. The keys need to be strings, which means using quotation marks.

    @xkev320x
    I was referring to the link above. See the part of it that's highlighted in red? That's a big hint.

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Last edited by a moderator: Mar 21, 2015
  6. Offline

    mrCookieSlime

    Please speak English on this Forum, not everyone here can speak german.
     
  7. Offline

    xkev320x

  8. Offline

    adam753

    @xkev320x
    Code:
    {
        "pages": [
            "      [
             "",
    What is this? You shouldn't be using json if you can't find glaring errors for yourself.
     
  9. Offline

    xkev320x

    I did not write the JSON-Code, http://minecraftjson.com did it for me, the only thing I added was some ' \" ' , because it was neccesary(gave errors in eclipse), so those quotation marks you're showing me are not mine :/
     
  10. Invisible

    nverdier

    @xkev320x The site you gave doesn't do that. When you were adding the backslashes, you probably added that quotation mark.
     
  11. Offline

    xkev320x

    I've tested a little bit around and removed that quotation mark, now there's another error:
    Code:
    21:45:38
    CONSOLE:
    [INFO] Data tag parsing failed: Unbalanced square brackets []: {"pages":"[["",{"text":"================
    21:45:38
    CONSOLE:
    ","color":"dark_gray"},{"text":"SkyPvP","color":"dark_aqua","bold":"true"},{"text":"
    21:45:38
    CONSOLE:
    auf die Abschnitte, um schnell zu ihnen zu gelangen.)","color":"gray","italic":"true"}]","["",{"text":"================
    21:45:38
    CONSOLE:
    ","color":"dark_gray"},{"text":" Spielprinzip ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    21:45:38
    CONSOLE:
    ","color":"blue"},{"text":"geht es darum, auf den verschiedenen fliegenden Inseln Items zu sammeln, welche sich in den Truhen befinden. Noch dazu kannst du mit einem von vier Kits starten.","color":"blue"}]","["",{"text":"================
    21:45:38
    CONSOLE:
    ","color":"dark_gray"},{"text":" Regeln ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    21:45:38
    CONSOLE:
    gelten die normalen Serverregeln komplett unverändert. Um diese zu lesen, klicke ","color":"blue"},{"text":"hier","color":"blue","underlined":"true","clickEvent":{"action":"run_command","value":"/lobby"}},{"text":" um zur Lobby zu gelangen und die Serverregeln zu lesen.","color":"blue"}]","["",{"text":"================
    21:45:38
    CONSOLE:
    ","color":"dark_gray"},{"text":" Die Items ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    21:45:38
    CONSOLE:
    3 Arten von Items zu unterscheiden. Die normalen, die, die dir Effekte geben und die, die dem Gegner Effekte geben. Die starken Items, wird man eher seltener finden.","color":"blue"}]","["",{"text":"================
    21:45:38
    CONSOLE:
    ","color":"dark_gray"},{"text":" Die Kits ","color":"dark_aqua","bold":"true","clickEvent":{"action":"change_page","value":"1"}},{"text":"
    21:45:39
    CONSOLE:
    ingesamt vier Kits, zwei kostenlose, und zwei kaufbare Kits. Du kannst ein Kit kaufen, indem du auf das entsprechende Schild klickst, wie beim Ausrüsten.","color":"blue"}"]"],"title":"83lSkyPvP8","author":"bPvP-Unlimited"}
    
    And my current json looks like this https://www.dropbox.com/s/30oo6879paldtvk/book.json?dl=0
    I have no idea how to fix it..
    EDIT: @adam753 I don't want to use JSON but I need it for those books and usually I'd use the Chat Component API but it doesn't support the change_page clickeventaction ._.
     
    Last edited: Mar 21, 2015
  12. Offline

    xkev320x

  13. Offline

    xkev320x

    @adam753 bump pls. I just saw that the JSON, which minecraft is using, is a little bit different e.g. pages: mustn't be in quotation marks and so on. So I took the original code from the command(http://minecraftjson.com) and I only added 5 or 6 backslashes. But it won't work yet :( I hope that's a little help and referring to the fact above -> you can't use JSON-Validators for "Minecraft-JSON", because it's not exactly the same.
     
  14. Offline

    Infuzion

  15. Offline

    xkev320x

    Seems similar to my JSON but I'll try it ;)
    EDIT: @Infuzion I've tested your code and it gave me a book with no title and author and there was only one page: * Invalid book tag *
    So I edited your code a lot, after a while the book had the right name and author but still the same content. It won't work, and remember you must use the "Minecraft-JSON", the pages, title, author tags are not in quotation marks! (Yees I edited this but still...)
     
    Last edited: Mar 24, 2015
Thread Status:
Not open for further replies.

Share This Page