Search in sources :

Example 21 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project Ublisk by Derkades.

the class StatsCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    UPlayer player = new UPlayer(sender);
    if (args.length == 1) {
        UPlayer target = null;
        try {
            target = new UPlayer(args[1]);
        } catch (PlayerNotFoundException e) {
            player.sendMessage(Message.PLAYER_NOT_FOUND);
            return true;
        }
        BaseComponent[] hoverText = new ComponentBuilder("yes click me pls").create();
        BaseComponent[] text = new ComponentBuilder("Click here to open " + target.getName() + "'s statistics page in your browser.").color(ChatColor.AQUA).bold(true).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)).event(new ClickEvent(ClickEvent.Action.OPEN_URL, target.getStatsURL())).create();
        player.sendMessage(text);
        return true;
    } else if (args.length == 0) {
        BaseComponent[] hoverText = new ComponentBuilder("yes click me pls").create();
        BaseComponent[] text = new ComponentBuilder("Click here to open your statistics page in your browser.").color(ChatColor.AQUA).bold(true).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)).event(new ClickEvent(ClickEvent.Action.OPEN_URL, player.getStatsURL())).create();
        player.sendMessage(text);
        return true;
    } else {
        return false;
    }
}
Also used : HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 22 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project Ublisk by Derkades.

the class TownCommand method onCommand.

@Override
protected void onCommand(UPlayer player, String[] args) {
    List<BaseComponent> list = new ArrayList<BaseComponent>();
    for (Town town : Town.values()) {
        TextComponent component = new TextComponent(town.getName() + "   ");
        double x = town.getSpawnLocation().getX();
        double y = town.getSpawnLocation().getY();
        double z = town.getSpawnLocation().getZ();
        component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tp @p " + x + " " + y + " " + z));
        list.add(component);
    }
    BaseComponent[] components = list.toArray(new BaseComponent[] {});
    player.sendMessage(components);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Town(xyz.derkades.ublisk.Town) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) ArrayList(java.util.ArrayList)

Example 23 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project LandLord by SpatiumPrinceps.

the class Claims method onClaims.

