1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Item to chat

Discussion in 'Snippets' started by Waltz, Jan 15, 2019.

  1. Waltz

    Waltz Member

    Joined:
    Feb 18, 2017
    Messages:
    3
    Likes Received:
    3
    It took me a while to figure out (especially JSON, jesus), so I figured I should post it somewhere so people don't have to break their heads with JSON syntax.

    You could make it so it replaces some placeholders in chat with it or something:

    Code (Skript):
    1. import:
    2.     net.md_5.bungee.api.chat.BaseComponent
    3.     net.md_5.bungee.api.chat.TextComponent
    4.     net.md_5.bungee.api.chat.TranslatableComponent
    5.     org.bukkit.Material
    6.    
    7. on rightclick:
    8.     if name of tool of player is not set:
    9.         set {_material} to Material.matchMaterial("%vanilla name of tool of player%") #get raw material from item
    10.         set {_rawName} to "%vanilla name of tool of player%"
    11.         replace every ":" in {_rawName} with "."
    12.         if {_material}.isBlock() is true: #if item is block, add "block." prefix, otherwise - "item."
    13.             set {_rawName} to "block.%{_rawName}%"
    14.         else:
    15.             set {_rawName} to "item.%{_rawName}%"
    16. #translatable name would look like this: "block.minecraft.stone"
    17.            
    18.         set {_c} to a new text component "<dark gray>[<reset>"
    19.         {_c}.addExtra(new TranslatableComponent({_rawName})) #adding translatabe component to text component of Skellett
    20.         {_c}.addExtra(new TextComponent(" <gray>x%number of tool of player%<dark gray>]"))
    21.     else: #if item has custom name
    22.         set {_c} to a new text component "<dark gray>[<reset>%name of tool of player% <gray>x%number of tool of player%<dark gray>]<reset>"
    23.  
    24.     if item-nbt of tool of player is set: #if item has any nbt data, requires NBeeT
    25.         add hover event with action SHOW_ITEM with text "{""id"":""%vanilla name of tool of player%"",""Count"":1,""tag"":%item-nbt of tool of player%}" to text component {_c}
    26.     else: #if no nbt data
    27.         add hover event with action SHOW_ITEM with text "{""id"":""%vanilla name of tool of player%"",""Count"":1}" to text component {_c}
    28.  
    29.     message text components {_c} to player
    Requires Skellett and skript-mirror

    Works on 1.13.2, probably needs tweaks for previous versions
     
    Diclo likes this.

Share This Page

Loading...