-
Notifications
You must be signed in to change notification settings - Fork 0
BukkitTextComponentUtils
BukkitTextComponentUtils directly inherits from TextComponentUtils
all its functions and adds some only compatible with Bukkit.
Specifically, this utility class allows to use ItemStacks with TextComponents.
First thing first, it provides the getItemHoverEvent()
:
public static HoverEvent getItemHoverEvent(ItemStack itemStack) throws Exception;
This function returns an HoverEvent containing the ItemStack.
Basically, when the HoverEvent is called, it would be as if the player is looking directly at the itemstack itself.
Thanks to BearCommands, the real power of this function is its cross-compatibility among versions, from 1.8 all the way to the latest version.
If you are looking for a "complete package", maybe a TextComponent containing the name of the item, then there are two functions that come to the rescue:
public static String getItemName(ItemStack itemStack, boolean showAmount);
As the name suggests, getItemName()
returns the name of the given itemstack.
If showAmount
is set to true, then along with the name, the amount of items will be shown in the following format:
"&6%amount%x (&b if enchanted)&f%item-name%
But there is an even more convenient function that joins the previously seen methods:
public static TextComponent getItemComponent(ItemStack itemStack, boolean showAmount) throws Exception;
This function will return a TextComponent with the name of the item as message and the HoverEvent resulting from getItemHoverEvent()
.
- Home
- How to start a plugin
- Work with Configuration Files
- Work with Enums
- Work with Commands
- Work with Custom Players
- Work with Messaging Channels
- Creating custom SavableObjects
- Timers
- General Utils
- Placeholders
- Bukkit Utils
- Velocity Utils