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;
}
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();
}
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();
}
Aggregations