diff --git a/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/Main.kt b/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/Main.kt index 5964fce..b9b64d3 100644 --- a/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/Main.kt +++ b/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/Main.kt @@ -9,6 +9,7 @@ import cafe.kirameki.minikuraVelocity.utils.createWebSocketClient import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.google.inject.Inject +import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI import com.velocitypowered.api.command.CommandManager import com.velocitypowered.api.command.CommandMeta import com.velocitypowered.api.command.SimpleCommand @@ -43,6 +44,7 @@ class Main @Inject constructor(private val logger: Logger, private val server: P private val apiUrl: String = System.getenv("MINIKURA_API_URL") ?: "http://localhost:3000" private val websocketUrl: String = System.getenv("MINIKURA_WEBSOCKET_URL") ?: "ws://localhost:3000/ws" private var acceptingTransfers = AtomicBoolean(false) + private val redisBungeeApi = RedisBungeeAPI.getRedisBungeeApi() @Subscribe fun onProxyInitialization(event: ProxyInitializeEvent?) { @@ -85,6 +87,7 @@ class Main @Inject constructor(private val logger: Logger, private val server: P .plugin(this) .build() + // TODO: Rework this command and support and arguments val migrateCommand = SimpleCommand { p -> val source = p.source() val args = p.arguments() @@ -102,6 +105,11 @@ class Main @Inject constructor(private val logger: Logger, private val server: P return@SimpleCommand } + if (targetServer.name == redisBungeeApi.proxyId) { + source.sendMessage(Component.text("Target server cannot be the current proxy server.")) + return@SimpleCommand + } + ProxyTransferUtils.migratePlayersToServer(targetServer) source.sendMessage(Component.text("Migrating players to server '$targetServerName'...")) } diff --git a/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/utils/ProxyTransferUtils.kt b/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/utils/ProxyTransferUtils.kt index 62cdc0e..86335d9 100644 --- a/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/utils/ProxyTransferUtils.kt +++ b/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/utils/ProxyTransferUtils.kt @@ -31,7 +31,13 @@ object ProxyTransferUtils { val targetAddress = InetSocketAddress(targetServer.address, targetServer.port) val currentProxyName = redisBungeeApi.proxyId - val players = server.allPlayers.toList() + val playerOnThisProxy = redisBungeeApi.getPlayersOnProxy(currentProxyName) + .map { it.toString() } + + val players = server.allPlayers + .toList() + .filter { playerOnThisProxy.contains(it.uniqueId.toString()) } + val batchSize = (players.size * 0.05).coerceAtLeast(1.0).toInt() // 5% of players per batch to avoid overloading the server var currentIndex = 0