Search in sources :

Example 21 with ServerConnection

use of com.velocitypowered.api.proxy.ServerConnection in project ProxyQueues by JLyne.

the class Commands method join.

@CommandMethod("queue join <server>")
@CommandDescription("Join the queue for a server")
@CommandPermission(Constants.BASE_PERM + "join")
public void join(CommandSource sender, @Argument("server") RegisteredServer server) {
    ProxyQueue queue = queueHandler.getQueue(server);
    ProxyQueuesImpl proxyQueues = ProxyQueuesImpl.getInstance();
    if (queue == null || !queue.isActive()) {
        proxyQueues.sendMessage(sender, MessageType.ERROR, "errors.server-no-queue", Collections.singletonMap("server", server.getServerInfo().getName()));
        return;
    }
    Optional<ServerConnection> currentServer = ((Player) sender).getCurrentServer();
    if (currentServer.isPresent() && currentServer.get().getServer().equals(server)) {
        proxyQueues.sendMessage(sender, MessageType.ERROR, "errors.player-same-server", Collections.singletonMap("server", server.getServerInfo().getName()));
        return;
    }
    queueHandler.clearPlayer((Player) sender);
    queue.addPlayer((Player) sender);
}
Also used : ProxyQueue(uk.co.notnull.proxyqueues.api.queues.ProxyQueue) QueuePlayer(uk.co.notnull.proxyqueues.api.queues.QueuePlayer) Player(com.velocitypowered.api.proxy.Player) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) CommandMethod(cloud.commandframework.annotations.CommandMethod) CommandDescription(cloud.commandframework.annotations.CommandDescription) CommandPermission(cloud.commandframework.annotations.CommandPermission)

Aggregations

ServerConnection (com.velocitypowered.api.proxy.ServerConnection)21 Subscribe (com.velocitypowered.api.event.Subscribe)12 Player (com.velocitypowered.api.proxy.Player)12 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)8 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)6 UUID (java.util.UUID)6 Component (net.kyori.adventure.text.Component)5 File (java.io.File)4 InputStreamReader (java.io.InputStreamReader)4 TimeUnit (java.util.concurrent.TimeUnit)4 Inject (com.google.inject.Inject)3 CommandSource (com.velocitypowered.api.command.CommandSource)3 PostOrder (com.velocitypowered.api.event.PostOrder)3 DisconnectEvent (com.velocitypowered.api.event.connection.DisconnectEvent)3 ServerPostConnectEvent (com.velocitypowered.api.event.player.ServerPostConnectEvent)3 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)3 IOException (java.io.IOException)3 TextComponent (net.kyori.adventure.text.TextComponent)3 HoverEvent (net.kyori.adventure.text.event.HoverEvent)3 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)2