refactor: change package path to reflect group id of pom.xml
BREAKING CHANGE:
This commit is contained in:
1 parent
2b08351f6d
commit
f4c7e9c703
94 files changed
+373
-372
No files matched your search
@@ -0,0 +1,129 @@
|
||||
package me.bobert.netneutrality.music;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
* https://discord.gg/qUa6zNFZsd
|
||||
*/
|
||||
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
|
||||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist;
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
import me.bobert.netneutrality.core.LogHandler;
|
||||
import me.bobert.netneutrality.core.context.CommandContext;
|
||||
import me.bobert.netneutrality.utils.MessageFunction;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TrackLoadingHandler implements AudioLoadResultHandler {
|
||||
private final Logger logger = LogManager.getLogger(TrackLoadingHandler.class);
|
||||
|
||||
private final String identifier;
|
||||
private final SourceFinder.AudioSourceType type;
|
||||
private final boolean silent;
|
||||
private Consumer<Boolean> loadConsumer;
|
||||
private boolean loadingDisabled = false;
|
||||
private final Guild guild;
|
||||
private final TrackScheduler scheduler;
|
||||
private final CommandContext context;
|
||||
|
||||
public TrackLoadingHandler(CommandContext context, MusicManager manager, String identifier, SourceFinder.AudioSourceType type, boolean silent) {
|
||||
this.identifier = identifier;
|
||||
this.type = type;
|
||||
this.silent = silent;
|
||||
this.guild = manager.getGuild();
|
||||
this.scheduler = manager.getScheduler();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public synchronized void stopLoading() {
|
||||
logger.debug("Guild {}: stopped loading of new tracks", guild.getId());
|
||||
loadingDisabled = true;
|
||||
}
|
||||
|
||||
public void useCallbackOnLoad(Consumer<Boolean> consumer) {
|
||||
this.loadConsumer = consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trackLoaded(AudioTrack audioTrack) {
|
||||
if (loadConsumer != null) {
|
||||
loadConsumer.accept(true);
|
||||
}
|
||||
|
||||
if (loadingDisabled)
|
||||
return;
|
||||
|
||||
context.deleteMessage();
|
||||
|
||||
logger.debug("Guild {}: track loaded: {}", guild.getId(), audioTrack.getIdentifier());
|
||||
scheduler.getQueueManager().queue(audioTrack, context.getGuildUser());
|
||||
|
||||
if (!silent) {
|
||||
context.reply(MessageFunction.buildAddingTrackMessage(audioTrack, type));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playlistLoaded(AudioPlaylist playlist) {
|
||||
if (loadConsumer != null) {
|
||||
loadConsumer.accept(true);
|
||||
}
|
||||
|
||||
if (loadingDisabled)
|
||||
return;
|
||||
|
||||
logger.debug("Guild {}: playlist loaded: {}", guild.getId(), identifier);
|
||||
|
||||
if (!playlist.getTracks().isEmpty()) {
|
||||
if (playlist.isSearchResult()) {
|
||||
|
||||
AudioTrack track = playlist.getTracks().get(0);
|
||||
scheduler.getQueueManager().queue(track, context.getGuildUser());
|
||||
|
||||
if (!silent) {
|
||||
context.reply(MessageFunction.buildAddingTrackMessage(track, type));
|
||||
}
|
||||
|
||||
} else {
|
||||
context.deleteMessage();
|
||||
if (!silent) {
|
||||
context.reply(MessageFunction.buildAddingPlaylistMessage(playlist, identifier, type));
|
||||
}
|
||||
|
||||
for (AudioTrack track : playlist.getTracks()) {
|
||||
if (loadingDisabled) {
|
||||
break;
|
||||
}
|
||||
|
||||
scheduler.getQueueManager().queue(track, context.getGuildUser());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noMatches() {
|
||||
if (loadConsumer != null)
|
||||
loadConsumer.accept(false);
|
||||
|
||||
if (!silent)
|
||||
context.replyToMessage("No matches found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFailed(FriendlyException e) {
|
||||
if (loadConsumer != null)
|
||||
loadConsumer.accept(false);
|
||||
|
||||
logger.debug("Guild {}: load failed for identifier {}", guild.getId(), identifier, e);
|
||||
LogHandler.log(e);
|
||||
|
||||
if (!silent)
|
||||
context.replyToMessage(MessageFunction.buildSentryErrorMessage("Failed to load track: " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user