improve music info + add song requester
This commit is contained in:
parent
ee27f874c0
commit
5856429708
4 changed files with 29 additions and 25 deletions
|
@ -18,6 +18,7 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -102,7 +103,7 @@ public class MusicCommand extends Command {
|
|||
|
||||
path = Path.of(root.toString(), _path);
|
||||
|
||||
if (path.toString().contains("http")) player.loadSong(new URL(_path));
|
||||
if (path.toString().contains("http")) player.loadSong(new URL(_path), context.sender);
|
||||
else {
|
||||
// among us protection!!!11
|
||||
if (!path.normalize().startsWith(root.toString())) throw new CommandException(Component.text("no"));
|
||||
|
@ -137,7 +138,7 @@ public class MusicCommand extends Command {
|
|||
|
||||
final String file = matchedArray[0];
|
||||
|
||||
player.loadSong(Path.of(realPath.toString(), file));
|
||||
player.loadSong(Path.of(realPath.toString(), file), context.sender);
|
||||
} catch (CommandException e) {
|
||||
throw e;
|
||||
} catch (NoSuchFileException e) {
|
||||
|
@ -163,7 +164,7 @@ public class MusicCommand extends Command {
|
|||
|
||||
final String file = matchedArray[0];
|
||||
|
||||
player.loadSong(Path.of(root.toString(), file));
|
||||
player.loadSong(Path.of(root.toString(), file), context.sender);
|
||||
} catch (CommandException e) {
|
||||
throw e;
|
||||
} catch (NoSuchFileException e) {
|
||||
|
@ -433,23 +434,18 @@ public class MusicCommand extends Command {
|
|||
|
||||
if (currentSong == null) throw new CommandException(Component.text("No song is currently playing"));
|
||||
|
||||
// ig very code yup
|
||||
final String title = currentSong.name;
|
||||
final String songAuthor = currentSong.songAuthor == null || currentSong.songAuthor.equals("") ? "N/A" : currentSong.songAuthor;
|
||||
final String songOriginalAuthor = currentSong.songOriginalAuthor == null || currentSong.songOriginalAuthor.equals("") ? "N/A" : currentSong.songOriginalAuthor;
|
||||
final String songDescription = currentSong.songDescription == null || currentSong.songDescription.equals("") ? "N/A" : currentSong.songDescription;
|
||||
final List<Component> components = new ArrayList<>();
|
||||
|
||||
return Component.translatable(
|
||||
"""
|
||||
Title/Filename: %s
|
||||
Author: %s
|
||||
Original author: %s
|
||||
Description: %s""",
|
||||
Component.text(title).color(NamedTextColor.AQUA),
|
||||
Component.text(songAuthor).color(NamedTextColor.AQUA),
|
||||
Component.text(songOriginalAuthor).color(NamedTextColor.AQUA),
|
||||
Component.text(songDescription).color(NamedTextColor.AQUA)
|
||||
).color(NamedTextColor.GOLD);
|
||||
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.songDescription != null && !currentSong.songDescription.isBlank()) components.add(Component.translatable("Description: %s", Component.text(currentSong.songDescription).color(valueColor)).color(keyColor));
|
||||
|
||||
return Component.join(JoinConfiguration.newlines(), components);
|
||||
}
|
||||
|
||||
public Component testSong (CommandContext context) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
|
|||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.BotBossBar;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.Loop;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.Note;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.Song;
|
||||
|
@ -67,10 +68,10 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
bot.executor.scheduleAtFixedRate(() -> limit = 0, 0, bot.config.music.urlRatelimit.seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void loadSong (Path location) {
|
||||
public void loadSong (Path location, PlayerEntry sender) {
|
||||
if (songQueue.size() > 100) return;
|
||||
|
||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot);
|
||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot, sender.profile.getName());
|
||||
|
||||
bot.chat.tellraw(
|
||||
Component
|
||||
|
@ -84,7 +85,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
bot.executorService.submit(runnable);
|
||||
}
|
||||
|
||||
public void loadSong (URL location) {
|
||||
public void loadSong (URL location, PlayerEntry sender) {
|
||||
if (songQueue.size() > 100) return;
|
||||
|
||||
limit++;
|
||||
|
@ -94,7 +95,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot);
|
||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot, sender.profile.getName());
|
||||
|
||||
bot.chat.tellraw(
|
||||
Component
|
||||
|
|
|
@ -10,6 +10,7 @@ public class Song {
|
|||
public final ArrayList<Note> notes = new ArrayList<>();
|
||||
public final String originalName;
|
||||
public final String name;
|
||||
public String requester = "Unknown";
|
||||
public int position = 0; // Current note index
|
||||
public boolean paused = true;
|
||||
public long startTime = 0; // Start time in millis since unix epoch
|
||||
|
|
|
@ -36,20 +36,24 @@ public class SongLoaderRunnable implements Runnable {
|
|||
|
||||
private final Bot bot;
|
||||
|
||||
private final String requester;
|
||||
|
||||
private final boolean isUrl;
|
||||
|
||||
private boolean isFolder = false;
|
||||
|
||||
public SongLoaderRunnable(URL location, Bot bot) {
|
||||
public SongLoaderRunnable(URL location, Bot bot, String requester) {
|
||||
this.bot = bot;
|
||||
this.requester = requester;
|
||||
isUrl = true;
|
||||
songUrl = location;
|
||||
|
||||
fileName = location.getFile();
|
||||
}
|
||||
|
||||
public SongLoaderRunnable(Path location, Bot bot) {
|
||||
public SongLoaderRunnable(Path location, Bot bot, String requester) {
|
||||
this.bot = bot;
|
||||
this.requester = requester;
|
||||
isUrl = false;
|
||||
songPath = location;
|
||||
|
||||
|
@ -109,6 +113,8 @@ public class SongLoaderRunnable implements Runnable {
|
|||
|
||||
failed();
|
||||
} else {
|
||||
song.requester = requester;
|
||||
|
||||
bot.music.songQueue.add(song);
|
||||
|
||||
if (!isFolder) showAddedToQueue();
|
||||
|
|
Loading…
Reference in a new issue