diff options
| author | Luck <git@lucko.me> | 2020-11-07 17:41:39 +0000 |
|---|---|---|
| committer | Luck <git@lucko.me> | 2020-11-07 17:41:39 +0000 |
| commit | 8cc92ff83634dffacfe1f25a135bc9ac665ff68b (patch) | |
| tree | 35efc9d9131c7ceb1db3822fbb6a0707535f7c18 /spark-common/src/main/java | |
| parent | 70a468e114316a98f6d7f7e91afa8d50639762c9 (diff) | |
| download | spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.tar.gz spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.tar.bz2 spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.zip | |
Update from text to adventure
Diffstat (limited to 'spark-common/src/main/java')
14 files changed, 1178 insertions, 388 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java index da4f4d8..f03bab2 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java @@ -42,10 +42,7 @@ import me.lucko.spark.common.monitor.tick.TickStatistics; import me.lucko.spark.common.sampler.tick.TickHook; import me.lucko.spark.common.sampler.tick.TickReporter; import me.lucko.spark.common.util.BytebinClient; -import net.kyori.text.TextComponent; -import net.kyori.text.event.ClickEvent; -import net.kyori.text.format.TextColor; -import net.kyori.text.format.TextDecoration; +import net.kyori.adventure.text.event.ClickEvent; import okhttp3.OkHttpClient; import java.util.ArrayList; @@ -55,6 +52,10 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.TextDecoration.*; + /** * Abstract spark implementation used by all platforms. */ @@ -166,26 +167,28 @@ public class SparkPlatform { CommandResponseHandler resp = new CommandResponseHandler(this, sender); if (!sender.hasPermission("spark")) { - resp.replyPrefixed(TextComponent.of("You do not have permission to use this command.", TextColor.RED)); + resp.replyPrefixed(text("You do not have permission to use this command.", RED)); return; } if (args.length == 0) { - resp.replyPrefixed(TextComponent.builder("") - .append(TextComponent.of("spark", TextColor.WHITE)) - .append(TextComponent.space()) - .append(TextComponent.of("v" + getPlugin().getVersion(), TextColor.GRAY)) + resp.replyPrefixed(text() + .append(text("spark", WHITE)) + .append(space()) + .append(text("v" + getPlugin().getVersion(), GRAY)) .build() ); - resp.replyPrefixed(TextComponent.builder("").color(TextColor.GRAY) - .append(TextComponent.of("Use ")) - .append(TextComponent.builder("/" + getPlugin().getCommandName() + " help") - .color(TextColor.WHITE) - .decoration(TextDecoration.UNDERLINED, true) + resp.replyPrefixed(text() + .color(GRAY) + .append(text("Use ")) + .append(text() + .content("/" + getPlugin().getCommandName() + " help") + .color(WHITE) + .decoration(UNDERLINED, true) .clickEvent(ClickEvent.runCommand("/" + getPlugin().getCommandName() + " help")) .build() ) - .append(TextComponent.of(" to view usage information.")) + .append(text(" to view usage information.")) .build() ); return; @@ -199,7 +202,7 @@ public class SparkPlatform { try { command.executor().execute(this, sender, resp, new Arguments(rawArgs)); } catch (IllegalArgumentException e) { - resp.replyPrefixed(TextComponent.of(e.getMessage(), TextColor.RED)); + resp.replyPrefixed(text(e.getMessage(), RED)); } return; } @@ -233,36 +236,38 @@ public class SparkPlatform { } private void sendUsage(CommandResponseHandler sender) { - sender.replyPrefixed(TextComponent.builder("") - .append(TextComponent.of("spark", TextColor.WHITE)) - .append(TextComponent.space()) - .append(TextComponent.of("v" + getPlugin().getVersion(), TextColor.GRAY)) + sender.replyPrefixed(text() + .append(text("spark", WHITE)) + .append(space()) + .append(text("v" + getPlugin().getVersion(), GRAY)) .build() ); for (Command command : this.commands) { String usage = "/" + getPlugin().getCommandName() + " " + command.aliases().get(0); ClickEvent clickEvent = ClickEvent.suggestCommand(usage); - sender.reply(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.GOLD).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.builder(usage).color(TextColor.GRAY).clickEvent(clickEvent).build()) + sender.reply(text() + .append(text(">", GOLD, BOLD)) + .append(space()) + .append(text().content(usage).color(GRAY).clickEvent(clickEvent).build()) .build() ); for (Command.ArgumentInfo arg : command.arguments()) { if (arg.requiresParameter()) { - sender.reply(TextComponent.builder(" ") - .append(TextComponent.of("[", TextColor.DARK_GRAY)) - .append(TextComponent.of("--" + arg.argumentName(), TextColor.GRAY)) - .append(TextComponent.space()) - .append(TextComponent.of("<" + arg.parameterDescription() + ">", TextColor.DARK_GRAY)) - .append(TextComponent.of("]", TextColor.DARK_GRAY)) + sender.reply(text() + .content(" ") + .append(text("[", DARK_GRAY)) + .append(text("--" + arg.argumentName(), GRAY)) + .append(space()) + .append(text("<" + arg.parameterDescription() + ">", DARK_GRAY)) + .append(text("]", DARK_GRAY)) .build() ); } else { - sender.reply(TextComponent.builder(" ") - .append(TextComponent.of("[", TextColor.DARK_GRAY)) - .append(TextComponent.of("--" + arg.argumentName(), TextColor.GRAY)) - .append(TextComponent.of("]", TextColor.DARK_GRAY)) + sender.reply(text() + .content(" ") + .append(text("[", DARK_GRAY)) + .append(text("--" + arg.argumentName(), GRAY)) + .append(text("]", DARK_GRAY)) .build() ); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java b/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java index 635e785..472ae4c 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/CommandResponseHandler.java @@ -22,23 +22,26 @@ package me.lucko.spark.common.command; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.command.sender.CommandSender; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import net.kyori.text.format.TextDecoration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.TextDecoration.*; + public class CommandResponseHandler { /** The prefix used in all messages "&8[&e&l⚡&8] &7" */ - private static final TextComponent PREFIX = TextComponent.builder("").color(TextColor.GRAY) - .append(TextComponent.of("[", TextColor.DARK_GRAY)) - .append(TextComponent.builder("⚡").color(TextColor.YELLOW).decoration(TextDecoration.BOLD, TextDecoration.State.TRUE).build()) - .append(TextComponent.of("]", TextColor.DARK_GRAY)) - .append(TextComponent.of(" ")) + private static final TextComponent PREFIX = text() + .color(GRAY) + .append(text("[", DARK_GRAY)) + .append(text("⚡", YELLOW, BOLD)) + .append(text("]", DARK_GRAY)) + .append(text(" ")) .build(); private final SparkPlatform platform; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java index c78e567..9b611fb 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/ActivityLogModule.java @@ -24,14 +24,12 @@ import me.lucko.spark.common.activitylog.ActivityLog.Activity; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; import me.lucko.spark.common.command.tabcomplete.TabCompleter; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.event.ClickEvent; -import net.kyori.text.feature.pagination.Pagination; -import net.kyori.text.feature.pagination.Pagination.Renderer; -import net.kyori.text.feature.pagination.Pagination.Renderer.RowRenderer; -import net.kyori.text.format.TextColor; -import net.kyori.text.format.TextDecoration; +import me.lucko.spark.common.util.pagination.Pagination; +import me.lucko.spark.common.util.pagination.Pagination.Renderer; +import me.lucko.spark.common.util.pagination.Pagination.Renderer.RowRenderer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; import java.util.ArrayList; import java.util.Collection; @@ -39,6 +37,9 @@ import java.util.List; import java.util.function.Consumer; import static me.lucko.spark.common.command.CommandResponseHandler.*; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.TextDecoration.*; public class ActivityLogModule implements CommandModule, RowRenderer<Activity> { @@ -46,12 +47,12 @@ public class ActivityLogModule implements CommandModule, RowRenderer<Activity> { .renderer(new Renderer() { @Override public Component renderEmpty() { - return applyPrefix(TextComponent.of("There are no entries present in the log.")); + return applyPrefix(text("There are no entries present in the log.")); } @Override public Component renderUnknownPage(int page, int pages) { - return applyPrefix(TextComponent.of("Unknown page selected. " + pages + " total pages.")); + return applyPrefix(text("Unknown page selected. " + pages + " total pages.")); } }) .resultsPerPage(4); @@ -59,33 +60,35 @@ public class ActivityLogModule implements CommandModule, RowRenderer<Activity> { @Override public Collection<Component> renderRow(Activity activity, int index) { List<Component> reply = new ArrayList<>(5); - reply.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("#" + (index + 1), TextColor.WHITE)) - .append(TextComponent.of(" - ", TextColor.DARK_GRAY)) - .append(TextComponent.of(activity.getType(), TextColor.YELLOW)) - .append(TextComponent.of(" - ", TextColor.DARK_GRAY)) - .append(TextComponent.of(formatDateDiff(activity.getTime()), TextColor.GRAY)) + reply.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("#" + (index + 1), WHITE)) + .append(text(" - ", DARK_GRAY)) + .append(text(activity.getType(), YELLOW)) + .append(text(" - ", DARK_GRAY)) + .append(text(formatDateDiff(activity.getTime()), GRAY)) .build() ); - reply.add(TextComponent.builder(" ") - .append(TextComponent.of("Created by: ", TextColor.GRAY)) - .append(TextComponent.of(activity.getUser().getName(), TextColor.WHITE)) + reply.add(text() + .content(" ") + .append(text("Created by: ", GRAY)) + .append(text(activity.getUser().getName(), WHITE)) .build() ); - TextComponent.Builder valueComponent = TextComponent.builder(activity.getDataValue(), TextColor.WHITE); + TextComponent.Builder valueComponent = text().content(activity.getDataValue()).color(WHITE); if (activity.getDataType().equals("url")) { valueComponent.clickEvent(ClickEvent.openUrl(activity.getDataValue())); } - reply.add(TextComponent.builder(" ") - .append(TextComponent.of(Character.toUpperCase(activity.getDataType().charAt(0)) + activity.getDataType().substring(1) + ": ", TextColor.GRAY)) + reply.add(text() + .content(" ") + .append(text(Character.toUpperCase(activity.getDataType().charAt(0)) + activity.getDataType().substring(1) + ": ", GRAY)) .append(valueComponent) .build() ); - reply.add(TextComponent.space()); + reply.add(space()); return reply; } @@ -99,14 +102,14 @@ public class ActivityLogModule implements CommandModule, RowRenderer<Activity> { log.removeIf(Activity::shouldExpire); if (log.isEmpty()) { - resp.replyPrefixed(TextComponent.of("There are no entries present in the log.")); + resp.replyPrefixed(text("There are no entries present in the log.")); return; } int page = Math.max(1, arguments.intFlag("page")); Pagination<Activity> activityPagination = this.pagination.build( - TextComponent.of("Recent spark activity", TextColor.GOLD), + text("Recent spark activity", GOLD), this, value -> "/" + platform.getPlugin().getCommandName() + " activity --page " + value ); diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/GcMonitoringModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/GcMonitoringModule.java index ea1cc00..d66a181 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/GcMonitoringModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/GcMonitoringModule.java @@ -28,10 +28,7 @@ import me.lucko.spark.common.command.CommandResponseHandler; import me.lucko.spark.common.monitor.memory.GarbageCollectionMonitor; import me.lucko.spark.common.monitor.memory.GarbageCollectorStatistics; import me.lucko.spark.common.util.FormatUtil; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import net.kyori.text.format.TextDecoration; +import net.kyori.adventure.text.Component; import java.lang.management.MemoryUsage; import java.text.DecimalFormat; @@ -40,6 +37,10 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.TextDecoration.*; + public class GcMonitoringModule implements CommandModule { private static final DecimalFormat df = new DecimalFormat("#.##"); @@ -59,14 +60,14 @@ public class GcMonitoringModule implements CommandModule { consumer.accept(Command.builder() .aliases("gc") .executor((platform, sender, resp, arguments) -> { - resp.replyPrefixed(TextComponent.of("Calculating GC statistics...")); + resp.replyPrefixed(text("Calculating GC statistics...")); List<Component> report = new LinkedList<>(); - report.add(TextComponent.empty()); - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("Garbage Collector statistics", TextColor.GOLD)) + report.add(empty()); + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("Garbage Collector statistics", GOLD)) .build() ); @@ -78,16 +79,18 @@ public class GcMonitoringModule implements CommandModule { double collectionTime = collector.getValue().getCollectionTime(); long collectionCount = collector.getValue().getCollectionCount(); - report.add(TextComponent.empty()); + report.add(empty()); if (collectionCount == 0) { - report.add(TextComponent.builder(" ") - .append(TextComponent.of(collectorName + " collector:", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(collectorName + " collector:", GRAY)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(0, TextColor.WHITE)) - .append(TextComponent.of(" collections", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(0, WHITE)) + .append(text(" collections", GRAY)) .build() ); continue; @@ -96,27 +99,30 @@ public class GcMonitoringModule implements CommandModule { double averageCollectionTime = collectionTime / collectionCount; double averageFrequency = (serverUptime - collectionTime) / collectionCount; - report.add(TextComponent.builder(" ") - .append(TextComponent.of(collectorName + " collector:", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(collectorName + " collector:", GRAY)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(df.format(averageCollectionTime), TextColor.GOLD)) - .append(TextComponent.of(" ms avg", TextColor.GRAY)) - .append(TextComponent.of(", ", TextColor.DARK_GRAY)) - .append(TextComponent.of(collectionCount, TextColor.WHITE)) - .append(TextComponent.of(" total collections", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(df.format(averageCollectionTime), GOLD)) + .append(text(" ms avg", GRAY)) + .append(text(", ", DARK_GRAY)) + .append(text(collectionCount, WHITE)) + .append(text(" total collections", GRAY)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(formatTime((long) averageFrequency), TextColor.WHITE)) - .append(TextComponent.of(" avg frequency", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(formatTime((long) averageFrequency), WHITE)) + .append(text(" avg frequency", GRAY)) .build() ); } if (report.size() == 1) { - resp.replyPrefixed(TextComponent.of("No garbage collectors are reporting data.")); + resp.replyPrefixed(text("No garbage collectors are reporting data.")); } else { report.forEach(resp::reply); } @@ -129,10 +135,10 @@ public class GcMonitoringModule implements CommandModule { .executor((platform, sender, resp, arguments) -> { if (this.activeGcMonitor == null) { this.activeGcMonitor = new ReportingGcMonitor(platform, resp); - resp.broadcastPrefixed(TextComponent.of("GC monitor enabled.")); + resp.broadcastPrefixed(text("GC monitor enabled.")); } else { close(); - resp.broadcastPrefixed(TextComponent.of("GC monitor disabled.")); + resp.broadcastPrefixed(text("GC monitor disabled.")); } }) .build() @@ -195,13 +201,15 @@ public class GcMonitoringModule implements CommandModule { this.platform.getPlugin().executeAsync(() -> { List<Component> report = new LinkedList<>(); - report.add(CommandResponseHandler.applyPrefix(TextComponent.builder("").color(TextColor.GRAY) - .append(TextComponent.of(gcType + " ")) - .append(TextComponent.of("GC", TextColor.RED)) - .append(TextComponent.of(" lasting ")) - .append(TextComponent.of(df.format(data.getGcInfo().getDuration()), TextColor.GOLD)) - .append(TextComponent.of(" ms." + gcCause)) - .build() + report.add(CommandResponseHandler.applyPrefix( + text() + .color(GRAY) + .append(text(gcType + " ")) + .append(text("GC", RED)) + .append(text(" lasting ")) + .append(text(df.format(data.getGcInfo().getDuration()), GOLD)) + .append(text(" ms." + gcCause)) + .build() )); for (Map.Entry<String, MemoryUsage> entry : afterUsages.entrySet()) { @@ -219,33 +227,37 @@ public class GcMonitoringModule implements CommandModule { } if (diff > 0) { - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(diff), TextColor.GOLD)) - .append(TextComponent.of(" freed from ", TextColor.DARK_GRAY)) - .append(TextComponent.of(type, TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(diff), GOLD)) + .append(text(" freed from ", DARK_GRAY)) + .append(text(type, GRAY)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(before.getUsed()), TextColor.GRAY)) - .append(TextComponent.of(" → ", TextColor.DARK_GRAY)) - .append(TextComponent.of(FormatUtil.formatBytes(after.getUsed()), TextColor.GRAY)) - .append(TextComponent.space()) - .append(TextComponent.of("(", TextColor.DARK_GRAY)) - .append(TextComponent.of(FormatUtil.percent(diff, before.getUsed()), TextColor.WHITE)) - .append(TextComponent.of(")", TextColor.DARK_GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(before.getUsed()), GRAY)) + .append(text(" → ", DARK_GRAY)) + .append(text(FormatUtil.formatBytes(after.getUsed()), GRAY)) + .append(space()) + .append(text("(", DARK_GRAY)) + .append(text(FormatUtil.percent(diff, before.getUsed()), WHITE)) + .append(text(")", DARK_GRAY)) .build() ); } else { - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(-diff), TextColor.GOLD)) - .append(TextComponent.of(" moved to ", TextColor.DARK_GRAY)) - .append(TextComponent.of(type, TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(-diff), GOLD)) + .append(text(" moved to ", DARK_GRAY)) + .append(text(type, GRAY)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(before.getUsed()), TextColor.GRAY)) - .append(TextComponent.of(" → ", TextColor.DARK_GRAY)) - .append(TextComponent.of(FormatUtil.formatBytes(after.getUsed()), TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(before.getUsed()), GRAY)) + .append(text(" → ", DARK_GRAY)) + .append(text(FormatUtil.formatBytes(after.getUsed()), GRAY)) .build() ); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java index 64c2fba..9bf3421 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HealthModule.java @@ -28,10 +28,9 @@ import me.lucko.spark.common.monitor.cpu.CpuMonitor; import me.lucko.spark.common.monitor.tick.TickStatistics; import me.lucko.spark.common.util.FormatUtil; import me.lucko.spark.common.util.RollingAverage; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; -import net.kyori.text.format.TextDecoration; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.TextColor; import java.io.IOException; import java.lang.management.ManagementFactory; @@ -46,6 +45,10 @@ import java.util.LinkedList; import java.util.List; import java.util.function.Consumer; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; +import static net.kyori.adventure.text.format.TextDecoration.*; + public class HealthModule implements CommandModule { private static final int MSPT_95_PERCENTILE = 95; @@ -57,41 +60,45 @@ public class HealthModule implements CommandModule { .executor((platform, sender, resp, arguments) -> { TickStatistics tickStatistics = platform.getTickStatistics(); if (tickStatistics != null) { - resp.replyPrefixed(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:")); - resp.replyPrefixed(TextComponent.builder(" ") - .append(formatTps(tickStatistics.tps5Sec())).append(TextComponent.of(", ")) - .append(formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", ")) - .append(formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", ")) - .append(formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", ")) + resp.replyPrefixed(text("TPS from last 5s, 10s, 1m, 5m, 15m:")); + resp.replyPrefixed(text() + .content(" ") + .append(formatTps(tickStatistics.tps5Sec())).append(text(", ")) + .append(formatTps(tickStatistics.tps10Sec())).append(text(", ")) + .append(formatTps(tickStatistics.tps1Min())).append(text(", ")) + .append(formatTps(tickStatistics.tps5Min())).append(text(", ")) .append(formatTps(tickStatistics.tps15Min())) .build() ); - resp.replyPrefixed(TextComponent.empty()); + resp.replyPrefixed(empty()); if (tickStatistics.isDurationSupported()) { - resp.replyPrefixed(TextComponent.of("Tick durations (min/med/95%ile/max ms) from last 10s, 1m:")); - resp.replyPrefixed(TextComponent.builder(" ") - .append(formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of("; ")) + resp.replyPrefixed(text("Tick durations (min/med/95%ile/max ms) from last 10s, 1m:")); + resp.replyPrefixed(text() + .content(" ") + .append(formatTickDurations(tickStatistics.duration10Sec())).append(text("; ")) .append(formatTickDurations(tickStatistics.duration1Min())) .build() ); - resp.replyPrefixed(TextComponent.empty()); + resp.replyPrefixed(empty()); } } - resp.replyPrefixed(TextComponent.of("CPU usage from last 10s, 1m, 15m:")); - resp.replyPrefixed(TextComponent.builder(" ") - .append(formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", ")) - .append(formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", ")) + resp.replyPrefixed(text("CPU usage from last 10s, 1m, 15m:")); + resp.replyPrefixed(text() + .content(" ") + .append(formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(text(", ")) + .append(formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(text(", ")) .append(formatCpuUsage(CpuMonitor.systemLoad15MinAvg())) - .append(TextComponent.of(" (system)", TextColor.DARK_GRAY)) + .append(text(" (system)", DARK_GRAY)) .build() ); - resp.replyPrefixed(TextComponent.builder(" ") - .append(formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", ")) - .append(formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", ")) + resp.replyPrefixed(text() + .content(" ") + .append(formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(text(", ")) + .append(formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(text(", ")) .append(formatCpuUsage(CpuMonitor.processLoad15MinAvg())) - .append(TextComponent.of(" (process)", TextColor.DARK_GRAY)) + .append(text(" (process)", DARK_GRAY)) .build() ); }) @@ -103,103 +110,109 @@ public class HealthModule implements CommandModule { .aliases("healthreport", "health", "ht") .argumentUsage("memory", null) .executor((platform, sender, resp, arguments) -> { - resp.replyPrefixed(TextComponent.of("Generating server health report...")); + resp.replyPrefixed(text("Generating server health report...")); platform.getPlugin().executeAsync(() -> { List<Component> report = new LinkedList<>(); - report.add(TextComponent.empty()); + report.add(empty()); TickStatistics tickStatistics = platform.getTickStatistics(); if (tickStatistics != null) { - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("TPS from last 5s, 10s, 1m, 5m, 15m:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("TPS from last 5s, 10s, 1m, 5m, 15m:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(formatTps(tickStatistics.tps5Sec())).append(TextComponent.of( |
