Search in sources :

Example 71 with TextComponent

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

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

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

the class MessageManager method sendMessage.

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

Example 74 with TextComponent

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

the class MessageManager method broadcast.

/**
 * Broadcasts a server message without a permission.
 *
 * @param message     - The message to be broadcasted (Can be manipulated with MinigamesBroadcastEvent)
 * @param minigame    - The Minigame this broadcast is related to.
 * @param prefixColor - The color to be used in the prefix.
 */
public static void broadcast(String message, Minigame minigame, org.bukkit.ChatColor prefixColor) {
    BaseComponent init = new TextComponent("[Minigames]");
    init.setColor(prefixColor.asBungee());
    TextComponent m = new TextComponent(" " + message);
    MinigamesBroadcastEvent ev = new MinigamesBroadcastEvent(prefixColor + "[Minigames]" + org.bukkit.ChatColor.WHITE, message, minigame);
    Bukkit.getPluginManager().callEvent(ev);
    // Only send broadcast if event was not cancelled and is not empty
    if (!ev.isCancelled() && !ev.getMessage().isEmpty()) {
        if (PaperLib.isPaper()) {
            Bukkit.getServer().broadcast(init, m);
        } else {
            Bukkit.getServer().spigot().broadcast(init, m);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) MinigamesBroadcastEvent(au.com.mineauz.minigames.events.MinigamesBroadcastEvent)

Example 75 with TextComponent

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

TextComponent (net.md_5.bungee.api.chat.TextComponent)78 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)21 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)15 Player (org.bukkit.entity.Player)14 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)12 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)12 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)12 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)11 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)6 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)6 Configuration (net.md_5.bungee.config.Configuration)6 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)6 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)5 ChatColor (net.md_5.bungee.api.ChatColor)5 ItemStack (org.bukkit.inventory.ItemStack)5 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)4 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)4 DecimalFormat (java.text.DecimalFormat)4 HashMap (java.util.HashMap)4