use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.
the class ClearCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
GuildVoiceState state = event.getGuild().getSelfMember().getVoiceState();
if (state.getChannel() == null) {
event.replyEmbeds(EmbedUtil.warningEmbed("I am not connected to a voice channel!")).setEphemeral(true).queue();
return;
}
GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
if (player.getScheduler().getQueue().isEmpty()) {
event.replyEmbeds(EmbedUtil.warningEmbed("The queue is already empty!")).setEphemeral(true).queue();
return;
}
if (Util.getListeningUsers(state.getChannel()) == 1) {
player.getScheduler().getQueue().clear();
event.replyEmbeds(EmbedUtil.defaultEmbed("Cleared the queue!")).setEphemeral(true).queue();
player.forcePlayerUpdate();
return;
}
if (!ctx.getGuildData().isDJ(event.getMember())) {
boolean allowedToStop = true;
long userId = event.getUser().getIdLong();
List<AudioTrack> tracks = new ArrayList<>(player.getScheduler().getQueue());
for (AudioTrack track : tracks) {
TrackInfo trackInfo = track.getUserData(TrackInfo.class);
if (trackInfo.getRequesterIdLong() != userId) {
allowedToStop = false;
break;
}
}
if (!allowedToStop) {
event.replyEmbeds(EmbedUtil.errorEmbed("You need to be a DJ to do this!")).setEphemeral(true).queue();
return;
}
}
player.getScheduler().getQueue().clear();
event.replyEmbeds(EmbedUtil.defaultEmbed("Cleared the queue!")).setEphemeral(true).queue();
player.forcePlayerUpdate();
}
use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.
the class PlayerCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
GuildAudioPlayer player = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
AudioTrack track = player.getPlayer().getPlayingTrack();
boolean isRepeat = player.getScheduler().isRepeat();
boolean isPaused = player.getPlayer().isPaused();
event.reply("One moment...").queue(x -> player.playerSetup((GuildMessageChannel) event.getChannel(), (success) -> event.getHook().deleteOriginal().queue(), (error) -> event.reply("An error occurred!").setEphemeral(true).queue()));
}
use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.
the class Shutdown method executeCommand.
@Override
public void executeCommand(String invoke, String[] args) {
Set<GuildAudioPlayer> audioPlayers = Bean.getInstance().getAudioManager().getAudioPlayers();
if (args.length == 0 || !args[0].equalsIgnoreCase("-f")) {
int playing = audioPlayers.stream().mapToInt(pl -> pl.getPlayer().getPlayingTrack() == null ? 0 : 1).sum();
int mee6QueueSize = Bean.getInstance().getMEE6Queue().getQueue().size();
if (playing > 0)
Shell.println(MCColor.translate('&', "&eCareful: There are &2" + playing + "&e players running! Use shutdown -f to force-shutdown."));
if (mee6QueueSize > 0)
Shell.println(MCColor.translate('&', "&eCareful: There are &2" + mee6QueueSize + "&e pending MEE6 requests!"));
if (playing > 0 || mee6QueueSize > 0)
return;
}
logger.info("Shutting down...");
logger.info("Deleting player messages...");
audioPlayers.forEach(pl -> {
if (pl.getOpenPlayer() != null)
pl.getOpenPlayer().delete().complete();
});
logger.info("Destroying players...");
audioPlayers.forEach(GuildAudioPlayer::destroy);
Bean.getInstance().getShardManager().shutdown();
logger.info("Awaiting JDA ShardManager shutdown...");
for (JDA jda : Bean.getInstance().getShardManager().getShards()) {
while (jda.getStatus() != JDA.Status.SHUTDOWN) {
Thread.onSpinWait();
}
}
logger.info("Stopped all shards");
logger.info("Goodbye");
System.exit(0);
}
use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.
the class JoinCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
Member member = event.getMember();
GuildVoiceState voiceState = member.getVoiceState();
if (voiceState.getChannel() == null) {
event.replyEmbeds(EmbedUtil.errorEmbed("You must be listening in a voice channel to run this command!")).queue();
return;
}
GuildVoiceState state = event.getGuild().getSelfMember().getVoiceState();
if (state.getChannel() != null) {
AudioChannel channel = state.getChannel();
if (voiceState.getChannel().getIdLong() == channel.getIdLong()) {
event.replyEmbeds(EmbedUtil.errorEmbed("I already joined this channel!")).queue();
return;
}
if (Util.getListeningUsers(channel) > 0) {
event.replyEmbeds(EmbedUtil.errorEmbed("I am already playing music in **" + channel.getName() + "**!")).queue();
return;
}
}
GuildAudioPlayer audioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
try {
audioPlayer.getLink().connect(voiceState.getChannel());
} catch (PermissionException exception) {
event.replyEmbeds(EmbedUtil.errorEmbed("I do not have permission to join this channel!")).queue();
return;
}
event.replyEmbeds(EmbedUtil.successEmbed("Joined <#" + voiceState.getChannel().getIdLong() + ">!")).setEphemeral(true).queue();
audioPlayer.playerSetup((GuildMessageChannel) event.getChannel(), (s) -> {
}, e -> {
});
}
use of at.xirado.bean.music.GuildAudioPlayer in project Bean by Xirado.
the class PauseCommand method executeCommand.
@Override
public void executeCommand(@NotNull SlashCommandInteractionEvent event, @NotNull SlashCommandContext ctx) {
JdaLink link = Bean.getInstance().getLavalink().getLink(event.getGuild());
LavalinkPlayer player = link.getPlayer();
GuildAudioPlayer guildAudioPlayer = Bean.getInstance().getAudioManager().getAudioPlayer(event.getGuild().getIdLong());
if (player.getPlayingTrack() == null) {
ctx.replyError("I'm currently not playing any music!").setEphemeral(true).queue();
return;
}
if (player.isPaused()) {
ctx.replyError("The player is already paused! Use `/resume`").setEphemeral(true).queue();
return;
}
player.setPaused(true);
guildAudioPlayer.forcePlayerComponentsUpdate();
ctx.sendSimpleEphemeralEmbed("The player is now paused!");
}
Aggregations