mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-26 04:49:18 +01:00
change: refactor trackmanager to remove GuildMusicPlayer.java
This commit is contained in:
parent
2e421bc2f0
commit
2b0417575e
8 changed files with 200 additions and 126 deletions
|
|
@ -0,0 +1,74 @@
|
|||
package codes.ztereohype.ztereomusic.command.commands;
|
||||
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManagers;
|
||||
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;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Pause implements Command {
|
||||
CommandMeta meta = new CommandMeta("pause", "Pause the playing music", new String[]{"resume"}, false, false);
|
||||
|
||||
@Override
|
||||
public CommandMeta getMeta() {
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MessageReceivedEvent messageEvent, String[] args) {
|
||||
Member author = Objects.requireNonNull(messageEvent.getMember());
|
||||
|
||||
if (author.getVoiceState() == null) {
|
||||
messageEvent.getChannel().sendMessage("I was unable to access your information... strange...").queue();
|
||||
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;
|
||||
}
|
||||
|
||||
Guild guild = messageEvent.getGuild();
|
||||
VoiceChannel voiceChannel = author.getVoiceState().getChannel();
|
||||
MessageChannel messageChannel = messageEvent.getChannel();
|
||||
AudioManager manager = guild.getAudioManager();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
// Check if we are playing anything
|
||||
if (trackManager.getPlayer().getPlayingTrack() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if (trackManager.getPlayer().isPaused()) {
|
||||
trackManager.resume();
|
||||
} else {
|
||||
trackManager.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package codes.ztereohype.ztereomusic.command.commands;
|
||||
|
||||
import codes.ztereohype.ztereomusic.ZtereoMUSIC;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayer;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayers;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManagers;
|
||||
import codes.ztereohype.ztereomusic.command.Command;
|
||||
import codes.ztereohype.ztereomusic.command.CommandMeta;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
|
|
@ -19,7 +19,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
public class Play implements Command {
|
||||
CommandMeta meta = new CommandMeta("play", "Play music!", new String[]{}, false, false);
|
||||
CommandMeta meta = new CommandMeta("play", "Play music!", new String[]{"p"}, false, false);
|
||||
|
||||
@Override
|
||||
public CommandMeta getMeta() {
|
||||
|
|
@ -62,18 +62,18 @@ public class Play implements Command {
|
|||
identifier = mergedArgs;
|
||||
}
|
||||
|
||||
GuildMusicPlayer musicPlayer = GuildMusicPlayers.getGuildAudioPlayer(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
playerManager.loadItem(identifier, new AudioLoadResultHandler() {
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack track) {
|
||||
musicPlayer.queue(track);
|
||||
trackManager.queue(track);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
for (AudioTrack track : playlist.getTracks()) {
|
||||
musicPlayer.queue(track);
|
||||
trackManager.queue(track);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package codes.ztereohype.ztereomusic.command.commands;
|
||||
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayer;
|
||||
import codes.ztereohype.ztereomusic.audio.GuildMusicPlayers;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManager;
|
||||
import codes.ztereohype.ztereomusic.audio.TrackManagers;
|
||||
import codes.ztereohype.ztereomusic.command.Command;
|
||||
import codes.ztereohype.ztereomusic.command.CommandMeta;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
|
|
@ -31,9 +31,10 @@ public class Skip implements Command {
|
|||
|
||||
// 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 we are playing something
|
||||
- if mr user has the goshdarn role
|
||||
*/
|
||||
if (!author.getVoiceState().inVoiceChannel()) {
|
||||
messageEvent.getMessage().reply("You are not in a voice channel!").queue();
|
||||
|
|
@ -56,14 +57,14 @@ public class Skip implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
GuildMusicPlayer musicPlayer = GuildMusicPlayers.getGuildAudioPlayer(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel, manager.getConnectedChannel(), voiceChannel);
|
||||
|
||||
// Check if we are playing anything
|
||||
if (musicPlayer.getPlayer().getPlayingTrack() == null) {
|
||||
if (trackManager.getPlayer().getPlayingTrack() == null) {
|
||||
messageChannel.sendMessage("I am not even playing anything!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
musicPlayer.skip();
|
||||
trackManager.skip();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue