(A tester)

Refonte complète du système de jukebox et de menu.
This commit is contained in:
2021-10-05 11:04:35 +02:00
parent 97abc9a184
commit 43145071f1
6 changed files with 28 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package fr.Skydust.JdrBot.cmds.playmusic;
import java.util.HashMap;
import java.util.Map;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioTrack;
import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
import fr.Skydust.JdrBot.stock.Command;
import net.dv8tion.jda.api.Permission;
@@ -24,6 +25,8 @@ public class PlayMusic extends Command {
private static final AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
static Map<Long, GuildMusicManager> musicManagers;
public static Map<Long, JukeboxSystem> jukeboxSystems;
public PlayMusic() {
musicManagers = new HashMap<>();
AudioSourceManagers.registerRemoteSources(playerManager);
@@ -39,17 +42,22 @@ public class PlayMusic extends Command {
return;
}
//TODO: MAKE SURE ONLY ONE JUKEBOX PER GUILD
if(JukeboxGUISystem.getGuildsJukebox(e.getGuild()) != null) {
if(getGuildsJukebox(e.getGuild()) != null) {
e.getChannel().sendMessage("/!\\ Le lecteur audio est deja present ici ! Pour l'arreter, tapez \"!stopmusic\" !").queue();
return;
}
e.getChannel().sendMessage("Loading...").queue(JukeboxSystem::new);
//TODO: WHILE LOADING, CAN CALL AGAIN
// Creates a message to be edited by the jukebox system
e.getChannel().sendMessage("Loading...").queue(msg -> jukeboxSystems.put(e.getGuild().getIdLong(), new JukeboxSystem(msg)));
}
public static JukeboxSystem getGuildsJukebox(Guild guild) {
return jukeboxSystems.get(guild.getIdLong());
}
public static void loadAndPlay(final TextChannel channel, final String trackUrl, boolean loop, boolean nomsg) {
System.out.println(trackUrl);
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override

View File

@@ -1,6 +1,7 @@
package fr.Skydust.JdrBot.cmds.playmusic;
import fr.Skydust.JdrBot.cmds.record.Record;
import fr.Skydust.JdrBot.jukebox.JukeboxSystem;
import fr.Skydust.JdrBot.stock.Command;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
@@ -36,14 +37,14 @@ public class StopMusic extends Command {
}
public static void stopMusic(Guild g) {
JukeboxGUI gui = JukeboxGUISystem.getGuildsJukebox(g);
JukeboxSystem jukebox = PlayMusic.getGuildsJukebox(g);
if(gui != null) {
g.getTextChannelById(gui.TextChannelID).deleteMessageById(gui.MessageID)
.queue(msg -> {
JukeboxGUISystem.setGuildsJukebox(g, null);
});
if(jukebox != null) {
jukebox.jukeboxMessage.delete().queue();
}
PlayMusic.jukeboxSystems.put(g.getIdLong(), null);
PlayMusic.getGuildAudioPlayer(g).scheduler.stop();
if(!Record.getGuildRecordState(g).isRecording) {

View File

@@ -1,5 +1,6 @@
package fr.Skydust.JdrBot.cmds.record;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.stock.Command;
import fr.Skydust.JdrBot.stock.RecordState;
import fr.Skydust.JdrBot.utils.MessageType;
@@ -16,7 +17,7 @@ public class CancelRecord extends Command {
public void call(GuildMessageReceivedEvent e) {
RecordState rs = Record.getGuildRecordState(e.getGuild());
if(rs.isRecording) {
if(JukeboxGUISystem.getGuildsJukebox(e.getGuild()) == null) {
if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) {
e.getGuild().getAudioManager().closeAudioConnection();
}
rs.cancelRecord(e.getGuild());

View File

@@ -1,5 +1,6 @@
package fr.Skydust.JdrBot.cmds.record;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.stock.Command;
import fr.Skydust.JdrBot.stock.RecordState;
import fr.Skydust.JdrBot.utils.MessageType;
@@ -16,7 +17,7 @@ public class StopRecord extends Command {
public void call(GuildMessageReceivedEvent e) {
RecordState rs = Record.getGuildRecordState(e.getGuild());
if(rs.isRecording) {
if(JukeboxGUISystem.getGuildsJukebox(e.getGuild()) == null) {
if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) {
e.getGuild().getAudioManager().closeAudioConnection();
}
rs.endRecord(e.getGuild(), e.getChannel());

View File

@@ -6,7 +6,6 @@ import fr.Skydust.JdrBot.menu.Menu;
import fr.Skydust.JdrBot.menu.MenuSystem;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.io.File;
import java.util.*;
@@ -22,7 +21,7 @@ public class JukeboxSystem {
public String songPlayedPath = "";
private final HashMap<String, Menu> linkedPath = new HashMap<>();
private final Message jukeboxMessage;
public final Message jukeboxMessage;
private String currentFolder = "";

View File

@@ -18,6 +18,9 @@ public class Utils {
public static final String FolderUnicode = "\uD83D\uDCC1";
public static final String ReturnUnicode = "\u21A9";
public static final String ProgressBarForeground = "\uD83D\uDFE9";
public static final String ProgressBarBackground = "\u2B1C";
public static boolean IsInt(String info) {
try {
Integer.parseInt(info);