From bf9f29ffe9023c4ed879c5883d1d842cecb6335c Mon Sep 17 00:00:00 2001 From: William Date: Tue, 26 Dec 2023 14:41:39 +0000 Subject: [PATCH] refactor: Improve display of `/husksync status` --- .../husksync/command/HuskSyncCommand.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java b/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java index 2b084a8a..de0696e6 100644 --- a/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java +++ b/common/src/main/java/net/william278/husksync/command/HuskSyncCommand.java @@ -23,6 +23,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.event.HoverEvent; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; import net.william278.desertwell.about.AboutMenu; import net.william278.desertwell.util.UpdateChecker; @@ -196,7 +197,7 @@ public List suggest(@NotNull CommandUser user, @NotNull String[] args) { private enum StatusLine { PLUGIN_VERSION(plugin -> Component.text("v" + plugin.getPluginVersion().toStringWithoutMetadata()) - .append(plugin.getPluginVersion().getMetadata().isBlank() ? Component.empty() + .appendSpace().append(plugin.getPluginVersion().getMetadata().isBlank() ? Component.empty() : Component.text("(build " + plugin.getPluginVersion().getMetadata() + ")"))), PLATFORM_TYPE(plugin -> Component.text(WordUtils.capitalizeFully(plugin.getPlatformType()))), LANGUAGE(plugin -> Component.text(plugin.getSettings().getLanguage())), @@ -208,15 +209,17 @@ private enum StatusLine { SERVER_NAME(plugin -> Component.text(plugin.getServerName())), DATABASE_TYPE(plugin -> Component.text(plugin.getSettings().getDatabaseType().getDisplayName())), IS_DATABASE_LOCAL(plugin -> getLocalhostBoolean(plugin.getSettings().getMySqlHost())), - IS_REDIS_SENTINEL(plugin -> getBoolean(!plugin.getSettings().getRedisSentinelMaster().isBlank())), - IS_REDIS_PASSWORD(plugin -> getBoolean(!plugin.getSettings().getRedisPassword().isBlank())), - IS_REDIS_SSL(plugin -> getBoolean(plugin.getSettings().redisUseSsl())), + USING_REDIS_SENTINEL(plugin -> getBoolean(!plugin.getSettings().getRedisSentinelMaster().isBlank())), + USING_REDIS_PASSWORD(plugin -> getBoolean(!plugin.getSettings().getRedisPassword().isBlank())), + REDIS_USING_SSL(plugin -> getBoolean(plugin.getSettings().redisUseSsl())), IS_REDIS_LOCAL(plugin -> getLocalhostBoolean(plugin.getSettings().getRedisHost())), DATA_TYPES(plugin -> Component.join( JoinConfiguration.commas(true), plugin.getRegisteredDataTypes().stream().map(i -> { boolean enabled = plugin.getSettings().isSyncFeatureEnabled(i); - return Component.text(i.toString(), TextColor.color(enabled ? 0x00ff00 : 0xff0000)) + return Component.textOfChildren(Component + .text(i.toString()).appendSpace().append(Component.text(enabled ? '✔' : '❌'))) + .color(enabled ? NamedTextColor.GREEN : NamedTextColor.RED) .hoverEvent(HoverEvent.showText(Component.text(enabled ? "Enabled" : "Disabled"))); }).toList() )); @@ -229,17 +232,19 @@ private enum StatusLine { @NotNull private Component get(@NotNull HuskSync plugin) { - return Component.text( + return Component + .text("•").appendSpace() + .append(Component.text( WordUtils.capitalizeFully(name().replaceAll("_", " ")), TextColor.color(0x848484) - ) - .append(Component.text(':')).append(Component.space()) + )) + .append(Component.text(':')).append(Component.space().color(NamedTextColor.WHITE)) .append(supplier.apply(plugin)); } @NotNull private static Component getBoolean(boolean value) { - return Component.text(value ? "Yes" : "No", TextColor.color(value ? 0x00ff00 : 0xff0000)); + return Component.text(value ? "Yes" : "No", value ? NamedTextColor.GREEN : NamedTextColor.RED); } @NotNull