JSON CHAT FORMATTING

Discussion in 'Spigot Plugin Development' started by simonsejse, Feb 14, 2018 at 8:04 PM.

  1. So I'm doing a plugin where it opens an anvil, now when you do [item] and presses the users head, I want it to find the player's item in hand.
    upload_2018-2-14_21-2-35.png
    So in this it's supposted look like this to the guy im /msg
    hey look > Diamond Sword < cool?
    Now Diamond sword is going to be a json, that you can then see the lore display name, enchants and so on, but I have no idea how JSON is working, and I've tried several things. I'm also having a hard time finding out how I would make the json inside the text..
     
  2. Just use item meta.. im not sure why you would need to use json... and just get the item in the players hand... store it as a variable.. feel free to use a hashmap... then get the information from it.. like name.. lore.. type.. then send it to the other player.
     
  3. Uhm, what? But why does it matter to you why I need to use json? I want to use json, to also make it look cool. For the layout. But why does that matter, it's okay if you don't know how to make a JSON text in chat with tooltip, and all that, but I'll just wait till someone knows its alright..
     
  4. Woah there.. All i was saying is there is no need for what you want... i was trying to give you a nice simple solution.

    However, I thought you said that you wanted to save the item information into json files... not the text to json..

    Now I see what you want... just same the item meta variables, then use them in a json text... There are plenty tutorials on how to use json in spigot.

    As for the rest of the idea I gave you.. it is quite simple.

    When the player clicks the item in the anvil... save the item in their hand to a variable... at that point you can take that item, break down its item meta.. and get the lore, name, enchantments, etc. Once that is done, fill in the variables in the JSON text, then send the message. Hope that makes sense, if not... just let me know.
     
    • Optimistic Optimistic x 1
  5. Thanks, sorry then. Didn't mean to sound rute, it was a misunderstanding then. But, could you show me how to do the JSON text, just a tiny little example, and then of course I'll do the rest so you don't spoon feed. :p
     
  6. https://www.minecraftjson.com/ :D
     
  7. Well, I can't just place that in the code? I need a packet sender right?
     
  8. Code (Text):
    TextComponent msg = new TextComponent("┬žaDiamond Sword");
                msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("┬žaThis text is shown on hover!").create()));
                msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/yourcommand"));
                p.spigot().sendMessage(msg);
     
  9. Wow, thank you so much! The code i tried from watching a youtube video had like 7 lines, so appreciate it!
     
  10. Not related at all to this topic, but I do would like to point out that this website triggers my antivirus software because it contains a JSCoinminer, essentially a bitcoin miner that wants to use your system's resources via JavaScript.
     
  11. Just asking, would it be possible to display it like this in chat? upload_2018-2-16_1-41-1.png
    Mine looks like this now::
    upload_2018-2-16_1-41-31.png
     
  12. I just looked and nd I understand the hover event, but I don't know what to exactly write to find the exactly name, Diamond Sword ,and the enchants and so on..:p
     
  13. Code (Text):
    ItemStack sword = p.getInventory().getItemInMainHand();
    ItemMeta swordMeta = sword.getItemMeta();
    String swordName = swordMeta.getDisplayName();

    you could use a loop to get all the enchantments and such...
     
  14. I just realized that... my bad :/
     
  15. I will try the itemmeta, but the DisplayName, I already tried that several times before you posted it, and it just displayed it if you had made a custom name and if you hadn't it would be null. But lemme try the itemmeta, and ill brb.
     
  16. Hmm, if I wanted it do display if it was a diamond sword how would i make it display "Diamond Sword", just like normal. displayName doesn't work. itemstack#.getType() displays "DIAMOND_SWORD".. :p??
     
  17. Did you try getCustomName();
     

Share This Page