Search in sources :

Example 1 with KickedFromServerEvent

use of com.velocitypowered.api.event.player.KickedFromServerEvent in project SubServers-2 by ME1312.

the class ExProxy method validate.

@Subscribe(order = PostOrder.LAST)
public void validate(ServerPreConnectEvent e) {
    if (e.getPlayer().isActive()) {
        ServerData server = getData(e.getOriginalServer().getServerInfo());
        if (server == null || !server.canAccess(e.getPlayer())) {
            if (!e.getPlayer().getCurrentServer().isPresent() || fallback.containsKey(e.getPlayer().getUniqueId())) {
                if (!fallback.containsKey(e.getPlayer().getUniqueId()) || fallback.get(e.getPlayer().getUniqueId()).names.contains(e.getOriginalServer().getServerInfo().getName())) {
                    Component text = ChatColor.convertColor(api.getLang("SubServers", "Bungee.Restricted"));
                    KickedFromServerEvent kick = new KickedFromServerEvent(e.getPlayer(), e.getOriginalServer(), text, true, KickedFromServerEvent.DisconnectPlayer.create(text));
                    fallback(kick);
                    if (e.getPlayer().getCurrentServer().isPresent())
                        e.setResult(ServerPreConnectEvent.ServerResult.denied());
                    if (kick.getResult() instanceof KickedFromServerEvent.DisconnectPlayer)
                        e.getPlayer().disconnect(text);
                    else if (kick.getResult() instanceof KickedFromServerEvent.RedirectPlayer)
                        e.getPlayer().createConnectionRequest(((KickedFromServerEvent.RedirectPlayer) kick.getResult()).getServer()).fireAndForget();
                }
            } else {
                e.getPlayer().sendMessage(ChatColor.convertColor(api.getLang("SubServers", "Bungee.Restricted")));
                e.setResult(ServerPreConnectEvent.ServerResult.denied());
            }
        } else if (e.getPlayer().getCurrentServer().isPresent() && !fallback.containsKey(e.getPlayer().getUniqueId()) && server instanceof SubServerData && !((SubServerData) server).isRunning()) {
            e.getPlayer().sendMessage(ChatColor.convertColor(api.getLang("SubServers", "Bungee.Server.Offline")));
            e.setResult(ServerPreConnectEvent.ServerResult.denied());
        }
        if (fallback.containsKey(e.getPlayer().getUniqueId())) {
            FallbackState state = fallback.get(e.getPlayer().getUniqueId());
            if (state.names.contains(e.getOriginalServer().getServerInfo().getName())) {
                state.remove(e.getOriginalServer().getServerInfo().getName());
            } else if (e.getPlayer().getCurrentServer().isPresent()) {
                fallback.remove(e.getPlayer().getUniqueId());
            }
        }
    } else {
        e.setResult(ServerPreConnectEvent.ServerResult.denied());
    }
}
Also used : KickedFromServerEvent(com.velocitypowered.api.event.player.KickedFromServerEvent) SubServerData(net.ME1312.SubServers.Velocity.Server.SubServerData) PacketDisconnectPlayer(net.ME1312.SubServers.Client.Common.Network.Packet.PacketDisconnectPlayer) SubServerData(net.ME1312.SubServers.Velocity.Server.SubServerData) ServerData(net.ME1312.SubServers.Velocity.Server.ServerData) FallbackState(net.ME1312.SubServers.Velocity.Library.Fallback.FallbackState) Component(net.kyori.adventure.text.Component) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 2 with KickedFromServerEvent

use of com.velocitypowered.api.event.player.KickedFromServerEvent in project ProxyQueues by JLyne.

the class ProxyQueueEventHandler method onKick.

@Subscribe(order = PostOrder.LAST)
public void onKick(KickedFromServerEvent event) {
    if (!event.getServer().equals(queue.getServer()) || event.kickedDuringServerConnect()) {
        return;
    }
    proxyQueues.getLogger().debug("Player " + event.getPlayer().getUsername() + " kicked from " + event.getServer().getServerInfo().getName() + ". Reason: " + event.getServerKickReason());
    Component reason = event.getServerKickReason().orElse(Component.empty());
    String reasonPlain = PlainTextComponentSerializer.plainText().serialize(reason);
    List<String> fatalErrors = proxyQueues.getSettingsHandler().getSettingsManager().getProperty(ConfigOptions.FATAL_ERRORS);
    Optional<RegisteredServer> waitingServer = proxyQueues.getWaitingServer();
    boolean fatal = fatalErrors.stream().anyMatch(reasonPlain::contains);
    if (!fatal) {
        proxyQueues.getLogger().debug("Reason not fatal, re-queueing " + event.getPlayer().getUsername());
        boolean staff = event.getPlayer().hasPermission(settingsManager.getProperty(ConfigOptions.STAFF_PERMISSION));
        queue.addPlayer(event.getPlayer(), staff ? QueueType.STAFF : QueueType.PRIORITY);
        if (event.getResult() instanceof KickedFromServerEvent.DisconnectPlayer && waitingServer.isPresent()) {
            event.setResult(KickedFromServerEvent.RedirectPlayer.create(waitingServer.get()));
        }
    } else {
        proxyQueues.getLogger().debug("Reason fatal");
    }
}
Also used : KickedFromServerEvent(com.velocitypowered.api.event.player.KickedFromServerEvent) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) Component(net.kyori.adventure.text.Component) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

Subscribe (com.velocitypowered.api.event.Subscribe)2 KickedFromServerEvent (com.velocitypowered.api.event.player.KickedFromServerEvent)2 Component (net.kyori.adventure.text.Component)2 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 PacketDisconnectPlayer (net.ME1312.SubServers.Client.Common.Network.Packet.PacketDisconnectPlayer)1 FallbackState (net.ME1312.SubServers.Velocity.Library.Fallback.FallbackState)1 ServerData (net.ME1312.SubServers.Velocity.Server.ServerData)1 SubServerData (net.ME1312.SubServers.Velocity.Server.SubServerData)1