Search in sources :

Example 6 with TextComponent

use of net.kyori.adventure.text.TextComponent in project Prism-Bukkit by prism.

the class WandCommand method sendWandStatus.

static void sendWandStatus(final CommandSender sender, @PropertyKey(resourceBundle = "languages.message") String wandStatusMessageKey, final boolean status, final String wandType, final String parameters) {
    final TextComponent state;
    if (status) {
        state = Il8nHelper.getMessage("enabled").color(NamedTextColor.GREEN);
    } else {
        state = Il8nHelper.getMessage("disabled").color(NamedTextColor.RED);
    }
    TextComponent out = Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage(wandStatusMessageKey).replaceText(Pattern.compile("<status>"), builder -> Component.text().append(state)));
    if (status) {
        out.append(Component.newline()).append(Il8nHelper.getMessage("wand-item-type").replaceText(Pattern.compile("<itemType>"), builder -> Component.text().content(wandType)).replaceText(Pattern.compile("<parameters"), builder -> Component.text().content(parameters)));
    }
    Prism.messenger.sendMessage(sender, out);
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) Prism(me.botsko.prism.Prism) TextComponent(net.kyori.adventure.text.TextComponent) CommandSender(org.bukkit.command.CommandSender) Settings(me.botsko.prism.settings.Settings) CallInfo(me.botsko.prism.commandlibs.CallInfo) RestoreWand(me.botsko.prism.wands.RestoreWand) RollbackWand(me.botsko.prism.wands.RollbackWand) QueryWandBase(me.botsko.prism.wands.QueryWandBase) Wand(me.botsko.prism.wands.Wand) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) ItemStack(org.bukkit.inventory.ItemStack) Objects(java.util.Objects) InventoryUtils(me.botsko.prism.utils.InventoryUtils) ProfileWand(me.botsko.prism.wands.ProfileWand) List(java.util.List) ItemUtils(me.botsko.prism.utils.ItemUtils) Component(net.kyori.adventure.text.Component) Il8nHelper(me.botsko.prism.Il8nHelper) InspectorWand(me.botsko.prism.wands.InspectorWand) PlayerInventory(org.bukkit.inventory.PlayerInventory) PropertyKey(org.jetbrains.annotations.PropertyKey) Pattern(java.util.regex.Pattern) Material(org.bukkit.Material)

Example 7 with TextComponent

use of net.kyori.adventure.text.TextComponent in project Prism-Bukkit by prism.

the class HelpCommand method help.

/**
 * Displays help.
 *
 * @param s CommandSender
 */
protected void help(CommandSender s) {
    Audience sender = Prism.getAudiences().sender(s);
    if (failed) {
        sender.sendMessage(Identity.nil(), Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("prism-disabled-header").color(NamedTextColor.GOLD)).append(Component.newline()).append(Prism.messenger.playerMsg(Il8nHelper.getMessage("prism-disabled-content")).color(NamedTextColor.GOLD)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("discord", ":").color(NamedTextColor.WHITE).append(Component.text(Il8nHelper.getRawMessage("discord-url"))))).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("wiki", ":").color(NamedTextColor.WHITE).append(Component.text(Il8nHelper.getRawMessage("wiki-url"))))));
        return;
    }
    TextComponent component = Prism.messenger.playerHeaderMsg(Component.text("--- Basic Usage ---").color(NamedTextColor.GOLD)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("help-extended-message"))).append(Component.newline());
    Stream<SubCommand> stream = Prism.getInstance().getCommands().getSubCommands().values().stream().distinct();
    for (SubCommand command : stream.collect(Collectors.toList())) {
        if (command.getHelp().length > 1) {
            int i = 0;
            for (String message : command.getHelp()) {
                if (i == 0) {
                    component = component.append(Prism.messenger.playerHelp(Arrays.toString(command.getAliases()), message).clickEvent(ClickEvent.openUrl(command.getWebLink()))).append(Component.newline());
                } else {
                    component = component.append(Prism.messenger.playerHelp("      |- ", message).clickEvent(ClickEvent.openUrl(command.getWebLink()))).append(Component.newline());
                }
                i++;
            }
        } else {
            component = component.append(Prism.messenger.playerHelp(Arrays.toString(command.getAliases()), command.getHelp()[0]).clickEvent(ClickEvent.openUrl(command.getWebLink()))).append(Component.newline());
        }
    }
    sender.sendMessage(Identity.nil(), component);
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) SubCommand(me.botsko.prism.commandlibs.SubCommand) Audience(net.kyori.adventure.audience.Audience)

Example 8 with TextComponent

use of net.kyori.adventure.text.TextComponent in project Prism-Bukkit by prism.

the class UseMonitor method incrementCount.

/**
 * Maintain use alert message history.
 * Increments the number of times the player has caused a particular alert.
 * If the count is below the threshold, the alert will be sent.
 *
 * @param playername Player causing the alert
 * @param msg        Alert message
 * @param alertPerm  Players with this permission will receive the alert
 */
protected void incrementCount(String playername, String msg, String alertPerm) {
    int count = 0;
    String key = playername + msg;
    if (countedEvents.containsKey(key)) {
        count = countedEvents.get(key);
    }
    count++;
    countedEvents.put(key, count);
    TextComponent out = Component.text(playername + " " + msg).color(NamedTextColor.GRAY);
    if (count == 5) {
        out = out.append(Component.text(" - pausing warnings.").color(NamedTextColor.GRAY));
    }
    if (count <= 5) {
        // Alert staff
        plugin.alertPlayers(null, out, alertPerm);
        // Log to console
        if (plugin.getConfig().getBoolean("prism.alerts.uses.log-to-console")) {
            Prism.log(PlainComponentSerializer.plain().serialize(out));
        }
        // Log to commands
        List<String> commands = plugin.getConfig().getStringList("prism.alerts.uses.log-commands");
        MiscUtils.dispatchAlert(msg, commands);
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent)

Aggregations

TextComponent (net.kyori.adventure.text.TextComponent)8 Pattern (java.util.regex.Pattern)3 Component (net.kyori.adventure.text.Component)3 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)3 Material (org.bukkit.Material)3 ActionType (me.botsko.prism.api.actions.ActionType)2 Handler (me.botsko.prism.api.actions.Handler)2 Utilities (me.botsko.prism.utils.block.Utilities)2 ClickEvent (net.kyori.adventure.text.event.ClickEvent)2 HoverEvent (net.kyori.adventure.text.event.HoverEvent)2 TextColor (net.kyori.adventure.text.format.TextColor)2 PlainComponentSerializer (net.kyori.adventure.text.serializer.plain.PlainComponentSerializer)2 Location (org.bukkit.Location)2 Player (org.bukkit.entity.Player)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Il8nHelper (me.botsko.prism.Il8nHelper)1 Prism (me.botsko.prism.Prism)1 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)1