diff --git a/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/commands/EndCommand.kt b/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/commands/EndCommand.kt new file mode 100644 index 0000000..47def7e --- /dev/null +++ b/plugins/MinikuraVelocity/src/main/kotlin/cafe/kirameki/minikuraVelocity/commands/EndCommand.kt @@ -0,0 +1,43 @@ +package cafe.kirameki.minikuraVelocity + +import cafe.kirameki.minikuraVelocity.utils.ProxyTransferUtils +import com.mojang.brigadier.Command +import com.mojang.brigadier.arguments.StringArgumentType +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import com.velocitypowered.api.command.BrigadierCommand +import com.velocitypowered.api.command.CommandSource +import com.velocitypowered.api.proxy.ConnectionRequestBuilder +import com.velocitypowered.api.proxy.Player +import com.velocitypowered.api.proxy.ProxyServer +import com.velocitypowered.api.proxy.ServerConnection +import com.velocitypowered.api.proxy.server.RegisteredServer +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor +import java.util.function.Consumer + +object EndCommand { + fun createEndCommand(proxy: ProxyServer): BrigadierCommand { + val serverNode = BrigadierCommand.literalArgumentBuilder("end") + //.requires { source: CommandSource? -> source is Player } + .then(BrigadierCommand.requiredArgumentBuilder("forceEnd", StringArgumentType.word()) + .suggests { context: CommandContext?, builder: SuggestionsBuilder -> + builder.suggest("--force") + builder.buildFuture() + } + .executes { context: CommandContext -> + val source = context.source + proxy.shutdown() + return@executes Command.SINGLE_SUCCESS + } + ) + .executes { context: CommandContext -> + val source = context.source + ProxyTransferUtils.endProxy() + return@executes Command.SINGLE_SUCCESS + } + .build() + + return BrigadierCommand(serverNode) + } +} \ No newline at end of file