Search in sources :

Example 1 with VerificationResult

use of uk.co.notnull.proxydiscord.api.VerificationResult in project ProxyQueues by JLyne.

the class ProxyDiscordHandler method onPlayerJoinQueue.

@Subscribe
public void onPlayerJoinQueue(PlayerQueueEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (verificationManager.isPublicServer(event.getServer())) {
        return;
    }
    VerificationResult result = verificationManager.checkVerificationStatus(event.getPlayer());
    if (result.isVerified()) {
        Optional<ServerConnection> currentServer = event.getPlayer().getCurrentServer();
        if (currentServer.isPresent() && verificationManager.isPublicServer(currentServer.get().getServer())) {
            if (plugin.getWaitingServer().isPresent()) {
                event.getPlayer().createConnectionRequest(plugin.getWaitingServer().get()).fireAndForget();
            }
        }
        return;
    }
    event.setCancelled(true);
    RegisteredServer linkingServer = verificationManager.getLinkingServer();
    RegisteredServer currentServer = event.getPlayer().getCurrentServer().map(ServerConnection::getServer).orElse(null);
    if (linkingServer != null && (currentServer == null || !currentServer.equals(linkingServer))) {
        event.getPlayer().createConnectionRequest(linkingServer).fireAndForget();
    }
    switch(result) {
        case NOT_LINKED:
            event.setReason(Messages.get("errors.discord-not-linked"));
            break;
        case LINKED_NOT_VERIFIED:
            event.setReason(Messages.get("errors.discord-not-verified"));
            break;
        default:
            event.setReason("An error has occurred.");
    }
}
Also used : VerificationResult(uk.co.notnull.proxydiscord.api.VerificationResult) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) ServerConnection(com.velocitypowered.api.proxy.ServerConnection) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

Subscribe (com.velocitypowered.api.event.Subscribe)1 ServerConnection (com.velocitypowered.api.proxy.ServerConnection)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 VerificationResult (uk.co.notnull.proxydiscord.api.VerificationResult)1