Search in sources :

Example 1 with Content

use of net.md_5.bungee.api.chat.hover.content.Content in project Denizen-For-Bukkit by DenizenScript.

the class HoverFormatHelper method processHoverInput.

public static boolean processHoverInput(HoverEvent.Action action, TextComponent hoverableText, String input) {
    Content content;
    if (action == HoverEvent.Action.SHOW_ITEM) {
        ItemTag item = ItemTag.valueOf(FormattedTextHelper.unescape(input), CoreUtilities.noDebugContext);
        if (item == null) {
            return true;
        }
        // TODO: Why is there not a direct conversion method for Spigot ItemStack -> BungeeChat Item?
        String itemNbt = NMSHandler.getItemHelper().getRawHoverText(item.getItemStack());
        content = new Item(item.getBukkitMaterial().getKey().toString(), item.getAmount(), net.md_5.bungee.api.chat.ItemTag.ofNbt(itemNbt));
    } else if (action == HoverEvent.Action.SHOW_ENTITY) {
        EntityTag entity = EntityTag.valueOf(FormattedTextHelper.unescape(input), CoreUtilities.basicContext);
        if (entity == null) {
            return true;
        }
        BaseComponent name = null;
        if (entity.getBukkitEntity() != null && entity.getBukkitEntity().isCustomNameVisible()) {
            name = new TextComponent();
            for (BaseComponent component : FormattedTextHelper.parse(entity.getBukkitEntity().getCustomName(), ChatColor.WHITE)) {
                name.addExtra(component);
            }
        }
        content = new Entity(entity.getBukkitEntityType().getKey().toString(), entity.getUUID().toString(), name);
    } else {
        content = new Text(FormattedTextHelper.parse(FormattedTextHelper.unescape(input), ChatColor.WHITE));
    }
    hoverableText.setHoverEvent(new HoverEvent(action, content));
    return false;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Item(net.md_5.bungee.api.chat.hover.content.Item) Entity(net.md_5.bungee.api.chat.hover.content.Entity) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Content(net.md_5.bungee.api.chat.hover.content.Content) EntityTag(com.denizenscript.denizen.objects.EntityTag) Text(net.md_5.bungee.api.chat.hover.content.Text) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)1 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 Content (net.md_5.bungee.api.chat.hover.content.Content)1 Entity (net.md_5.bungee.api.chat.hover.content.Entity)1 Item (net.md_5.bungee.api.chat.hover.content.Item)1 Text (net.md_5.bungee.api.chat.hover.content.Text)1