use of net.minecraft.text.Style in project EdenClient by HahaOO7.
the class ChatColor method translateColors.
public static Text translateColors(String string) {
final Pattern hex = Pattern.compile("ยง#[0-9a-fA-F]{6}");
LiteralText text = new LiteralText("");
Style style = Style.EMPTY;
Matcher matcher = hex.matcher(string);
while (matcher.find()) {
int start = matcher.start();
int end = matcher.end();
text.append(new LiteralText(string.substring(0, start)).setStyle(style));
style = style.withColor(TextColor.parse(string.substring(start + 1, end)));
string = string.substring(end);
matcher = hex.matcher(string);
}
text.append(new LiteralText(string).setStyle(style));
return text;
}
use of net.minecraft.text.Style in project EdenClient by HahaOO7.
the class StyleLoader method load.
@Override
public Style load(NbtCompound tag) {
Style style = Style.EMPTY;
style = style.withBold(tag.getBoolean("bold"));
style = style.withObfuscated(tag.getBoolean("obfuscated"));
style = style.withItalic(tag.getBoolean("italic"));
style = style.withStrikethrough(tag.getBoolean("strikethrough"));
style = style.withUnderline(tag.getBoolean("underlined"));
if (tag.contains("rgb"))
style = style.withColor(tag.getInt("rgb"));
return style;
}
use of net.minecraft.text.Style in project AdvancedChatBox by DarkKronicle.
the class ColorCodeFormatter method format.
@Override
public Optional<FluidText> format(FluidText text, @Nullable ParseResults<CommandSource> parse) {
if (parse != null) {
return Optional.empty();
}
String string = text.getString();
if (!string.contains("&")) {
return Optional.empty();
}
SearchResult search = SearchResult.searchOf(string, "(?i)&[0-9A-FK-OR]", FindType.REGEX);
if (search.size() == 0) {
return Optional.empty();
}
int index = 0;
Style last = Style.EMPTY;
FluidText formatted = new FluidText();
for (StringMatch match : search.getMatches()) {
formatted.append(text.truncate(new StringMatch("", index, match.start)).fillStyle(last));
Formatting format = Formatting.byCode(match.match.charAt(1));
last = last.withFormatting(format);
index = match.start;
}
FluidText small = text.truncate(new StringMatch("", index, string.length()));
if (small != null && !small.getString().isEmpty()) {
formatted.append(small.fillStyle(last));
}
return Optional.of(formatted);
}
use of net.minecraft.text.Style in project mclogs-fabric by aternosorg.
the class CommandMclogsList method register.
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("mclogs").then(literal("list").requires(source -> source.hasPermissionLevel(2)).executes((context) -> {
ServerCommandSource source = context.getSource();
try {
String[] logs = MclogsFabricLoader.getLogs(context);
if (logs.length == 0) {
source.sendFeedback(new LiteralText("No logs available!"), false);
return 0;
}
LiteralText feedback = new LiteralText("Available Logs:");
for (String log : logs) {
Style s = Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mclogs share " + log));
LiteralText tempText = new LiteralText("\n" + log);
tempText.setStyle(s);
feedback.append(tempText);
}
source.sendFeedback(feedback, false);
return logs.length;
} catch (Exception e) {
MclogsFabricLoader.logger.error("An error occurred when listing your logs.");
MclogsFabricLoader.logger.error(e);
LiteralText error = new LiteralText("An error occurred. Check your log for more details.");
source.sendError(error);
return -1;
}
})));
}
use of net.minecraft.text.Style in project mclogs-fabric by aternosorg.
the class MclogsFabricLoader method share.
public static int share(ServerCommandSource source, String filename) {
MclogsAPI.mcversion = source.getMinecraftServer().getVersion();
logger.log(Level.INFO, "Sharing " + filename);
source.sendFeedback(new LiteralText("Sharing " + filename), false);
try {
Path logs = source.getMinecraftServer().getFile("logs/").toPath();
Path log = logs.resolve(filename);
if (!log.getParent().equals(logs)) {
throw new FileNotFoundException();
}
APIResponse response = MclogsAPI.share(log);
if (response.success) {
LiteralText feedback = new LiteralText("Your log has been uploaded: ");
feedback.setStyle(Style.EMPTY.withColor(Formatting.GREEN));
LiteralText link = new LiteralText(response.url);
Style linkStyle = Style.EMPTY.withColor(Formatting.BLUE);
linkStyle = linkStyle.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, response.url));
link.setStyle(linkStyle);
source.sendFeedback(feedback.append(link), true);
return 1;
} else {
logger.error("An error occurred when uploading your log: ");
logger.error(response.error);
LiteralText error = new LiteralText("An error occurred. Check your log for more details");
source.sendError(error);
return 0;
}
} catch (FileNotFoundException | IllegalArgumentException e) {
LiteralText error = new LiteralText("The log file " + filename + " doesn't exist. Use '/mclogs list' to list all logs.");
source.sendError(error);
return -1;
} catch (IOException e) {
source.sendError(new LiteralText("An error occurred. Check your log for more details"));
logger.error("Could not get log file!");
logger.error(e);
return 0;
}
}
Aggregations