Search in sources :

Example 1 with Component

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

the class ActionMessage method getMainMessage.

private TextComponent getMainMessage(ActionType action, String format1) {
    final TextColor highlight = NamedTextColor.DARK_AQUA;
    TextComponent out = Component.text().content(format1).build();
    Component result = out.replaceFirstText(Pattern.compile("<prefix>"), builder -> getPosNegPrefix()).replaceFirstText(Pattern.compile("<index>"), builder -> builder.content("[" + index + "] ").color(NamedTextColor.GRAY)).replaceFirstText(Pattern.compile("<target>"), builder -> Component.text().content(handler.getSourceName()).color(highlight)).replaceFirstText(Pattern.compile("<description>"), builder -> Component.text().content(getDescription((ActionTypeImpl) action)).color(NamedTextColor.WHITE)).replaceFirstText(Pattern.compile("<actorNice>"), builder -> getActor((ActionTypeImpl) action, highlight)).replaceFirstText(Pattern.compile("<actor>"), builder -> Component.text().content(action.getName())).replaceFirstText(Pattern.compile("<extendedInfo>"), builder -> Component.text().append(getExtendedInfo())).replaceFirstText(Pattern.compile("<timeDiff>"), builder -> Component.text().append(getTimeDiff())).replaceFirstText(Pattern.compile("<count>"), builder -> Component.text().append(getCount())).replaceFirstText(Pattern.compile("<actionType>"), builder -> Component.text().content("(a:" + action.getShortName() + ")").color(NamedTextColor.GRAY)).replaceFirstText(Pattern.compile("<handlerId>"), builder -> Component.text(handler.getId()).toBuilder().color(NamedTextColor.GRAY));
    return Component.text().content("").append(result).hoverEvent(HoverEvent.showText(Component.text("Click to teleport").color(NamedTextColor.DARK_AQUA))).clickEvent(ClickEvent.runCommand("/pr tp " + index)).build();
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) TextComponent(net.kyori.adventure.text.TextComponent) TextColor(net.kyori.adventure.text.format.TextColor) Handler(me.botsko.prism.api.actions.Handler) ClickEvent(net.kyori.adventure.text.event.ClickEvent) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) ActionType(me.botsko.prism.api.actions.ActionType) Utilities(me.botsko.prism.utils.block.Utilities) Location(org.bukkit.Location) Component(net.kyori.adventure.text.Component) Pattern(java.util.regex.Pattern) HoverEvent(net.kyori.adventure.text.event.HoverEvent) PlainComponentSerializer(net.kyori.adventure.text.serializer.plain.PlainComponentSerializer) Material(org.bukkit.Material) TextColor(net.kyori.adventure.text.format.TextColor) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component)

Example 2 with Component

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

the class ActionMessage method getMessage.

/**
 * Get the message.
 *
 * @return String[]
 */
public TextComponent getMessage() {
    String format1 = "<prefix> <index> <target> <description> <actorNice> <extendedInfo><count> <timeDiff> <actionType>";
    String format2 = "-<handlerId>- <dateTime> - <location>";
    ActionType action = handler.getActionType();
    TextComponent out = getMainMessage(action, format1);
    if (showExtended) {
        out = out.append(Component.newline());
        Component line2 = Component.text().content(format2).build().replaceFirstText(Pattern.compile("<handlerId>"), builder -> Component.text(handler.getId()).toBuilder().color(NamedTextColor.GRAY)).replaceFirstText(Pattern.compile("<dateTime>"), builder -> Component.text().content(handler.getDisplayDate() + " " + handler.getDisplayTime())).replaceFirstText(Pattern.compile("<location>"), builder -> Component.text().content(getFormattedLocation()));
        out = out.append(line2);
    }
    return out;
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) TextComponent(net.kyori.adventure.text.TextComponent) TextColor(net.kyori.adventure.text.format.TextColor) Handler(me.botsko.prism.api.actions.Handler) ClickEvent(net.kyori.adventure.text.event.ClickEvent) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) ActionType(me.botsko.prism.api.actions.ActionType) Utilities(me.botsko.prism.utils.block.Utilities) Location(org.bukkit.Location) Component(net.kyori.adventure.text.Component) Pattern(java.util.regex.Pattern) HoverEvent(net.kyori.adventure.text.event.HoverEvent) PlainComponentSerializer(net.kyori.adventure.text.serializer.plain.PlainComponentSerializer) Material(org.bukkit.Material) ActionType(me.botsko.prism.api.actions.ActionType) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component)

Example 3 with Component

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

the class DrainCommand method handle.

