Skip to content

Commit

Permalink
Make Player implement IPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Dec 3, 2021
1 parent ecdbff7 commit 4f425b9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ build/*
.settings
/Testbot/build/
/Testbot/out/
/plugin-api/build/
/plugin-api/out/
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ServerConfig {
var bufferDurationMs: Int? = null
var frameBufferDurationMs: Int? = null
var youtubePlaylistLoadLimit: Int? = null
var playerUpdateInterval: Int? = 5
var playerUpdateInterval: Int = 5
var isGcWarnings = true
var isYoutubeSearchEnabled = true
var isSoundcloudSearchEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SocketContext internal constructor(
internal fun getPlayer(guildId: Long) = getPlayer(guildId.toString())

internal fun getPlayer(guildId: String) = players.computeIfAbsent(guildId) {
Player(this, guildId, audioPlayerManager, serverConfig)
Player(this, guildId.toLong(), audioPlayerManager, serverConfig)
}

internal fun getPlayers(): Map<String, Player> {
Expand All @@ -106,7 +106,7 @@ class SocketContext internal constructor(
* Gets or creates a voice connection
*/
fun getVoiceConnection(player: Player): VoiceConnection {
val guildId = player.guildId.toLong()
val guildId = player.guildId
var conn = koe.getConnection(guildId)
if (conn == null) {
conn = koe.createConnection(guildId)
Expand Down Expand Up @@ -179,7 +179,7 @@ class SocketContext internal constructor(
executor.shutdown()
playerUpdateService.shutdown()
players.values.forEach {
destroy(it.guildId.toLong())
destroy(it.guildId)
}
koe.close()
}
Expand Down
21 changes: 17 additions & 4 deletions LavalinkServer/src/main/java/lavalink/server/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sedmelluq.discord.lavaplayer.track.AudioTrackEndReason;
import com.sedmelluq.discord.lavaplayer.track.playback.AudioFrame;
import io.netty.buffer.ByteBuf;
import lavalink.api.ISocketContext;
import lavalink.server.io.SocketContext;
import lavalink.server.io.SocketServer;
import lavalink.server.player.filters.FilterChain;
Expand All @@ -38,25 +39,26 @@
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lavalink.api.IPlayer;

import javax.annotation.Nullable;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class Player extends AudioEventAdapter {
public class Player extends AudioEventAdapter implements IPlayer {

private static final Logger log = LoggerFactory.getLogger(Player.class);

private final SocketContext socketContext;
private final String guildId;
private final long guildId;
private final ServerConfig serverConfig;
private final AudioPlayer player;
private final AudioLossCounter audioLossCounter = new AudioLossCounter();
private AudioFrame lastFrame = null;
private FilterChain filters;
private ScheduledFuture<?> myFuture = null;

public Player(SocketContext socketContext, String guildId, AudioPlayerManager audioPlayerManager, ServerConfig serverConfig) {
public Player(SocketContext socketContext, long guildId, AudioPlayerManager audioPlayerManager, ServerConfig serverConfig) {
this.socketContext = socketContext;
this.guildId = guildId;
this.serverConfig = serverConfig;
Expand All @@ -83,10 +85,21 @@ public void setPause(boolean b) {
player.setPaused(b);
}

public String getGuildId() {
@Override
public AudioPlayer getAudioPlayer() {
return player;
}

@Override
public long getGuildId() {
return guildId;
}

@Override
public ISocketContext getSocketContext() {
return null;
}

public void seekTo(long position) {
AudioTrack track = player.getPlayingTrack();

Expand Down
6 changes: 0 additions & 6 deletions plugin-api/src/main/java/lavalink/api/ISocketContext.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package lavalink.api;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import org.json.JSONObject;
import org.springframework.lang.Nullable;
import org.springframework.web.socket.WebSocketSession;

public interface ISocketContext {
WebSocketSession getWebSocketSession();
@Nullable
IPlayer getPlayer(long guildId);
void destroyPlayer(long guildId);
void sendMessage(JSONObject message);
Expand Down

0 comments on commit 4f425b9

Please sign in to comment.