Finally fix the ohio code in Song and move isNotNullAndNotBlank to StringUtilities

This commit is contained in:
Chayapak 2024-10-25 17:59:11 +07:00
parent eaa42d40a3
commit 42cb149e26
3 changed files with 25 additions and 29 deletions

View file

@ -31,6 +31,8 @@ import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank;
public class MusicCommand extends Command { public class MusicCommand extends Command {
private Path root; private Path root;
@ -599,12 +601,12 @@ public class MusicCommand extends Command {
final TextColor keyColor = ColorUtilities.getColorByString(bot.config.colorPalette.secondary); final TextColor keyColor = ColorUtilities.getColorByString(bot.config.colorPalette.secondary);
final TextColor valueColor = ColorUtilities.getColorByString(bot.config.colorPalette.string); 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 (isNotNullAndNotBlank(currentSong.name)) 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 (isNotNullAndNotBlank(currentSong.requester)) 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 (isNotNullAndNotBlank(currentSong.songAuthor)) 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 (isNotNullAndNotBlank(currentSong.songOriginalAuthor)) 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 (isNotNullAndNotBlank(currentSong.tracks)) 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.songDescription)) components.add(Component.translatable("Description: %s", Component.text(currentSong.songDescription).color(valueColor)).color(keyColor));
return Component.join(JoinConfiguration.newlines(), components); return Component.join(JoinConfiguration.newlines(), components);
} }

View file

@ -4,6 +4,8 @@ import me.chayapak1.chomens_bot.Bot;
import java.util.*; import java.util.*;
import static me.chayapak1.chomens_bot.util.StringUtilities.isNotNullAndNotBlank;
// Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff // Author: hhhzzzsss & _ChipMC_ but i changed most of the stuff
public class Song { public class Song {
public final ArrayList<Note> notes = new ArrayList<>(); public final ArrayList<Note> notes = new ArrayList<>();
@ -47,30 +49,18 @@ public class Song {
} }
public void updateName() { public void updateName() {
// real ohio code String authorPart = null;
// TODO: clean this up
if (isNotNullAndNotBlank(songOriginalAuthor) && !isNotNullAndNotBlank(songAuthor)) name = String.format( if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) {
"%s - %s", authorPart = String.format("%s/%s", songOriginalAuthor, songAuthor);
songOriginalAuthor, } else if (isNotNullAndNotBlank(songOriginalAuthor)) {
isNotNullAndNotBlank(songName) ? songName : originalName authorPart = songOriginalAuthor;
); } else if (isNotNullAndNotBlank(songAuthor)) {
else if (!isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) name = String.format( authorPart = songAuthor;
"%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;
} }
// should this be in idk, util? String namePart = isNotNullAndNotBlank(songName) ? songName : originalName;
private boolean isNotNullAndNotBlank (String text) { name = (authorPart != null) ? String.format("%s - %s", authorPart, namePart) : namePart;
return text != null && !text.isBlank();
} }
public Note get (int i) { public Note get (int i) {

View file

@ -50,4 +50,8 @@ public class StringUtilities {
return false; return false;
} }
public static boolean isNotNullAndNotBlank (String text) {
return text != null && !text.isBlank();
}
} }