@Override
public void handle(CallInfo call) {
    String drainType = "";
    int radius = plugin.getConfig().getInt("prism.drain.default-radius");
    if (call.getArgs().length == 3) {
        if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
            drainType = call.getArg(1);
        } else {
            Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
            return;
        }
        // Validate radius
        radius = validateRadius(call, call.getArg(2));
    } else if (call.getArgs().length == 2) {
        if (TypeUtils.isNumeric(call.getArg(1))) {
            radius = validateRadius(call, call.getArg(1));
        } else {
            if (call.getArg(1).equalsIgnoreCase("water") || call.getArg(1).equalsIgnoreCase("lava")) {
                drainType = call.getArg(1);
            } else {
                Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError("Invalid drain type. Must be lava, water, or left out."));
                return;
            }
        }
    }
    if (radius == 0) {
        return;
    }
    TextComponent.Builder builder = Component.text().append(Il8nHelper.formatMessage("command-drain-lookup", drainType, radius));
    String key = "command-drain-lookup-water";
    if (drainType.equals("lava")) {
        key = "command-drain-lookup-lava";
    }
    builder.append(Component.text(" ")).append(Il8nHelper.getMessage(key).color(NamedTextColor.GRAY));
    Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerHeaderMsg(builder.build()));
    ArrayList<BlockStateChange> blockStateChanges = null;
    if (drainType.isEmpty()) {
        blockStateChanges = Utilities.drain(call.getPlayer().getLocation(), radius);
    } else if (drainType.equals("water")) {
        blockStateChanges = Utilities.drainWater(call.getPlayer().getLocation(), radius);
    } else if (drainType.equals("lava")) {
        blockStateChanges = Utilities.drainLava(call.getPlayer().getLocation(), radius);
    }
    if (blockStateChanges != null && !blockStateChanges.isEmpty()) {
        // @todo remove the extra space in msg
        Component out = Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("command-drain-lookup-result", blockStateChanges.size(), drainType)).append(Component.newline()).append(Prism.messenger.playerSubduedHeaderMsg(Il8nHelper.getMessage("command-drain-result-undo")));
        Prism.messenger.sendMessage(call.getSender(), out);
        // Trigger the event
        final PrismDrainEvent event = EventHelper.createDrainEvent(blockStateChanges, call.getPlayer(), radius);
        plugin.getServer().getPluginManager().callEvent(event);
    } else {
        Prism.messenger.sendMessage(call.getPlayer(), Prism.messenger.playerError(Il8nHelper.getMessage("command-drain-result-empty")));
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) BlockStateChange(me.botsko.prism.api.BlockStateChange) PrismDrainEvent(me.botsko.prism.events.PrismDrainEvent) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component)

Example 4 with Component

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

the class LookupCommand method handle.

/**
 * Handle the command.
 */
