diff options
author | Luck <git@lucko.me> | 2021-12-21 20:47:48 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2021-12-21 20:47:48 +0000 |
commit | a7a534cdbb4dd6c8180cf857bbf846ee4c6fc2f8 (patch) | |
tree | dab717e8a3ef85a6d7971cdfebda408bbd9833c2 /spark-common/src | |
parent | 425b53578481fe95837ab3d932ce2fd6af00db28 (diff) | |
download | spark-a7a534cdbb4dd6c8180cf857bbf846ee4c6fc2f8.tar.gz spark-a7a534cdbb4dd6c8180cf857bbf846ee4c6fc2f8.tar.bz2 spark-a7a534cdbb4dd6c8180cf857bbf846ee4c6fc2f8.zip |
Combine long messages into one component
Diffstat (limited to 'spark-common/src')
4 files changed, 15 insertions, 8 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 1acb3dc..a9e2229 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 @@ -24,6 +24,7 @@ import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.command.sender.CommandSender; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.TextComponent; import java.util.Set; @@ -81,10 +82,20 @@ public class CommandResponseHandler { this.sender.sendMessage(message); } + public void reply(Iterable<Component> message) { + Component joinedMsg = Component.join(JoinConfiguration.separator(Component.newline()), message); + this.sender.sendMessage(joinedMsg); + } + public void broadcast(Component message) { allSenders(sender -> sender.sendMessage(message)); } + public void broadcast(Iterable<Component> message) { + Component joinedMsg = Component.join(JoinConfiguration.separator(Component.newline()), message); + allSenders(sender -> sender.sendMessage(joinedMsg)); + } + public void replyPrefixed(Component message) { reply(applyPrefix(message)); } 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 4268b25..b777f3e 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 @@ -119,7 +119,7 @@ public class ActivityLogModule implements CommandModule, RowRenderer<Activity> { this, value -> "/" + platform.getPlugin().getCommandName() + " activity --page " + value ); - activityPagination.render(log, page).forEach(resp::reply); + resp.reply(activityPagination.render(log, page)); }) .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--page")) .build() 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 88d4169..2ce83fd 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 @@ -132,7 +132,7 @@ public class GcMonitoringModule implements CommandModule { if (collectorStats.isEmpty()) { resp.replyPrefixed(text("No garbage collectors are reporting data.")); } else { - report.forEach(resp::reply); + resp.reply(report); } }) .build() @@ -183,10 +183,6 @@ public class GcMonitoringModule implements CommandModule { addListener(this); } - protected void sendMessage(Component message) { - this.resp.broadcastPrefixed(message); - } - @Override public void onGc(GarbageCollectionNotificationInfo data) { String gcType = GarbageCollectionMonitor.getGcType(data); @@ -259,7 +255,7 @@ public class GcMonitoringModule implements CommandModule { } } - report.forEach(this.resp::broadcast); + this.resp.broadcast(report); }); } 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 d6c0e10..51fa905 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 @@ -156,7 +156,7 @@ public class HealthModule implements CommandModule { e.printStackTrace(); } - report.forEach(resp::reply); + resp.reply(report); } private static void addTickStats(List<Component> report, TickStatistics tickStatistics) { |