Search in sources :

Example 1 with TextComponent

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

the class Prism method alertPlayers.

/**
 * Send an alert to players.
 *
 * @param player    Player which caused the alert
 * @param msg       Alert message
 * @param alertPerm Players with this permission (or prism.alerts) will receive the alert
 */
public void alertPlayers(Player player, Component msg, String alertPerm) {
    for (final Player p : getServer().getOnlinePlayers()) {
        if ((!p.equals(player) || getConfig().getBoolean("prism.alerts.alert-player-about-self")) && (p.hasPermission("prism.alerts") || (alertPerm != null && p.hasPermission(alertPerm)))) {
            TextComponent prefix = Il8nHelper.getMessage("alert-prefix").color(NamedTextColor.RED).append(msg);
            audiences.player(p).sendMessage(Identity.nil(), prefix);
        }
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) Player(org.bukkit.entity.Player) PrismPlayer(me.botsko.prism.players.PrismPlayer)

Example 2 with TextComponent

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

the class PrismPlayerEvents method onCommandPreprocess.

/**
 * Log command use.
 *
 * @param event PlayerCommandPreprocessEvent
 */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCommandPreprocess(PlayerCommandPreprocessEvent event) {
    final Player player = event.getPlayer();
    final String cmd = event.getMessage().toLowerCase();
    final String[] cmdArgs = cmd.split(" ");
    final String primaryCmd = cmdArgs[0].substring(1);
    if (plugin.getConfig().getBoolean("prism.alerts.illegal-commands.enabled")) {
        if (illegalCommands.contains(primaryCmd)) {
            final String msg = player.getName() + " attempted an illegal command: " + primaryCmd + ". Originally: " + cmd;
            TextComponent send = Component.text(msg);
            Prism.messenger.sendMessage(player, Prism.messenger.playerError("Sorry, this command is not available in-game."));
            plugin.alertPlayers(null, send, null);
            event.setCancelled(true);
            // Log to console
            if (plugin.getConfig().getBoolean("prism.alerts.illegal-commands.log-to-console")) {
                Prism.log(msg);
            }
            // Log to commands
            List<String> commands = plugin.getConfig().getStringList("prism.alerts.illegal-commands.log-commands");
            MiscUtils.dispatchAlert(msg, commands);
        }
    }
    if (!Prism.getIgnore().event("player-command", player)) {
        return;
    }
    // Ignore some commands based on config
    if (ignoreCommands.contains(primaryCmd)) {
        return;
    }
    RecordingQueue.addToQueue(ActionFactory.createPlayer("player-command", player, event.getMessage()));
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 3 with TextComponent

use of net.kyori.adventure.text.TextComponent 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 4 with TextComponent

use of net.kyori.adventure.text.TextComponent 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 5 with TextComponent

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

the class OreMonitor method processAlertsFromBlock.

/**
 * Process alerts.
 *
 * @param player    Player
 * @param block     Block
 * @param alertPerm Players with this permission will receive the alert
 */
public void processAlertsFromBlock(final Player player, final Block block, final String alertPerm) {
    if (!plugin.getConfig().getBoolean("prism.alerts.ores.enabled")) {
        return;
    }
    if (player == null || player.getGameMode().equals(GameMode.CREATIVE)) {
        return;
    }
    if (block != null && isWatched(block) && !plugin.alertedBlocks.containsKey(block.getLocation())) {
        threshold = 1;
        // identify all ore blocks on same Y axis in x/z direction
        final ArrayList<Block> matchingBlocks = new ArrayList<>();
        final ArrayList<Block> foundores = findNeighborBlocks(block.getType(), block, matchingBlocks);
        if (!foundores.isEmpty()) {
            // Create alert message
            final String count = foundores.size() + (foundores.size() >= thresholdMax ? "+" : "");
            final String msg = player.getName() + " found " + count + " " + getOreNiceName(block) + " " + getLightLevel(block) + "% light";
            final TextComponent component = Component.text().content(msg).color(getOreColor(block)).hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ShowItem.of(Key.key(block.getType().getKey().toString()), 1))).build();
            plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
                // Check if block placed
                // Build params
                final QueryParameters params = new QueryParameters();
                params.setWorld(player.getWorld().getName());
                params.addSpecificBlockLocation(block.getLocation());
                params.addActionType("block-place");
                final ActionsQuery aq = new ActionsQuery(plugin);
                final QueryResult results = aq.lookup(params, player);
                if (results.getActionResults().isEmpty()) {
                    // Block was not placed - Alert staff
                    plugin.alertPlayers(null, component, alertPerm);
                    // Log to console
                    if (plugin.getConfig().getBoolean("prism.alerts.ores.log-to-console")) {
                        Prism.log(PlainComponentSerializer.plain().serialize(component));
                    }
                    // Log to commands
                    List<String> commands = plugin.getConfig().getStringList("prism.alerts.ores.log-commands");
                    MiscUtils.dispatchAlert(msg, commands);
                }
            });
        }
    }
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) QueryResult(me.botsko.prism.actionlibs.QueryResult) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) QueryParameters(me.botsko.prism.actionlibs.QueryParameters)

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