forked from ChomeNS/chomens-bot-java
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.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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(
|
|
||||||
"%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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should this be in idk, util?
|
if (isNotNullAndNotBlank(songOriginalAuthor) && isNotNullAndNotBlank(songAuthor)) {
|
||||||
private boolean isNotNullAndNotBlank (String text) {
|
authorPart = String.format("%s/%s", songOriginalAuthor, songAuthor);
|
||||||
return text != null && !text.isBlank();
|
} 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) {
|
public Note get (int i) {
|
||||||
|
|
|
@ -50,4 +50,8 @@ public class StringUtilities {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNotNullAndNotBlank (String text) {
|
||||||
|
return text != null && !text.isBlank();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue