Search in sources :

Example 11 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent 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 12 with BaseComponent

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

the class Chat method onChat.

@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncPlayerChatEvent event) {
    // Don't send chat message, we'll send a custom message
    event.setCancelled(true);
    UPlayer player = new UPlayer(event);
    if (Chat.IS_MUTED.get(player.getUniqueId())) {
        player.sendMessage(Message.CANT_CHAT_MUTED);
        event.setCancelled(true);
        return;
    }
    for (Trigger trigger : Trigger.values()) {
        if (event.getMessage().equals(trigger.getTrigger())) {
            event.setMessage(trigger.getMessage());
        }
    }
    ChatColor chatColor = ChatColor.WHITE;
    if (IS_SOFT_MUTED.get(player.getUniqueId()))
        chatColor = ChatColor.GRAY;
    int level = player.getLevel();
    BaseComponent[] message = new ComponentBuilder("").append("[").reset().color(ChatColor.DARK_GRAY).append(level + "").reset().color(ChatColor.GRAY).append("] ").reset().color(ChatColor.DARK_GRAY).append(player.getGroup().getName()).color(player.getGroup().getPrefixColor()).bold(player.getGroup().nameBold()).append(":").reset().color(ChatColor.DARK_GRAY).append(" ").create();
    message = ArrayUtils.addAll(message, player.getDisplayName(player.getGroup().getNameColor(), player.getGroup().nameBold()));
    message = ArrayUtils.addAll(message, new ComponentBuilder("").append(": ").reset().color(ChatColor.DARK_GRAY).bold(true).append(event.getMessage()).reset().color(chatColor).create());
    Ublisk.getServer().spigot().broadcast(message);
}
Also used : BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Trigger(xyz.derkades.ublisk.chat.Trigger) ChatColor(net.md_5.bungee.api.ChatColor) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Example 13 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent 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 14 with BaseComponent

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

the class V1_12_R1 method sendActionBarMessage.

@Override
public void sendActionBarMessage(Player player, String message) {
    IChatBaseComponent dummyComponent = ChatSerializer.a("{\"text\":\"herobrine1337\"}");
    PacketPlayOutChat packet = new PacketPlayOutChat(dummyComponent, ChatMessageType.GAME_INFO);
    packet.components = new BaseComponent[] { new TextComponent(message) };
    CraftPlayer craftPlayer = (CraftPlayer) player;
    craftPlayer.getHandle().playerConnection.sendPacket(packet);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) PacketPlayOutChat(net.minecraft.server.v1_12_R1.PacketPlayOutChat) IChatBaseComponent(net.minecraft.server.v1_12_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)

Example 15 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent 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)

Aggregations

BaseComponent (net.md_5.bungee.api.chat.BaseComponent)23 TextComponent (net.md_5.bungee.api.chat.TextComponent)8 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)7 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)6 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)5 Player (org.bukkit.entity.Player)4 BookMeta (org.bukkit.inventory.meta.BookMeta)4 UPlayer (xyz.derkades.ublisk.utils.UPlayer)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)3 ListTag (com.denizenscript.denizencore.objects.core.ListTag)3 ChatColor (net.md_5.bungee.api.ChatColor)3 MapTag (com.denizenscript.denizencore.objects.core.MapTag)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ListTag (net.minecraft.nbt.ListTag)2 EventHandler (org.bukkit.event.EventHandler)2 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)2 MinigamesBroadcastEvent (au.com.mineauz.minigames.events.MinigamesBroadcastEvent)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1