use of main.exceptions.AutoPlayException in project Robertify-Bot by bombies.
the class SkipToCommand method handleSkip.
public EmbedBuilder handleSkip(User skipper, ConcurrentLinkedQueue<AudioTrack> queue, GuildMusicManager musicManager, int id) {
if (id > queue.size() || id <= 0)
return RobertifyEmbedUtils.embedMessage(musicManager.getGuild(), "ID provided isn't a valid ID!");
final var audioPlayer = musicManager.getPlayer();
final var scheduler = musicManager.getScheduler();
final var guild = musicManager.getGuild();
List<AudioTrack> currentQueue = new ArrayList<>(queue);
List<AudioTrack> songsToRemoveFromQueue = new ArrayList<>();
for (int i = 0; i < id - 1; i++) songsToRemoveFromQueue.add(currentQueue.get(i));
queue.removeAll(songsToRemoveFromQueue);
audioPlayer.seekTo(0);
HashMap<Long, Stack<AudioTrack>> pastQueue = scheduler.getPastQueue();
if (!pastQueue.containsKey(guild.getIdLong()))
pastQueue.put(guild.getIdLong(), new Stack<>());
AudioTrack playingTrack = audioPlayer.getPlayingTrack();
pastQueue.get(guild.getIdLong()).push(playingTrack);
try {
scheduler.nextTrack(playingTrack, true, playingTrack.getPosition());
} catch (AutoPlayException ignored) {
}
if (new DedicatedChannelConfig().isChannelSet(guild.getIdLong()))
new DedicatedChannelConfig().updateMessage(guild);
LofiCommand.getLofiEnabledGuilds().remove(guild.getIdLong());
new LogUtils().sendLog(guild, LogType.TRACK_SKIP, skipper.getAsMention() + " has skipped to `track #" + id + "`");
SkipCommand.clearVoteSkipInfo(guild);
return RobertifyEmbedUtils.embedMessage(musicManager.getGuild(), "Skipped to **track #" + id + "**!");
}
Aggregations