Search in sources :

Example 1 with TextColor

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

the class TypeUtils method from.

/**
 * Get Color.
 *
 * @param hex String.
 * @return ChatColor.
 */
public static TextColor from(String hex) {
    if (hex.length() == 2 && hex.startsWith("&")) {
        LegacyFormat format = LegacyComponentSerializer.parseChar(hex.charAt(1));
        if (format != null && format.color() != null) {
            return format.color();
        } else {
            return NamedTextColor.WHITE;
        }
    }
    if (hex.length() != 7 && !hex.startsWith("#")) {
        Prism.log("Could not decode as hex:" + hex);
        TextColor color = NamedTextColor.NAMES.value(hex);
        if (color != null) {
            return color;
        }
        return NamedTextColor.WHITE;
    }
    TextColor color = TextColor.fromHexString(hex);
    if (color == null) {
        return NamedTextColor.WHITE;
    }
    return color;
}
Also used : TextColor(net.kyori.adventure.text.format.TextColor) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) LegacyFormat(net.kyori.adventure.text.serializer.legacy.LegacyFormat)

Example 2 with TextColor

use of net.kyori.adventure.text.format.TextColor 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 3 with TextColor

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

the class Prism method loadConfig.

/**
 * Load configuration and language files.
 */
public void loadConfig() {
    final PrismConfig mc = new PrismConfig(this);
    config = mc.getConfig();
    // Cache config arrays we check constantly
    illegalBlocks = getConfig().getStringList("prism.appliers.never-place-block").stream().map(Material::matchMaterial).filter(Objects::nonNull).collect(Collectors.toList());
    illegalEntities = getConfig().getStringList("prism.appliers.never-spawn-entity").stream().map(s -> {
        try {
            return EntityType.valueOf(s.toUpperCase());
        } catch (Exception e) {
            debug(e.getMessage());
        }
        return null;
    }).filter(Objects::nonNull).collect(Collectors.toList());
    final ConfigurationSection alertBlocks = getConfig().getConfigurationSection("prism.alerts.ores.blocks");
    alertedOres.clear();
    if (alertBlocks != null) {
        for (final String key : alertBlocks.getKeys(false)) {
            Material m = Material.matchMaterial(key.toUpperCase());
            String colorString = alertBlocks.getString(key);
            if (m == null || colorString == null) {
                Prism.log("Could not match alert block:" + key + " color:" + colorString);
                continue;
            }
            TextColor color = TypeUtils.from(colorString);
            alertedOres.put(m, color);
        }
    }
    items = new MaterialAliases();
}
Also used : InternalAffairs(me.botsko.prism.actionlibs.InternalAffairs) KeywordParameter(me.botsko.prism.parameters.KeywordParameter) SimpleFormatter(java.util.logging.SimpleFormatter) EntityParameter(me.botsko.prism.parameters.EntityParameter) PrismMiscEvents(me.botsko.prism.listeners.self.PrismMiscEvents) ActionsQuery(me.botsko.prism.actionlibs.ActionsQuery) PrismDatabaseFactory(me.botsko.prism.database.PrismDatabaseFactory) TimeTaken(me.botsko.prism.measurement.TimeTaken) Future(java.util.concurrent.Future) FileHandler(java.util.logging.FileHandler) PreviewSession(me.botsko.prism.appliers.PreviewSession) PlayerParameter(me.botsko.prism.parameters.PlayerParameter) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) EventHelper(me.botsko.prism.events.EventHelper) Material(org.bukkit.Material) CommandSender(org.bukkit.command.CommandSender) TextColor(net.kyori.adventure.text.format.TextColor) Ignore(me.botsko.prism.actionlibs.Ignore) PrismBlockEvents(me.botsko.prism.listeners.PrismBlockEvents) PrismPlayerEvents(me.botsko.prism.listeners.PrismPlayerEvents) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) PaperListeners(me.botsko.prism.listeners.PaperListeners) JavaPluginLoader(org.bukkit.plugin.java.JavaPluginLoader) QueueStats(me.botsko.prism.measurement.QueueStats) QueueDrain(me.botsko.prism.actionlibs.QueueDrain) PrismDataSource(me.botsko.prism.database.PrismDataSource) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Result(me.botsko.prism.api.Result) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PurgeManager(me.botsko.prism.purge.PurgeManager) PrismInventoryMoveItemEvent(me.botsko.prism.listeners.PrismInventoryMoveItemEvent) PrismCommands(me.botsko.prism.commands.PrismCommands) FlagParameter(me.botsko.prism.parameters.FlagParameter) Identity(net.kyori.adventure.identity.Identity) IOException(java.io.IOException) QueryResult(me.botsko.prism.actionlibs.QueryResult) File(java.io.File) IdParameter(me.botsko.prism.parameters.IdParameter) RecordingTask(me.botsko.prism.actionlibs.RecordingTask) PrismVehicleEvents(me.botsko.prism.listeners.PrismVehicleEvents) PrismWorldEvents(me.botsko.prism.listeners.PrismWorldEvents) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) BlockParameter(me.botsko.prism.parameters.BlockParameter) Connection(java.sql.Connection) Date(java.util.Date) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Player(org.bukkit.entity.Player) PaperLib(io.papermc.lib.PaperLib) PrismEntityEvents(me.botsko.prism.listeners.PrismEntityEvents) Block(org.bukkit.block.Block) QueryParameters(me.botsko.prism.actionlibs.QueryParameters) Bukkit(org.bukkit.Bukkit) OreMonitor(me.botsko.prism.monitors.OreMonitor) TextComponent(net.kyori.adventure.text.TextComponent) PrismPlayer(me.botsko.prism.players.PrismPlayer) ActionMeter(me.botsko.prism.actions.ActionMeter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TypeUtils(me.botsko.prism.utils.TypeUtils) Metrics(org.bstats.bukkit.Metrics) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) PrismApi(me.botsko.prism.api.PrismApi) MaterialAliases(me.botsko.prism.utils.MaterialAliases) PluginCommand(org.bukkit.command.PluginCommand) Collectors(java.util.stream.Collectors) WhatCommand(me.botsko.prism.commands.WhatCommand) ActionParameter(me.botsko.prism.parameters.ActionParameter) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Objects(java.util.Objects) List(java.util.List) RadiusParameter(me.botsko.prism.parameters.RadiusParameter) BukkitTask(org.bukkit.scheduler.BukkitTask) Entry(java.util.Map.Entry) Handler(java.util.logging.Handler) BeforeParameter(me.botsko.prism.parameters.BeforeParameter) WorldParameter(me.botsko.prism.parameters.WorldParameter) PrismParameterHandler(me.botsko.prism.parameters.PrismParameterHandler) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) HandlerRegistry(me.botsko.prism.actionlibs.HandlerRegistry) Level(java.util.logging.Level) PrismParameters(me.botsko.prism.api.PrismParameters) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) PrismInventoryEvents(me.botsko.prism.listeners.PrismInventoryEvents) Component(net.kyori.adventure.text.Component) ActionRegistry(me.botsko.prism.actionlibs.ActionRegistry) SqlPlayerIdentificationHelper(me.botsko.prism.database.sql.SqlPlayerIdentificationHelper) BukkitAudiences(net.kyori.adventure.platform.bukkit.BukkitAudiences) UseMonitor(me.botsko.prism.monitors.UseMonitor) SinceParameter(me.botsko.prism.parameters.SinceParameter) Wand(me.botsko.prism.wands.Wand) TimeUnit(java.util.concurrent.TimeUnit) PrismCustomEvents(me.botsko.prism.listeners.PrismCustomEvents) MaterialAliases(me.botsko.prism.utils.MaterialAliases) Objects(java.util.Objects) Material(org.bukkit.Material) TextColor(net.kyori.adventure.text.format.TextColor) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) SQLException(java.sql.SQLException) IOException(java.io.IOException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)2 TextColor (net.kyori.adventure.text.format.TextColor)2 PaperLib (io.papermc.lib.PaperLib)1 File (java.io.File)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1