diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java index bcaacaa..bedbe59 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/MusicCommand.java @@ -31,6 +31,8 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank; + public class MusicCommand extends Command { private Path root; @@ -599,12 +601,12 @@ public class MusicCommand extends Command { final TextColor keyColor = ColorUtilities.getColorByString(bot.config.colorPalette.secondary); final TextColor valueColor = ColorUtilities.getColorByString(bot.config.colorPalette.string); - if (currentSong.name != null) components.add(Component.translatable("Title/Filename: %s", Component.text(currentSong.name).color(valueColor)).color(keyColor)); - if (currentSong.requester != null) components.add(Component.translatable("Requester: %s", Component.text(currentSong.requester).color(valueColor)).color(keyColor)); - if (currentSong.songAuthor != null && !currentSong.songAuthor.isBlank()) components.add(Component.translatable("Author: %s", Component.text(currentSong.songAuthor).color(valueColor)).color(keyColor)); - if (currentSong.songOriginalAuthor != null && !currentSong.songOriginalAuthor.isBlank()) components.add(Component.translatable("Original author: %s", Component.text(currentSong.songOriginalAuthor).color(valueColor)).color(keyColor)); - if (currentSong.tracks != null && !currentSong.tracks.isBlank()) components.add(Component.translatable("Tracks: %s", Component.text(currentSong.tracks).color(valueColor)).color(keyColor)); - if (currentSong.songDescription != null && !currentSong.songDescription.isBlank()) components.add(Component.translatable("Description: %s", Component.text(currentSong.songDescription).color(valueColor)).color(keyColor)); + if (isNotNullAndNotBlank(currentSong.name)) components.add(Component.translatable("Title/Filename: %s", Component.text(currentSong.name).color(valueColor)).color(keyColor)); + if (isNotNullAndNotBlank(currentSong.requester)) components.add(Component.translatable("Requester: %s", Component.text(currentSong.requester).color(valueColor)).color(keyColor)); + if (isNotNullAndNotBlank(currentSong.songAuthor)) components.add(Component.translatable("Author: %s", Component.text(currentSong.songAuthor).color(valueColor)).color(keyColor)); + if (isNotNullAndNotBlank(currentSong.songOriginalAuthor)) components.add(Component.translatable("Original author: %s", Component.text(currentSong.songOriginalAuthor).color(valueColor)).color(keyColor)); + if (isNotNullAndNotBlank(currentSong.tracks)) components.add(Component.translatable("Tracks: %s", Component.text(currentSong.tracks).color(valueColor)).color(keyColor)); + if (isNotNullAndNotBlank(currentSong.songDescription)) components.add(Component.translatable("Description: %s", Component.text(currentSong.songDescription).color(valueColor)).color(keyColor)); return Component.join(JoinConfiguration.newlines(), components); } diff --git a/src/main/java/me/chayapak1/chomens_bot/song/Song.java b/src/main/java/me/chayapak1/chomens_bot/song/Song.java index 47ee7e5..1451a73 100644 --- a/src/main/java/me/chayapak1/chomens_bot/song/Song.java +++ b/src/main/java/me/chayapak1/chomens_bot/song/Song.java @@ -4,6 +4,8 @@ import me.chayapak1.chomens_bot.Bot; import java.util.*; +import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank; + // Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff public class Song { public final ArrayList notes = new ArrayList<>(); @@ -47,30 +49,18 @@ public class Song { } public void updateName() { - // real ohio code - // TODO: clean this up - if (isNotNullAndNotBlank(songOriginalAuthor) && !isNotNullAndNotBlank(songAuthor)) name = String.format( - "%s - %s", - songOriginalAuthor, - isNotNullAndNotBlank(songName) ? songName : originalName - ); - else if (!isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format( - "%s - %s", - songAuthor, - isNotNullAndNotBlank(songName) ? songName : originalName - ); - else if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format( - "%s/%s - %s", - songOriginalAuthor, - songAuthor, - isNotNullAndNotBlank(songName) ? songName : originalName - ); - else name = isNotNullAndNotBlank(songName) ? songName : originalName; - } + String authorPart = null; - // should this be in idk, util? - private boolean isNotNullAndNotBlank (String text) { - return text != null && !text.isBlank(); + if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) { + authorPart = String.format("%s/%s", songOriginalAuthor, songAuthor); + } else if (isNotNullAndNotBlank(songOriginalAuthor)) { + authorPart = songOriginalAuthor; + } else if (isNotNullAndNotBlank(songAuthor)) { + authorPart = songAuthor; + } + + String namePart = isNotNullAndNotBlank(songName) ? songName : originalName; + name = (authorPart != null) ? String.format("%s - %s", authorPart, namePart) : namePart; } public Note get (int i) { diff --git a/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java b/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java index af8ff81..478b038 100644 --- a/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java +++ b/src/main/java/me/chayapak1/chomens_bot/util/StringUtilities.java @@ -50,4 +50,8 @@ public class StringUtilities { return false; } + + public static boolean isNotNullAndNotBlank (String text) { + return text != null && !text.isBlank(); + } }