public void onClaims(Player player) {
    if (plugin.getConfig().getBoolean("Shop.enable")) {
        int claimcount = plugin.getPlayerManager().get(player.getUniqueId()).getClaims();
        int regionCount = plugin.getWgHandler().getWG().getRegionManager(player.getWorld()).getRegionCountOfPlayer(plugin.getWgHandler().getWG().wrapPlayer(player));
        String message = lm.getString("Commands.Claims.message");
        String noClaims = lm.getString("Commands.Claims.noClaims");
        if (claimcount > 0) {
            player.sendMessage(message.replace("%regions%", regionCount + "").replace("%claims%", claimcount + ""));
        } else {
            BaseComponent text = new TextComponent(noClaims);
            text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ll shop"));
            player.spigot().sendMessage(text);
        }
    } else {
        player.sendMessage(lm.getString("Commands.Claims.disabled"));
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent)

Example 24 with ClickEvent

use of net.md_5.bungee.api.chat.ClickEvent in project Minigames by AddstarMC.

the class MessageManager method sendClickedCommandMessage.

public static void sendClickedCommandMessage(CommandSender target, String command, String identifier, String key, Object... args) {
    BaseComponent init = getMessageStart(MinigameMessageType.INFO);
    TextComponent message = new TextComponent(getMessage(identifier, key, args));
    message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
    sendMessage(target, init, message);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent)

Example 25 with ClickEvent

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

the class FormattedTextHelper method stringify.

public static String stringify(BaseComponent component) {
    if (component == null) {
        return null;
    }
    StringBuilder builder = new StringBuilder(128);
    ChatColor color = component.getColorRaw();
    if (color != null) {
        builder.append(color);
    }
    if (boolNotNull(component.isBoldRaw())) {
        builder.append(ChatColor.BOLD);
    }
    if (boolNotNull(component.isItalicRaw())) {
        builder.append(ChatColor.ITALIC);
    }
    if (boolNotNull(component.isStrikethroughRaw())) {
        builder.append(ChatColor.STRIKETHROUGH);
    }
    if (boolNotNull(component.isUnderlinedRaw())) {
        builder.append(ChatColor.UNDERLINE);
    }
    if (boolNotNull(component.isObfuscatedRaw())) {
        builder.append(ChatColor.MAGIC);
    }
    if (component.getFontRaw() != null) {
        builder.append(ChatColor.COLOR_CHAR).append("[font=").append(component.getFontRaw()).append("]");
    }
    boolean hasInsertion = component.getInsertion() != null;
    if (hasInsertion) {
        builder.append(ChatColor.COLOR_CHAR).append("[insertion=").append(escape(component.getInsertion())).append("]");
    }
    boolean hasHover = component.getHoverEvent() != null;
    if (hasHover) {
        HoverEvent hover = component.getHoverEvent();
        builder.append(ChatColor.COLOR_CHAR).append("[hover=").append(hover.getAction().name()).append(";").append(escape(NMSHandler.getInstance().stringForHover(hover))).append("]");
    }
    boolean hasClick = component.getClickEvent() != null;
    if (hasClick) {
        ClickEvent click = component.getClickEvent();
        builder.append(ChatColor.COLOR_CHAR).append("[click=").append(click.getAction().name()).append(";").append(escape(click.getValue())).append("]");
    }
    if (component instanceof TextComponent) {
        builder.append(((TextComponent) component).getText());
    } else if (component instanceof TranslatableComponent) {
        builder.append(ChatColor.COLOR_CHAR).append("[translate=").append(escape(((TranslatableComponent) component).getTranslate()));
        List<BaseComponent> with = ((TranslatableComponent) component).getWith();
        if (with != null) {
            for (BaseComponent withComponent : with) {
                builder.append(";").append(escape(stringify(withComponent)));
            }
        }
        builder.append("]");
    } else if (component instanceof SelectorComponent) {
        builder.append(ChatColor.COLOR_CHAR).append("[selector=").append(escape(((SelectorComponent) component).getSelector())).append("]");
    } else if (component instanceof KeybindComponent) {
        builder.append(ChatColor.COLOR_CHAR).append("[keybind=").append(escape(((KeybindComponent) component).getKeybind())).append("]");
    } else if (component instanceof ScoreComponent) {
        builder.append(ChatColor.COLOR_CHAR).append("[score=").append(escape(((ScoreComponent) component).getName())).append(";").append(escape(((ScoreComponent) component).getObjective())).append(";").append(escape(((ScoreComponent) component).getValue())).append("]");
    }
    List<BaseComponent> after = component.getExtra();
    if (after != null) {
        for (BaseComponent afterComponent : after) {
            builder.append(stringify(afterComponent));
        }
    }
    if (hasClick) {
        builder.append(ChatColor.COLOR_CHAR + "[/click]");
    }
    if (hasHover) {
        builder.append(ChatColor.COLOR_CHAR + "[/hover]");
    }
    if (hasInsertion) {
        builder.append(ChatColor.COLOR_CHAR + "[/insertion]");
    }
    builder.append(RESET);
    String output = builder.toString();
    return cleanRedundantCodes(output);
}
Also used : List(java.util.List) ChatColor(net.md_5.bungee.api.ChatColor)

Aggregations

ClickEvent (net.md_5.bungee.api.chat.ClickEvent)30 TextComponent (net.md_5.bungee.api.chat.TextComponent)21 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)15 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)10 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)7 Player (org.bukkit.entity.Player)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 UPlayer (xyz.derkades.ublisk.utils.UPlayer)3 OwnedLand (biz.princeps.landlord.util.OwnedLand)2 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)2 ArrayList (java.util.ArrayList)2 ChatColor (net.md_5.bungee.api.ChatColor)2 Material (org.bukkit.Material)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 World (org.bukkit.World)2 Landlord (biz.princeps.landlord.Landlord)1 Options (biz.princeps.landlord.api.Options)1 LandPostClaimEvent (biz.princeps.landlord.api.events.LandPostClaimEvent)1