Solved Chat Item Replacement

Discussion in 'Spigot Plugin Development' started by Richard37, Feb 2, 2020.

  1. Hi,
    I am making plugin that replaces placeholders to emojis and I want to create that if someone types :item: it will change to an item that the person that executed the command holds in his hand. So far I have this:
    Code (Java):
    public class ItemReplacement implements Listener {
        @EventHandler
        public void onItemSend(AsyncPlayerChatEvent e){
            String newMessage = e.getMessage().replace(":item:" ,  );
        }
    }
     
    Does anyone know what to add to the replacement section after :item: ?
     
  2. Btw, you solved your first thread, which also had this, and created a new one? Bit odd...
     
    • Funny Funny x 1
  3. And how can I show the name of the item?
    Because by the hover you can only show the lore, am I right?
     
    • Funny Funny x 1
  4. But there is only the hover and click event
     
  5. Use the hover event to display the item
    If you just want to display the item name/type get the player, get the inventory, get the item in main hand and use repalceAll
     
  6. Replace all is for regular expressions, you should use replace
     
  7. Nevermind I deleted this project cause it is too hard for me XDDD
     
  8. Don't give up just because you think it's hard, you got the answer so just look at the link provided and just play around with it. Good way to learn the SpigotAPI is just playing around with it and also looking at the Javadocs https://hub.spigotmc.org/javadocs/spigot/overview-summary.html
     
  9. Okay I will try...
     
  10. But I asked some friends on Discord and they said that I need to get meta of the item etc. and I dont even know what that is
     
    • Like Like x 1
  11. Thank you but why do I need that and how?
     
  12. You take the object (here "item"), you get its item meta and thanks to that you have the possibility to have the name of the object in question like this:
    Code (Text):
    ItemMeta meta = item.getItemMeta();
    String item_name = meta.getDisplayName();
     
    • Like Like x 1
  13. You can get all this info from an ItemStack from it's Meta
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/ItemMeta.html

    To use it simply get your ItemStack, in this case the ItemStack the player has in their main hand.

    Check if it has ItemMeta
    Code (Text):
    <ItemStack>#hasItemMeta();
    Then you can do
    Code (Text):
    ItemMeta meta = <ItemStack>#getItemMeta();
    Now you can check if it has a Display name, Lore, Enchantments etc
     
    • Like Like x 1
  14. Thank you very much.
     
    • Like Like x 1
  15. So I have to create an private void and there type this for example?
    Code (Text):
    PersistentDataHolder.getPersistentDataContainer();
     
  16. Also what do you mean by the "#" because when I use it, it says illegal character.
     
    #20 Richard37, Feb 2, 2020
    Last edited: Feb 2, 2020