mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-26 04:49:18 +01:00
change: refactor to use the new stuff
This commit is contained in:
parent
e76d236278
commit
6f4c00d4dc
4 changed files with 53 additions and 103 deletions
|
|
@ -1,12 +1,11 @@
|
|||
package codes.ztereohype.ztereomusic.command.commands;
|
||||
|
||||
import codes.ztereohype.ztereomusic.Bot;
|
||||
import codes.ztereohype.ztereomusic.audio.AudioPlayerSendHandler;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayer;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayers;
|
||||
import codes.ztereohype.ztereomusic.command.Command;
|
||||
import codes.ztereohype.ztereomusic.command.CommandMeta;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
|
|
@ -63,54 +62,18 @@ public class Play implements Command {
|
|||
identifier = mergedArgs;
|
||||
}
|
||||
|
||||
|
||||
/* Generally you would want to create a player per every
|
||||
different target you might want to separately stream audio to.
|
||||
It is totally fine to create them even if they are unlikely to be used,
|
||||
as they do not use any resources on their own without an active track. */
|
||||
AudioPlayer player;
|
||||
TrackManager trackManager;
|
||||
|
||||
boolean isInVC = manager.isConnected();
|
||||
boolean isInSameVC = isInVC && Objects.equals(manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
if (isInSameVC && Bot.trackScheduerMap.containsKey(voiceChannel)) {
|
||||
System.out.println("Found a trackScheduler for this VC already! reusing...");
|
||||
|
||||
trackManager = Bot.trackScheduerMap.get(voiceChannel);
|
||||
player = trackManager.getPlayer();
|
||||
|
||||
player.addListener(trackManager);
|
||||
|
||||
} else {
|
||||
// Maybe we don't wanna clear the whole queue when he gets kicked out?
|
||||
if (Bot.trackScheduerMap.containsKey(voiceChannel)) {
|
||||
System.out.println("Found old trackScheduler for this channel. Cleaning it up...");
|
||||
Bot.trackScheduerMap.remove(voiceChannel);
|
||||
}
|
||||
|
||||
System.out.println("Creating a new trackScheduler...");
|
||||
|
||||
player = playerManager.createPlayer();
|
||||
trackManager = new TrackManager(player, messageChannel);
|
||||
|
||||
player.addListener(trackManager);
|
||||
manager.setSendingHandler(new AudioPlayerSendHandler(player));
|
||||
manager.openAudioConnection(voiceChannel);
|
||||
|
||||
Bot.trackScheduerMap.put(voiceChannel, trackManager);
|
||||
}
|
||||
GuildMusicPlayer musicPlayer = GuildMusicPlayers.getGuildAudioPlayer(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
playerManager.loadItem(identifier, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
trackManager.queue(track);
|
||||
musicPlayer.queue(track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
for (AudioTrack track : playlist.getTracks()) {
|
||||
trackManager.queue(track);
|
||||
musicPlayer.queue(track);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package codes.ztereohype.ztereomusic.command.commands;
|
||||
|
||||
import codes.ztereohype.ztereomusic.Bot;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayer;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayers;
|
||||
import codes.ztereohype.ztereomusic.command.Command;
|
||||
import codes.ztereohype.ztereomusic.command.CommandMeta;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
|
@ -28,6 +29,12 @@ public class Skip implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
// todo: make this part of a perms system (only people in same vc or vc at all have perms on music control)
|
||||
/* Note to self: Things to check before executing command
|
||||
- if he's in vc
|
||||
- if we are in vc
|
||||
- if we are in the same vc
|
||||
*/
|
||||
if (!author.getVoiceState().inVoiceChannel()) {
|
||||
messageEvent.getMessage().reply("You are not in a voice channel!").queue();
|
||||
return;
|
||||
|
|
@ -35,25 +42,28 @@ public class Skip implements Command {
|
|||
|
||||
Guild guild = messageEvent.getGuild();
|
||||
VoiceChannel voiceChannel = author.getVoiceState().getChannel();
|
||||
MessageChannel messageChannel = messageEvent.getChannel();
|
||||
AudioManager manager = guild.getAudioManager();
|
||||
|
||||
boolean isInVC = manager.isConnected();
|
||||
boolean isInSameVC = isInVC && Objects.equals(manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
if (isInSameVC && Bot.trackScheduerMap.containsKey(voiceChannel)) {
|
||||
TrackManager trackManager = Bot.trackScheduerMap.get(voiceChannel);
|
||||
|
||||
if (trackManager.getPlayer().getPlayingTrack() == null) {
|
||||
messageEvent.getMessage().reply("No track is playing.").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
trackManager.skip();
|
||||
|
||||
} else {
|
||||
messageEvent.getMessage().reply("No track is playing...").queue();
|
||||
if (manager.getConnectedChannel() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
// Check if we are in the same vc
|
||||
if (!Objects.equals(author.getVoiceState().getChannel(), manager.getConnectedChannel())) {
|
||||
messageChannel.sendMessage("We aren't in the same channel").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
GuildMusicPlayer musicPlayer = GuildMusicPlayers.getGuildAudioPlayer(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
// Check if we are playing anything
|
||||
if (musicPlayer.getPlayer().getPlayingTrack() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
musicPlayer.skip();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue