|
| 1 | +package org.skriptlang.skript.bukkit.text.elements.expressions; |
| 2 | + |
| 3 | +import ch.njol.skript.doc.Description; |
| 4 | +import ch.njol.skript.doc.Example; |
| 5 | +import ch.njol.skript.doc.Name; |
| 6 | +import ch.njol.skript.doc.Since; |
| 7 | +import ch.njol.skript.expressions.base.SimplePropertyExpression; |
| 8 | +import net.kyori.adventure.text.Component; |
| 9 | +import org.bukkit.inventory.ItemStack; |
| 10 | +import org.skriptlang.skript.bukkit.text.TextComponentParser; |
| 11 | +import org.skriptlang.skript.registration.SyntaxRegistry; |
| 12 | + |
| 13 | +@Name("Show Item Hover Text") |
| 14 | +@Description(""" |
| 15 | + Creates a '<hover:show_item:...>' string from an item stack, which can be used to show the item's hover text in chat. |
| 16 | + """) |
| 17 | +@Example(""" |
| 18 | + on right click on a chest: |
| 19 | + send "Contents:" |
| 20 | + loop items in inventory of event-block: |
| 21 | + send formatted " - %item hover text of loop-item%%loop-item%" |
| 22 | + """) |
| 23 | +@Since("INSERT VERSION") |
| 24 | +public class ExprItemHoverText extends SimplePropertyExpression<ItemStack, String> { |
| 25 | + |
| 26 | + public static void register(SyntaxRegistry registry) { |
| 27 | + registry.register(SyntaxRegistry.EXPRESSION, |
| 28 | + infoBuilder(ExprItemHoverText.class, String.class, "[show] item hover text", "itemstacks", false) |
| 29 | + .supplier(ExprItemHoverText::new) |
| 30 | + .build()); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public String convert(ItemStack from) { |
| 35 | + Component dummy = Component.empty().hoverEvent(from.asHoverEvent()); |
| 36 | + return TextComponentParser.instance().toString(dummy); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public Class<? extends String> getReturnType() { |
| 41 | + return String.class; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + protected String getPropertyName() { |
| 46 | + return "item hover text"; |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments