Skip to content

Commit d56a50d

Browse files
committed
feat: allow connecting players to other servers registered to the proxy via pub/sub
1 parent f276875 commit d56a50d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/kotlin/dev/bypixel/redivelocity/RediVelocity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import dev.bypixel.redivelocity.election.ElectionScheduler
3333
import dev.bypixel.redivelocity.event.*
3434
import dev.bypixel.redivelocity.feature.globalPlayercount.PlayercountScheduler
3535
import dev.bypixel.redivelocity.heartbeat.HeartbeatScheduler
36+
import dev.bypixel.redivelocity.pubsub.ConnectListener
3637
import dev.bypixel.redivelocity.pubsub.KickListener
3738
import dev.bypixel.redivelocity.pubsub.LeaderElectionListener
3839
import dev.bypixel.redivelocity.pubsub.PlayercountListener
@@ -263,6 +264,7 @@ class RediVelocity @Inject constructor(val proxy: ProxyServer) {
263264
}
264265

265266
KickListener
267+
ConnectListener
266268
LeaderElectionListener
267269
PlayercountListener
268270

@@ -332,6 +334,7 @@ class RediVelocity @Inject constructor(val proxy: ProxyServer) {
332334
CommandAPI.onDisable()
333335

334336
RedisListener.unregisterListener(KickListener)
337+
RedisListener.unregisterListener(ConnectListener)
335338
RedisListener.unregisterListener(LeaderElectionListener)
336339
RedisListener.unregisterListener(PlayercountListener)
337340
ElectionScheduler.job.cancelAndJoin()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.bypixel.redivelocity.pubsub
2+
3+
import dev.bypixel.lettucewrapper.listener.RedisListener
4+
import dev.bypixel.redivelocity.RediVelocity
5+
import org.json.JSONObject
6+
import java.util.*
7+
8+
object ConnectListener : RedisListener("redivelocity-connect") {
9+
override fun onMessage(message: String) {
10+
val jMsg = JSONObject(message)
11+
12+
if (jMsg.has("uuid") && jMsg.has("server")) {
13+
val uuid = UUID.fromString(jMsg.getString("uuid"))
14+
val server = jMsg.getString("server")
15+
16+
RediVelocity.instance.proxy.allPlayers.find { it.uniqueId == uuid }?.let { player ->
17+
player.createConnectionRequest(
18+
RediVelocity.instance.proxy.getServer(server).orElseThrow {
19+
IllegalArgumentException("Server $server not found")
20+
}
21+
)
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)