Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Jan 1, 2018
2 parents 68d81b9 + cf09a34 commit 6c2afbf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
25 changes: 25 additions & 0 deletions LavalinkClient/src/main/java/lavalink/client/io/Lavalink.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.VoiceChannel;
import net.dv8tion.jda.core.entities.impl.JDAImpl;
import net.dv8tion.jda.core.events.DisconnectEvent;
import net.dv8tion.jda.core.events.ReadyEvent;
import net.dv8tion.jda.core.events.ReconnectedEvent;
import net.dv8tion.jda.core.events.ResumedEvent;
import net.dv8tion.jda.core.events.ShutdownEvent;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent;
Expand Down Expand Up @@ -200,6 +202,16 @@ public void onReady(ReadyEvent event) {
.put("VOICE_SERVER_UPDATE", new VoiceServerUpdateInterceptor(this, (JDAImpl) event.getJDA()));
}

@Override
public void onDisconnect(DisconnectEvent event) {
disconnectVoiceConnection(event.getJDA());
}

@Override
public void onShutdown(ShutdownEvent event) {
disconnectVoiceConnection(event.getJDA());
}

@Override
public void onReconnect(ReconnectedEvent event) {
reconnectVoiceConnections(event.getJDA());
Expand Down Expand Up @@ -249,4 +261,17 @@ private void reconnectVoiceConnections(JDA jda) {
});
}
}

private void disconnectVoiceConnection(JDA jda) {
links.forEach((guildId, link) -> {
try {
if (jda.getGuildById(guildId) != null) {
link.disconnect();
}
} catch (Exception e) {
log.error("Caught exception while trying to disconnect link " + link, e);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public boolean isPaused() {
@Override
public long getTrackPosition() {
if (getPlayingTrack() == null) throw new IllegalStateException("Not currently playing anything");
if (getPlayingTrack().getInfo().isStream) return Long.MAX_VALUE;

if (!paused) {
// Account for the time since our last update
Expand All @@ -145,7 +144,7 @@ public long getTrackPosition() {
@Override
public void seekTo(long position) {
if (getPlayingTrack() == null) throw new IllegalStateException("Not currently playing anything");
if (getPlayingTrack().getInfo().isStream) throw new IllegalStateException("Can't seek in a stream");
if (!getPlayingTrack().isSeekable()) throw new IllegalStateException("Track cannot be seeked");

JSONObject json = new JSONObject();
json.put("op", "seek");
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Being used in production by FredBoat and Dyno.
* [JDA client](https://github.com/Frederikam/Lavalink/tree/master/LavalinkClient) (JDA, Java)
* [eris-lavalink](https://github.com/briantanner/eris-lavalink) (Eris, JavaScript)
* [lava-d.js](https://github.com/untocodes/lava-d.js) (discord.js, JavaScript)
* [discord.js-lavalink](https://github.com/MrJacz/discord.js-lavalink) (discord.js, JavaScript)
* [lavalink.js](https://github.com/briantanner/lavalink.js) (discord.js, JavaScript)
* Or [create your own](https://github.com/Frederikam/Lavalink/blob/master/IMPLEMENTATION.md)

## Server configuration
Expand Down

0 comments on commit 6c2afbf

Please sign in to comment.