🐛 fix: don't allow migrating to current proxy

This commit is contained in:
2025-01-02 22:47:07 +07:00
parent bf439cf3f3
commit b3405cd6ad
2 changed files with 15 additions and 1 deletions

View File

@@ -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 <origin> and <destination> 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'..."))
}