@Override
public void handle(final CallInfo call) {
    // Process and validate all of the arguments
    final QueryParameters parameters = PreprocessArgs.process(plugin, call.getSender(), call.getArgs(), PrismProcessType.LOOKUP, 1, !plugin.getConfig().getBoolean("prism.queries.never-use-defaults"));
    if (parameters == null) {
        return;
    }
    // Run the lookup itself in an async task so the lookup query isn't done on the main thread
    plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
        // determine if defaults were used
        final List<String> defaultsUsed = parameters.getDefaultsUsed();
        StringBuilder defaultsReminder = new StringBuilder();
        if (!defaultsUsed.isEmpty()) {
            defaultsReminder.append(Il8nHelper.getRawMessage("queryparameter.defaults.prefix"));
            for (final String d : defaultsUsed) {
                defaultsReminder.append(" ").append(d);
            }
        }
        final ActionsQuery aq = new ActionsQuery(plugin);
        final QueryResult results = aq.lookup(parameters, call.getSender());
        final StringBuilder sharingWithPlayers = new StringBuilder();
        for (final CommandSender shareWith : parameters.getSharedPlayers()) {
            sharingWithPlayers.append(shareWith.getName()).append(", ");
        }
        if (sharingWithPlayers.length() > 0) {
            sharingWithPlayers.delete(sharingWithPlayers.lastIndexOf(","), sharingWithPlayers.length());
        }
        final String playersList = sharingWithPlayers.toString();
        // Add current sender
        parameters.addSharedPlayer(call.getSender());
        for (final CommandSender player : parameters.getSharedPlayers()) {
            final boolean isSender = player.getName().equals(call.getSender().getName());
            if (!isSender) {
                Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.getMessage("lookup-share-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<sender>"), builder -> Component.text().content(call.getSender().getName()).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1)));
            } else if (sharingWithPlayers.length() > 0) {
                Component component = Il8nHelper.getMessage("lookup-share-to-message").color(NamedTextColor.GOLD).replaceText(Pattern.compile("<players>"), builder -> Component.text().content(playersList).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, TextDecoration.State.TRUE), 1);
                Prism.messenger.sendMessage(call.getSender(), Prism.messenger.playerHeaderMsg(component));
            }
            if (!results.getActionResults().isEmpty()) {
                Prism.messenger.sendMessage(player, Prism.messenger.playerHeaderMsg(Il8nHelper.formatMessage("lookup-header-message", results.getTotalResults(), 1, results.getTotalPages())));
                if ((defaultsReminder.length() > 0) && isSender) {
                    Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
                }
                final List<Handler> paginated = results.getPaginatedActionResults();
                if (paginated != null) {
                    int resultCount = results.getIndexOfFirstResult();
                    for (final Handler a : paginated) {
                        final ActionMessage am = new ActionMessage(a);
                        if (parameters.hasFlag(Flag.EXTENDED) || plugin.getConfig().getBoolean("prism.messenger.always-show-extended")) {
                            am.showExtended();
                        }
                        am.setResultIndex(resultCount);
                        MiscUtils.sendClickableTpRecord(am, player);
                        resultCount++;
                    }
                    MiscUtils.sendPageButtons(results, player);
                } else {
                    Prism.messenger.sendMessage(player, Prism.messenger.playerError(Il8nHelper.getMessage("no-pagination-found")));
                }
                if (parameters.hasFlag(Flag.PASTE)) {
                    StringBuilder paste = new StringBuilder();
                    for (final Handler a : results.getActionResults()) {
                        paste.append(new ActionMessage(a).getRawMessage()).append("\r\n");
                    }
                    MiscUtils.paste_results(player, paste.toString());
                }
            } else {
                if (defaultsReminder.length() > 0) {
                    if (isSender) {
                        Prism.messenger.sendMessage(player, Prism.messenger.playerSubduedHeaderMsg(Component.text(defaultsReminder.toString())));
                    }
                }
                if (isSender) {
                    Prism.messenger.sendMessage(player, Prism.messenger.playerError("Nothing found." + ChatColor.GRAY + " Either you're missing something, or we are."));
                }
            }
        }
        // Flush timed data
        plugin.eventTimer.printTimeRecord();
    });
}
Also used : Prism(me.botsko.prism.Prism) CommandSender(org.bukkit.command.CommandSender) CallInfo(me.botsko.prism.commandlibs.CallInfo) PreprocessArgs(me.botsko.prism.commandlibs.PreprocessArgs) TextDecoration(net.kyori.adventure.text.format.TextDecoration) Handler(me.botsko.prism.api.actions.Handler) QueryResult(me.botsko.prism.actionlibs.QueryResult) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) List(java.util.List) SubHandler(me.botsko.prism.commandlibs.SubHandler) Flag(me.botsko.prism.api.commands.Flag) MiscUtils(me.botsko.prism.utils.MiscUtils) Component(net.kyori.adventure.text.Component) Il8nHelper(me.botsko.prism.Il8nHelper) PrismProcessType(me.botsko.prism.api.actions.PrismProcessType) ChatColor(org.bukkit.ChatColor) Pattern(java.util.regex.Pattern) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) Handler(me.botsko.prism.api.actions.Handler) SubHandler(me.botsko.prism.commandlibs.SubHandler) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) QueryResult(me.botsko.prism.actionlibs.QueryResult) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ActionMessage(me.botsko.prism.actionlibs.ActionMessage) CommandSender(org.bukkit.command.CommandSender) Component(net.kyori.adventure.text.Component)

Example 5 with Component

use of net.kyori.adventure.text.Component in project Denizen-For-Bukkit by DenizenScript.

the class PaperAdvancedTextImpl method getSignLines.

@Override
public String[] getSignLines(Sign sign) {
    String[] output = new String[4];
    int i = 0;
    for (Component component : sign.lines()) {
        output[i++] = PaperModule.stringifyComponent(component, ChatColor.BLACK);
    }
    return output;
}
Also used : Component(net.kyori.adventure.text.Component)

Aggregations

Component (net.kyori.adventure.text.Component)5 Pattern (java.util.regex.Pattern)3 Handler (me.botsko.prism.api.actions.Handler)3 TextComponent (net.kyori.adventure.text.TextComponent)3 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)3 ActionType (me.botsko.prism.api.actions.ActionType)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 Material (org.bukkit.Material)2 List (java.util.List)1 Il8nHelper (me.botsko.prism.Il8nHelper)1 Prism (me.botsko.prism.Prism)1 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)1 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)1 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)1 QueryResult (me.botsko.prism.actionlibs.QueryResult)1