diff options
Diffstat (limited to 'spark-common/src/main/java/me/lucko/spark/common/command')
8 files changed, 357 insertions, 312 deletions
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(", ")) - .append(formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", ")) - .append(formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", ")) - .append(formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", ")) + report.add(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() ); - report.add(TextComponent.empty()); + report.add(empty()); if (tickStatistics.isDurationSupported()) { - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("Tick durations (min/med/95%ile/max ms) from last 10s, 1m:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("Tick durations (min/med/95%ile/max ms) from last 10s, 1m:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of("; ")) + report.add(text() + .content(" ") + .append(formatTickDurations(tickStatistics.duration10Sec())).append(text("; ")) .append(formatTickDurations(tickStatistics.duration1Min())) .build() ); - report.add(TextComponent.empty()); + report.add(empty()); } } - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("CPU usage from last 10s, 1m, 15m:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("CPU usage from last 10s, 1m, 15m:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", ")) - .append(formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", ")) + report.add(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() ); - report.add(TextComponent.builder(" ") - .append(formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", ")) - .append(formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", ")) + report.add(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() ); - report.add(TextComponent.empty()); + report.add(empty()); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage(); - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("Memory usage:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("Memory usage:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(heapUsage.getUsed()), TextColor.WHITE)) - .append(TextComponent.space()) - .append(TextComponent.of("/", TextColor.GRAY)) - .append(TextComponent.space()) - .append(TextComponent.of(FormatUtil.formatBytes(heapUsage.getMax()), TextColor.WHITE)) - .append(TextComponent.of(" ")) - .append(TextComponent.of("(", TextColor.GRAY)) - .append(TextComponent.of(FormatUtil.percent(heapUsage.getUsed(), heapUsage.getMax()), TextColor.GREEN)) - .append(TextComponent.of(")", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(heapUsage.getUsed()), WHITE)) + .append(space()) + .append(text("/", GRAY)) + .append(space()) + .append(text(FormatUtil.formatBytes(heapUsage.getMax()), WHITE)) + .append(text(" ")) + .append(text("(", GRAY)) + .append(text(FormatUtil.percent(heapUsage.getUsed(), heapUsage.getMax()), GREEN)) + .append(text(")", GRAY)) .build() ); - report.add(TextComponent.builder(" ").append(generateMemoryUsageDiagram(heapUsage, 40)).build()); - report.add(TextComponent.empty()); + report.add(text().content(" ").append(generateMemoryUsageDiagram(heapUsage, 40)).build()); + report.add(empty()); if (arguments.boolFlag("memory")) { MemoryUsage nonHeapUsage = memoryMXBean.getNonHeapMemoryUsage(); - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("Non-heap memory usage:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("Non-heap memory usage:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(nonHeapUsage.getUsed()), TextColor.WHITE)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(nonHeapUsage.getUsed()), WHITE)) .build() ); - report.add(TextComponent.empty()); + report.add(empty()); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean memoryPool : memoryPoolMXBeans) { @@ -214,37 +227,39 @@ public class HealthModule implements CommandModule { usage = new MemoryUsage(usage.getInit(), usage.getUsed(), usage.getCommitted(), usage.getCommitted()); } - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of(memoryPool.getName() + " pool usage:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text(memoryPool.getName() + " pool usage:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(usage.getUsed()), TextColor.WHITE)) - .append(TextComponent.space()) - .append(TextComponent.of("/", TextColor.GRAY)) - .append(TextComponent.space()) - .append(TextComponent.of(FormatUtil.formatBytes(usage.getMax()), TextColor.WHITE)) - .append(TextComponent.of(" ")) - .append(TextComponent.of("(", TextColor.GRAY)) - .append(TextComponent.of(FormatUtil.percent(usage.getUsed(), usage.getMax()), TextColor.GREEN)) - .append(TextComponent.of(")", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(usage.getUsed()), WHITE)) + .append(space()) + .append(text("/", GRAY)) + .append(space()) + .append(text(FormatUtil.formatBytes(usage.getMax()), WHITE)) + .append(text(" ")) + .append(text("(", GRAY)) + .append(text(FormatUtil.percent(usage.getUsed(), usage.getMax()), GREEN)) + .append(text(")", GRAY)) .build() ); - report.add(TextComponent.builder(" ").append(generateMemoryPoolDiagram(usage, collectionUsage, 40)).build()); + report.add(text().content(" ").append(generateMemoryPoolDiagram(usage, collectionUsage, 40)).build()); if (collectionUsage != null) { - report.add(TextComponent.builder(" ") - .append(TextComponent.of("-", TextColor.RED)) - .append(TextComponent.space()) - .append(TextComponent.of("Usage at last GC:", TextColor.GRAY)) - .append(TextComponent.space()) - .append(TextComponent.of(FormatUtil.formatBytes(collectionUsage.getUsed()), TextColor.WHITE)) + report.add(text() + .content(" ") + .append(text("-", RED)) + .append(space()) + .append(text("Usage at last GC:", GRAY)) + .append(space()) + .append(text(FormatUtil.formatBytes(collectionUsage.getUsed()), WHITE)) .build() ); } - report.add(TextComponent.empty()); + report.add(empty()); } } @@ -252,26 +267,27 @@ public class HealthModule implements CommandModule { FileStore fileStore = Files.getFileStore(Paths.get(".")); long totalSpace = fileStore.getTotalSpace(); long usedSpace = totalSpace - fileStore.getUsableSpace(); - report.add(TextComponent.builder("") - .append(TextComponent.builder(">").color(TextColor.DARK_GRAY).decoration(TextDecoration.BOLD, true).build()) - .append(TextComponent.space()) - .append(TextComponent.of("Disk usage:", TextColor.GOLD)) + report.add(text() + .append(text(">", DARK_GRAY, BOLD)) + .append(space()) + .append(text("Disk usage:", GOLD)) .build() ); - report.add(TextComponent.builder(" ") - .append(TextComponent.of(FormatUtil.formatBytes(usedSpace), TextColor.WHITE)) - .append(TextComponent.space()) - .append(TextComponent.of("/", TextColor.GRAY)) - .append(TextComponent.space()) - .append(TextComponent.of(FormatUtil.formatBytes(totalSpace), TextColor.WHITE)) - .append(TextComponent.of(" ")) - .append(TextComponent.of("(", TextColor.GRAY)) - .append(TextComponent.of(FormatUtil.percent(usedSpace, totalSpace), TextColor.GREEN)) - .append(TextComponent.of(")", TextColor.GRAY)) + report.add(text() + .content(" ") + .append(text(FormatUtil.formatBytes(usedSpace), WHITE)) + .append(space()) + .append(text("/", GRAY)) + .append(space()) + .append(text(FormatUtil.formatBytes(totalSpace), WHITE)) + .append(text(" ")) + .append(text("(", GRAY)) + .append(text(FormatUtil.percent(usedSpace, totalSpace), GREEN)) + .append(text(")", GRAY)) .build() ); - report.add(TextComponent.builder(" ").append(generateDiskUsageDiagram(usedSpace, totalSpace, 40)).build()); - report.add(TextComponent.empty()); + report.add(text().content(" ").append(generateDiskUsageDiagram(usedSpace, totalSpace, 40)).build()); + report.add(empty()); } catch (IOException e) { e.printStackTrace(); } @@ -287,24 +303,24 @@ public class HealthModule implements CommandModule { public static TextComponent formatTps(double tps) { TextColor color; if (tps > 18.0) { - color = TextColor.GREEN; + color = GREEN; } else if (tps > 16.0) { - color = TextColor.YELLOW; + color = YELLOW; } else { - color = TextColor.RED; + color = RED; } - return TextComponent.of( (tps > 20.0 ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0), color); + return text((tps > 20.0 ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0), color); } public static TextComponent formatTickDurations(RollingAverage average){ - return TextComponent.builder("") + return text() .append(formatTickDuration(average.getMin())) - .append(TextComponent.of('/', TextColor.GRAY)) + .append(text('/', GRAY)) .append(formatTickDuration(average.getMedian())) - .append(TextComponent.of('/', TextColor.GRAY)) + .append(text('/', GRAY)) .append(formatTickDuration(average.getPercentile(MSPT_95_PERCENTILE))) - .append(TextComponent.of('/', TextColor.GRAY)) + .append(text('/', GRAY)) .append(formatTickDuration(average.getMax())) .build(); } @@ -312,27 +328,27 @@ public class HealthModule implements CommandModule { public static TextComponent formatTickDuration(double duration){ TextColor color; if (duration >= 50d) { - color = TextColor.RED; + color = RED; } else if (duration >= 40d) { - color = TextColor.YELLOW; + color = YELLOW; } else { - color = TextColor.GREEN; + color = GREEN; } - return TextComponent.of(String.format("%.1f", duration), color); + return text(String.format("%.1f", duration), color); } public static TextComponent formatCpuUsage(double usage) { TextColor color; if (usage > 0.9) { - color = TextColor.RED; + color = RED; } else if (usage > 0.65) { - color = TextColor.YELLOW; + color = YELLOW; } else { - color = TextColor.GREEN; + color = GREEN; } - return TextComponent.of(FormatUtil.percent(usage, 1d), color); + return text(FormatUtil.percent(usage, 1d), color); } private static TextComponent generateMemoryUsageDiagram(MemoryUsage usage, int length) { @@ -343,19 +359,19 @@ public class HealthModule implements CommandModule { int usedChars = (int) ((used * length) / max); int committedChars = (int) ((committed * length) / max); - TextComponent.Builder line = TextComponent.builder(Strings.repeat("/", usedChars)).color(TextColor.GRAY); + TextComponent.Builder line = text().content(Strings.repeat("/", usedChars)).color(GRAY); if (committedChars > usedChars) { - line.append(TextComponent.of(Strings.repeat(" ", (committedChars - usedChars) - 1))); - line.append(TextComponent.of("|", TextColor.YELLOW)); + line.append(text(Strings.repeat(" ", (committedChars - usedChars) - 1))); + line.append(text("|", YELLOW)); } if (length > committedChars) { - line.append(TextComponent.of(Strings.repeat(" ", (length - committedChars)))); + line.append(text(Strings.repeat(" ", (length - committedChars)))); } - return TextComponent.builder("") - .append(TextComponent.of("[", TextColor.DARK_GRAY)) + return text() + .append(text("[", DARK_GRAY)) .append(line.build()) - .append(TextComponent.of("]", TextColor.DARK_GRAY)) + .append(text("]", DARK_GRAY)) .build(); } @@ -372,34 +388,34 @@ public class HealthModule implements CommandModule { int collectionUsedChars = (int) ((collectionUsed * length) / max); int committedChars = (int) ((committed * length) / max); - TextComponent.Builder line = TextComponent.builder(Strings.repeat("/", collectionUsedChars)).color(TextColor.GRAY); + TextComponent.Builder line = text().content(Strings.repeat("/", collectionUsedChars)).color(GRAY); if (usedChars > collectionUsedChars) { - line.append(TextComponent.of("|", TextColor.RED)); - line.append(TextComponent.of(Strings.repeat("/", (usedChars - collectionUsedChars) - 1), TextColor.GRAY)); + line.append(text("|", RED)); + line.append(text(Strings.repeat("/", (usedChars - collectionUsedChars) - 1), GRAY)); } if (committedChars > usedChars) { - line.append(TextComponent.of(Strings.repeat(" ", (committedChars - usedChars) - 1))); - line.append(TextComponent.of("|", TextColor.YELLOW)); + line.append(text(Strings.repeat(" ", (committedChars - usedChars) - 1))); + line.append(text("|", YELLOW)); } if (length > committedChars) { - line.append(TextComponent.of(Strings.repeat(" ", (length - committedChars)))); + line.append(text(Strings.repeat(" ", (length - committedChars)))); } - return TextComponent.builder("") - .append(TextComponent.of("[", TextColor.DARK_GRAY)) + return text() + .append(text("[", DARK_GRAY)) .append(line.build()) - .append(TextComponent.of("]", TextColor.DARK_GRAY)) + .append(text("]", DARK_GRAY)) .build(); } private static TextComponent generateDiskUsageDiagram(double used, double max, int length) { int usedChars = (int) ((used * length) / max); String line = Strings.repeat("/", usedChars) + Strings.repeat(" ", length - usedChars); - return TextComponent.builder("") - .append(TextComponent.of("[", TextColor.DARK_GRAY)) - .append(TextComponent.of(line, TextColor.GRAY)) - .append(TextComponent.of("]", TextColor.DARK_GRAY)) + return text() + .append(text("[", DARK_GRAY)) + .append(text(line, GRAY)) + .append(text("]", DARK_GRAY)) .build(); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java index 0b46afd..edbc9cb 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/HeapAnalysisModule.java @@ -28,9 +28,7 @@ import me.lucko.spark.common.command.tabcomplete.TabCompleter; import me.lucko.spark.common.heapdump.HeapDump; import me.lucko.spark.common.heapdump.HeapDumpSummary; import me.lucko.spark.common.util.FormatUtil; -import net.kyori.text.TextComponent; -import net.kyori.text.event.ClickEvent; -import net.kyori.text.format.TextColor; +import net.kyori.adventure.text.event.ClickEvent; import okhttp3.MediaType; import org.tukaani.xz.LZMA2Options; import org.tukaani.xz.LZMAOutputStream; @@ -50,6 +48,9 @@ import java.util.function.Consumer; import java.util.function.LongConsumer; import java.util.zip.GZIPOutputStream; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; + public class HeapAnalysisModule implements CommandModule { private static final MediaType SPARK_HEAP_MEDIA_TYPE = MediaType.parse("application/x-spark-heap"); @@ -61,17 +62,17 @@ public class HeapAnalysisModule implements CommandModule { .executor((platform, sender, resp, arguments) -> { platform.getPlugin().executeAsync(() -> { if (arguments.boolFlag("run-gc-before")) { - resp.broadcastPrefixed(TextComponent.of("Running garbage collector...")); + resp.broadcastPrefixed(text("Running garbage collector...")); System.gc(); } - resp.broadcastPrefixed(TextComponent.of("Creating a new heap dump summary, please wait...")); + resp.broadcastPrefixed(text("Creating a new heap dump summary, please wait...")); HeapDumpSummary heapDump; try { heapDump = HeapDumpSummary.createNew(); } catch (Exception e) { - resp.broadcastPrefixed(TextComponent.of("An error occurred whilst inspecting the heap.", TextColor.RED)); + resp.broadcastPrefixed(text("An error occurred whilst inspecting the heap.", RED)); e.printStackTrace(); return; } @@ -81,16 +82,17 @@ public class HeapAnalysisModule implements CommandModule { String key = SparkPlatform.BYTEBIN_CLIENT.postContent(output, SPARK_HEAP_MEDIA_TYPE, false).key(); String url = SparkPlatform.VIEWER_URL + key; - resp.broadcastPrefixed(TextComponent.of("Heap dump summmary output:", TextColor.GOLD)); - resp.broadcast(TextComponent.builder(url) - .color(TextColor.GRAY) + resp.broadcastPrefixed(text("Heap dump summmary output:", GOLD)); + resp.broadcast(text() + .content(url) + .color(GRAY) .clickEvent(ClickEvent.openUrl(url)) .build() ); platform.getActivityLog().addToLog(Activity.urlActivity(sender, System.currentTimeMillis(), "Heap dump summary", url)); } catch (IOException e) { - resp.broadcastPrefixed(TextComponent.of("An error occurred whilst uploading the data.", TextColor.RED)); + resp.broadcastPrefixed(text("An error occurred whilst uploading the data.", RED)); e.printStackTrace(); } }); @@ -117,22 +119,24 @@ public class HeapAnalysisModule implements CommandModule { boolean liveOnly = !arguments.boolFlag("include-non-live"); if (arguments.boolFlag("run-gc-before")) { - resp.broadcastPrefixed(TextComponent.of("Running garbage collector...")); + resp.broadcastPrefixed(text("Running garbage collector...")); System.gc(); } - resp.broadcastPrefixed(TextComponent.of("Creating a new heap dump, please wait...")); + resp.broadcastPrefixed(text("Creating a new heap dump, please wait...")); try { HeapDump.dumpHeap(file, liveOnly); } catch (Exception e) { - resp.broadcastPrefixed(TextComponent.of("An error occurred whilst creating a heap dump.", TextColor.RED)); + resp.broadcastPrefixed(text("An error occurred whilst creating a heap dump.", RED)); e.printStackTrace(); return; } - resp.broadcastPrefixed(TextComponent.builder("Heap dump written to: ", TextColor.GOLD) - .append(TextComponent.of(file.toString(), TextColor.GRAY)) + resp.broadcastPrefixed(text() + .content("Heap dump written to: ") + .color(GOLD) + .append(text(file.toString(), GRAY)) .build() ); platform.getActivityLog().addToLog(Activity.fileActivity(sender, System.currentTimeMillis(), "Heap dump", file.toString())); @@ -149,7 +153,7 @@ public class HeapAnalysisModule implements CommandModule { } if (compress != null) { - resp.broadcastPrefixed(TextComponent.of("Compressing heap dump, please wait...")); + resp.broadcastPrefixed(text("Compressing heap dump, please wait...")); try { long size = Files.size(file); AtomicLong lastReport = new AtomicLong(System.currentTimeMillis()); @@ -160,14 +164,15 @@ public class HeapAnalysisModule implements CommandModule { lastReport.set(System.currentTimeMillis()); platform.getPlugin().executeAsync(() -> { - resp.broadcastPrefixed(TextComponent.builder("").color(TextColor.GRAY) - .append(TextComponent.of("Compressed ")) - .append(TextComponent.of(FormatUtil.formatBytes(progress), TextColor.GOLD)) - .append(TextComponent.of(" / ")) - .append(TextComponent.of(FormatUtil.formatBytes(size), TextColor.GOLD)) - .append(TextComponent.of(" so far... (")) - .append(TextComponent.of(FormatUtil.percent(progress, size), TextColor.GREEN)) - .append(TextComponent.of(")")) + resp.broadcastPrefixed(text() + .color(GRAY) + .append(text("Compressed ")) + .append(text(FormatUtil.formatBytes(progress), GOLD)) + .append(text(" / ")) + .append(text(FormatUtil.formatBytes(size), GOLD)) + .append(text(" so far... (")) + .append(text(FormatUtil.percent(progress, size), GREEN)) + .append(text(")")) .build() ); }); @@ -177,19 +182,22 @@ public class HeapAnalysisModule implements CommandModule { Path compressedFile = compress.compress(file, progressHandler); long compressedSize = Files.size(compressedFile); - resp.broadcastPrefixed(TextComponent.builder("").color(TextColor.GRAY) - .append(TextComponent.of("Compression complete: ")) - .append(TextComponent.of(FormatUtil.formatBytes(size), TextColor.GOLD)) - .append(TextComponent.of(" --> ")) - .append(TextComponent.of(FormatUtil.formatBytes(compressedSize), TextColor.GOLD)) - .append(TextComponent.of(" (")) - .append(TextComponent.of(FormatUtil.percent(compressedSize, size), TextColor.GREEN)) - .append(TextComponent.of(")")) + resp.broadcastPrefixed(text() + .color(GRAY) + .append(text("Compression complete: ")) + .append(text(FormatUtil.formatBytes(size), GOLD)) + .append(text(" --> ")) + .append(text(FormatUtil.formatBytes(compressedSize), GOLD)) + .append(text(" (")) + .append(text(FormatUtil.percent(compressedSize, size), GREEN)) + .append(text(")")) .build() ); - resp.broadcastPrefixed(TextComponent.builder("Compressed heap dump written to: ", TextColor.GOLD) - .append(TextComponent.of(compressedFile.toString(), TextColor.GRAY)) + resp.broadcastPrefixed(text() + .content("Compressed heap dump written to: ") + .color(GOLD) + .append(text(compressedFile.toString(), GRAY)) .build() ); } catch (IOException e) { diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java index 7a3755b..d9d8b44 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/SamplerModule.java @@ -36,9 +36,7 @@ import me.lucko.spark.common.sampler.ThreadNodeOrder; import me.lucko.spark.common.sampler.node.MergeMode; import me.lucko.spark.common.sampler.tick.TickHook; import me.lucko.spark.common.util.MethodDisambiguator; -import net.kyori.text.TextComponent; -import net.kyori.text.event.ClickEvent; -import net.kyori.text.format.TextColor; +import net.kyori.adventure.text.event.ClickEvent; import okhttp3.MediaType; import java.io.IOException; @@ -51,6 +49,9 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import static net.kyori.adventure.text.Component.*; +import static net.kyori.adventure.text.format.NamedTextColor.*; + public class SamplerModule implements CommandModule { private static final MediaType SPARK_SAMPLER_MEDIA_TYPE = MediaType.parse("application/x-spark-sampler"); @@ -87,38 +88,38 @@ public class SamplerModule implements CommandModule { .executor((platform, sender, resp, arguments) -> { if (arguments.boolFlag("info")) { if (this.activeSampler == null) { - resp.replyPrefixed(TextComponent.of("There isn't an active sampling task running.")); + resp.replyPrefixed(text("There isn't an active sampling task running.")); } else { long timeout = this.activeSampler.getEndTime(); if (timeout == -1) { - resp.replyPrefixed(TextComponent.of("There is an active sampler currently running, with no defined timeout.")); + resp.replyPrefixed(text("There is an active sampler currently running, with no defined timeout.")); } else { long timeoutDiff = (timeout - System.currentTimeMillis()) / 1000L; - resp.replyPrefixed(TextComponent.of("There is an active sampler currently running, due to timeout in " + timeoutDiff + " seconds.")); + resp.replyPrefixed(text("There is an active sampler currently running, due to timeout in " + timeoutDiff + " seconds.")); } long runningTime = (System.currentTimeMillis() - this.activeSampler.getStartTime()) / 1000L; - resp.replyPrefixed(TextComponent.of("It has been sampling for " + runningTime + " seconds so far.")); + resp.replyPrefixed(text("It has been sampling for " + runningTime + " seconds so far.")); } return; } if (arguments.boolFlag("cancel")) { if (this.activeSampler == null) { - resp.replyPrefixed(TextComponent.of("There isn't an active sampling task running.")); + resp.replyPrefixed(text("There isn't an active sampling task running.")); } else { close(); - resp.broadcastPrefixed(TextComponent.of("The active sampling task has been cancelled.", TextColor.GOLD)); + resp.broadcastPrefixed(text("The active sampling task has been cancelled.", GOLD)); } return; } if (arguments.boolFlag("stop") || arguments.boolFlag("upload")) { if (this.activeSampler == null) { - resp.replyPrefixed(TextComponent.of("There isn't an active sampling task running.")); + resp.replyPrefixed(text("There isn't an active sampling task running.")); } else { this.activeSampler.cancel(); - resp.broadcastPrefixed(TextComponent.of("The active sampling operation has been stopped! Uploading results...")); + resp.broadcastPrefixed(text("The active sampling operation has been stopped! Uploading results...")); ThreadNodeOrder threadOrder = arguments.boolFlag("order-by-time") ? ThreadNodeOrder.BY_TIME : ThreadNodeOrder.BY_NAME; String comment = Iterables.getFirst(arguments.stringFlag("comment"), null); MethodDisambiguator methodDisambiguator = new MethodDisambiguator(); @@ -131,13 +132,13 @@ public class SamplerModule implements CommandModule { int timeoutSeconds = arguments.intFlag("timeout"); if (timeoutSeconds != -1 && timeoutSeconds <= 10) { - resp.replyPrefixed(TextComponent.of("The specified timeout is not long enough for accurate results to be formed. " + - "Please choose a value greater than 10.", TextColor.RED)); + resp.replyPrefixed(text("The specified timeout is not long enough for accurate results to be formed. " + + "Please choose a value greater than 10.", RED)); return; } if (timeoutSeconds != -1 && timeoutSeconds < 30) { - resp.replyPrefixed(TextComponent.of("The accuracy of the output will significantly improve when sampling is able to run for longer periods. " + + resp.replyPrefixed(text("The accuracy of the output will significantly improve when sampling is able to run for longer periods. " + "Consider setting a timeout value over 30 seconds.")); } @@ -179,17 +180,17 @@ public class SamplerModule implements CommandModule { if (ticksOver != -1) { tickHook = platform.getTickHook(); if (tickHook == null) { - resp.replyPrefixed(TextComponent.of("Tick counting is not supported!", TextColor.RED)); + resp.replyPrefixed(text("Tick counting is not supported!", RED)); return; } } if (this.activeSampler != null) { - resp.replyPrefixed(TextComponent.of("An active sampler is already running.")); + resp.replyPrefixed(text("An active sampler is already running.")); return; } - resp.broadcastPrefixed(TextComponent.of("Initializing a new profiler, please wait...")); + resp.broadcastPrefixed(text("Initializing a new profiler, please wait...")); SamplerBuilder builder = new SamplerBuilder(); builder.threadDumper(threadDumper); @@ -205,11 +206,11 @@ public class SamplerModule implements CommandModule { } Sampler sampler = this.activeSampler = builder.start(); - resp.broadcastPrefixed(TextComponent.of("Profiler now active!", TextColor.GOLD)); + resp.broadcastPrefixed(text("Profiler now active!", GOLD)); if (timeoutSeconds == -1) { - resp.broadcastPrefixed(TextComponent.of("Use '/" + platform.getPlugin().getCommandName() + " sampler --stop' to stop profiling and upload the results.")); + resp.broadcastPrefixed(text("Use '/" + platform.getPlugin().getCommandName() + " sampler --stop' to stop profiling and upload the results.")); } else { - resp.broadcastPrefixed(TextComponent.of("The results will be automatically returned after the profiler has been running for " + timeoutSeconds + " seconds.")); + resp.broadcastPrefixed(text("The results will be automatically returned after the profiler has been running for " + timeoutSeconds + " seconds.")); } CompletableFuture<Sampler> future = this.activeSampler.getFuture(); @@ -217,7 +218,7 @@ public class SamplerModule implements CommandModule { // send message if profiling fails future.whenCompleteAsync((s, throwable) -> { if (throwable != null) { - resp.broadcastPrefixed(TextComponent.of("Sampling operation failed unexpectedly. Error: " + throwable.toString(), TextColor.RED)); + resp.broadcastPrefixed(text("Sampling operation failed unexpectedly. Error: " + throwable.toString(), RED)); throwable.printStackTrace(); } }); @@ -236,7 +237,7 @@ public class SamplerModule implements CommandModule { MethodDisambiguator methodDisambiguator = new MethodDisambiguator(); MergeMode mergeMode = arguments.boolFlag("separate-parent-calls") ? MergeMode.separateParentCalls(methodDisambiguator) : MergeMode.sameMethod(methodDisambiguator); future.thenAcceptAsync(s -> { - resp.broadcastPrefixed(TextComponent.of("The active sampling operation has completed! Uploading results...")); + resp.broadcastPrefixed(text("The active sampling operation has completed! Uploading results...")); handleUpload(platform, resp, s, threadOrder, comment, mergeMode); }); } @@ -272,16 +273,17 @@ public class SamplerModule implements CommandModule { String key = SparkPlatform.BYTEBIN_CLIENT.postContent(output, SPARK_SAMPLER_MEDIA_TYPE, false).key(); String url = SparkPlatform.VIEWER_URL + key; - resp.broadcastPrefixed(TextComponent.of("Sampling results:", TextColor.GOLD)); - resp.broadcast(TextComponent.builder(url) - .color(TextColor.GRAY) + resp.broadcastPrefixed(text("Sampling results:", GOLD)); + resp.broadcast(text() + .content(url) + .color(GRAY) .clickEvent(ClickEvent.openUrl(url)) .build() ); platform.getActivityLog().addToLog(Activity.urlActivity(resp.sender(), System.currentTimeMillis(), "Sampler", url)); } catch (IOException e) { - resp.broadcastPrefixed(TextComponent.of("An error occurred whilst uploading the results.", TextColor.RED)); + resp.broadcastPrefixed(text("An error occurred whilst uploading the results.", RED)); e.printStackTrace(); } }); diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java index bef5d78..043bc65 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java @@ -28,12 +28,13 @@ import me.lucko.spark.common.command.tabcomplete.TabCompleter; import me.lucko.spark.common.monitor.tick.TickMonitor; import me.lucko.spark.common.monitor.tick.TickMonitor.ReportPredicate; import me.lucko.spark.common.sampler.tick.TickHook; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import java.util.function.Consumer; +import static net.kyori.adventure.text.Component.*; + public class TickMonitoringModule implements CommandModule { /** The tick hook instance currently running, if any */ @@ -61,7 +62,7 @@ public class TickMonitoringModule implements CommandModule { this.tickHook = platform.getTickHook(); } if (this.tickHook == null) { - resp.replyPrefixed(TextComponent.of("Not supported!", TextColor.RED)); + resp.replyPrefixed(text("Not supported!", NamedTextColor.RED)); return; } @@ -81,7 +82,7 @@ public class TickMonitoringModule implements CommandModule { this.tickHook.addCallback(this.activeTickMonitor); } else { close(); - resp.broadcastPrefixed(TextComponent.of("Tick monitor disabled.")); + resp.broadcastPrefixed(text("Tick monitor disabled.")); } }) .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--threshold", "--threshold-tick", "--without-gc")) diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/sender/CommandSender.java b/spark-common/src/main/java/me/lucko/spark/common/command/sender/CommandSender.java index ef56185..b10c7d8 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/sender/CommandSender.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/sender/CommandSender.java @@ -24,7 +24,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import me.lucko.spark.proto.SparkProtos.CommandSenderData; -import net.kyori.text.Component; +import net.kyori.adventure.text.Component; import java.util.UUID; |