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: ?
Yo display items information in the chat you have to use packets or chat components https://www.spigotmc.org/wiki/the-chat-component-api/
And how can I show the name of the item? Because by the hover you can only show the lore, am I right?
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
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
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
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();
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
So I have to create an private void and there type this for example? Code (Text): PersistentDataHolder.getPersistentDataContainer();