forked from ChomeNS/chomens-bot-java
msuic thread bring back.
This commit is contained in:
parent
857884bcf4
commit
232fa0a2bb
3 changed files with 16 additions and 9 deletions
|
@ -95,6 +95,8 @@ public class MusicCommand extends Command {
|
|||
public Component play (CommandContext context) throws CommandException {
|
||||
final MusicPlayerPlugin player = context.bot.music;
|
||||
|
||||
if (player.loaderThread != null) throw new CommandException(Component.text("Already loading a song"));
|
||||
|
||||
String _path;
|
||||
Path path;
|
||||
try {
|
||||
|
|
|
@ -9,7 +9,7 @@ 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;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.SongLoaderRunnable;
|
||||
import land.chipmunk.chayapak.chomens_bot.song.SongLoaderThread;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.MathUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -43,7 +43,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
|
||||
public Song currentSong;
|
||||
public final List<Song> songQueue = new ArrayList<>();
|
||||
public SongLoaderRunnable loaderThread;
|
||||
public SongLoaderThread loaderThread = null;
|
||||
public Loop loop = Loop.OFF;
|
||||
|
||||
// sus nightcore stuff,..,.,.
|
||||
|
@ -74,7 +74,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
public void loadSong (Path location, PlayerEntry sender) {
|
||||
if (songQueue.size() > 100) return;
|
||||
|
||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot, sender.profile.getName());
|
||||
loaderThread = new SongLoaderThread(location, bot, sender.profile.getName());
|
||||
|
||||
bot.chat.tellraw(
|
||||
Component
|
||||
|
@ -85,7 +85,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor))
|
||||
);
|
||||
|
||||
bot.executorService.submit(runnable);
|
||||
loaderThread.start();
|
||||
}
|
||||
|
||||
public void loadSong (URL location, PlayerEntry sender) {
|
||||
|
@ -98,7 +98,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
final SongLoaderRunnable runnable = new SongLoaderRunnable(location, bot, sender.profile.getName());
|
||||
loaderThread = new SongLoaderThread(location, bot, sender.profile.getName());
|
||||
|
||||
bot.chat.tellraw(
|
||||
Component
|
||||
|
@ -109,7 +109,7 @@ public class MusicPlayerPlugin extends Bot.Listener {
|
|||
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor))
|
||||
);
|
||||
|
||||
bot.executorService.submit(runnable);
|
||||
loaderThread.start();
|
||||
}
|
||||
|
||||
public void coreReady () {
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.stream.Stream;
|
|||
|
||||
// Author: _ChipMC_ or hhhzzzsss? also i modified it to use runnable
|
||||
// because thread = bad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
public class SongLoaderRunnable implements Runnable {
|
||||
public class SongLoaderThread extends Thread {
|
||||
// should the converters be here?
|
||||
public static final List<Converter> converters = new ArrayList<>();
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class SongLoaderRunnable implements Runnable {
|
|||
|
||||
private boolean isFolder = false;
|
||||
|
||||
public SongLoaderRunnable(URL location, Bot bot, String requester) {
|
||||
public SongLoaderThread(URL location, Bot bot, String requester) {
|
||||
this.bot = bot;
|
||||
this.requester = requester;
|
||||
isUrl = true;
|
||||
|
@ -51,7 +51,7 @@ public class SongLoaderRunnable implements Runnable {
|
|||
fileName = location.getFile();
|
||||
}
|
||||
|
||||
public SongLoaderRunnable(Path location, Bot bot, String requester) {
|
||||
public SongLoaderThread(Path location, Bot bot, String requester) {
|
||||
this.bot = bot;
|
||||
this.requester = requester;
|
||||
isUrl = false;
|
||||
|
@ -62,6 +62,7 @@ public class SongLoaderRunnable implements Runnable {
|
|||
fileName = location.getFileName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run () {
|
||||
if (isFolder && !isUrl) {
|
||||
try (Stream<Path> files = Files.list(songPath)) {
|
||||
|
@ -80,6 +81,8 @@ public class SongLoaderRunnable implements Runnable {
|
|||
}
|
||||
|
||||
private void processFile () {
|
||||
if (bot.music.songQueue.size() > 100) return;
|
||||
|
||||
byte[] bytes;
|
||||
String name;
|
||||
try {
|
||||
|
@ -119,6 +122,8 @@ public class SongLoaderRunnable implements Runnable {
|
|||
|
||||
if (!isFolder) showAddedToQueue();
|
||||
}
|
||||
|
||||
bot.music.loaderThread = null;
|
||||
}
|
||||
|
||||
private void showAddedToQueue () {
|
Loading…
Reference in a new issue