diff --git a/common/src/main/java/net/william278/husksync/config/Locales.java b/common/src/main/java/net/william278/husksync/config/Locales.java index feea3732..e6c24906 100644 --- a/common/src/main/java/net/william278/husksync/config/Locales.java +++ b/common/src/main/java/net/william278/husksync/config/Locales.java @@ -121,6 +121,21 @@ public class Locales { return value.toString(); } + /** + * Truncates a String to a specified length, and appends an ellipsis if it is longer than the specified length + * + * @param string The string to truncate + * @param length The maximum length of the string + * @return The truncated string + */ + @NotNull + public static String truncate(@NotNull String string, int length) { + if (string.length() > length) { + return string.substring(0, length) + "…"; + } + return string; + } + /** * Returns the base list options to use for a paginated chat list * diff --git a/common/src/main/java/net/william278/husksync/data/DataSaveCause.java b/common/src/main/java/net/william278/husksync/data/DataSaveCause.java index 86502db2..c99d7f71 100644 --- a/common/src/main/java/net/william278/husksync/data/DataSaveCause.java +++ b/common/src/main/java/net/william278/husksync/data/DataSaveCause.java @@ -1,5 +1,6 @@ package net.william278.husksync.data; +import net.william278.husksync.config.Locales; import net.william278.husksync.player.OnlineUser; import net.william278.husksync.api.BaseHuskSyncAPI; import net.william278.husksync.player.User; @@ -100,4 +101,9 @@ public enum DataSaveCause { return UNKNOWN; } + @NotNull + public String getDisplayName() { + return Locales.truncate(name().toLowerCase(), 10); + } + } diff --git a/common/src/main/java/net/william278/husksync/util/DataSnapshotList.java b/common/src/main/java/net/william278/husksync/util/DataSnapshotList.java index 96137667..977fb684 100644 --- a/common/src/main/java/net/william278/husksync/util/DataSnapshotList.java +++ b/common/src/main/java/net/william278/husksync/util/DataSnapshotList.java @@ -32,7 +32,7 @@ public class DataSnapshotList { .format(snapshot.versionTimestamp()), snapshot.versionUUID().toString().split("-")[0], snapshot.versionUUID().toString(), - snapshot.cause().name().toLowerCase().replaceAll("_", " "), + snapshot.cause().getDisplayName(), dataOwner.username, snapshot.pinned() ? "※" : " ") .orElse("• " + snapshot.versionUUID())).toList(),