Finally fix the ohio code in Song and move isNotNullAndNotBlank to StringUtilities
This commit is contained in:
parent
eaa42d40a3
commit
42cb149e26
3 changed files with 25 additions and 29 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Note> 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;
|
||||
|
||||
if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) {
|
||||
authorPart = String.format("%s/%s", songOriginalAuthor, songAuthor);
|
||||
} else if (isNotNullAndNotBlank(songOriginalAuthor)) {
|
||||
authorPart = songOriginalAuthor;
|
||||
} else if (isNotNullAndNotBlank(songAuthor)) {
|
||||
authorPart = songAuthor;
|
||||
}
|
||||
|
||||
// should this be in idk, util?
|
||||
private boolean isNotNullAndNotBlank (String text) {
|
||||
return text != null && !text.isBlank();
|
||||
String namePart = isNotNullAndNotBlank(songName) ? songName : originalName;
|
||||
name = (authorPart != null) ? String.format("%s - %s", authorPart, namePart) : namePart;
|
||||
}
|
||||
|
||||
public Note get (int i) {
|
||||
|
|
|
@ -50,4 +50,8 @@ public class StringUtilities {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNotNullAndNotBlank (String text) {
|
||||
return text != null && !text.isBlank();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue