Written book set with JSON

Discussion in 'Plugin Development' started by Internetak, Feb 15, 2018.

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

    Internetak

    Hello,
    I need create ItemStack Written_book and set tags, etc. with JSON. JSON I have in String that I get from file.
    My answer is: How to set Meta of book with JSON without using dispatchCommand?
    Thanks you and sorry for my English.
     
  2. I found a way of doing it. I hooked into the CommandGive class and got this for you:


    Imports:
    Code:
    import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
    import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    Code:
    Code:
                Player player = null; //SET PLAYER
                int item_id = 387; //WRITTEN_BOOK
                int durability = 0;
                int amount = 1;
                String item_data = "{pages:[\"[\\\"\\\",{\\\"text\\\":\\\"Hello Sir\\\",\\\"color\\\":\\\"green\\\"}]\"],title:Book,author:ProxyGames14}
    ";
    
                Item item = Item.getById(item_id);
                ItemStack localItemStack = new ItemStack(item, amount, durability);
    
                EntityPlayer eplayer = ((CraftPlayer)player).getHandle();
                try {
                    localItemStack.setTag(MojangsonParser.parse(item_data));
                } catch (MojangsonParseException e) {
                    e.printStackTrace();
                }
    
                eplayer.inventory.pickup(localItemStack);

    Good luck with it, I hope this works for you :)
    BTW: Make sure you check if the version is right because the NTBtag (Json) is changed for books in the higher versions.
     
    Last edited: Feb 16, 2018
Thread Status:
Not open for further replies.

Share This Page