Search in sources :

Example 1 with ProxiedPlayerFallbackEvent

use of de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent in project CloudNet by Dytanic.

the class ProxiedListener method handleServerKick.

@EventHandler
public void handleServerKick(ServerKickEvent e) {
    if (e.getCancelServer() != null) {
        ServerInfo serverInfo = CloudProxy.getInstance().getCachedServers().get(e.getKickedFrom().getName());
        String fallback;
        if (CloudAPI.getInstance().getServerGroupData(serverInfo.getServiceId().getGroup()) != null && CloudAPI.getInstance().getServerGroupData(serverInfo.getServiceId().getGroup()).isKickedForceFallback()) {
            fallback = CloudProxy.getInstance().fallbackOnEnabledKick(e.getPlayer(), serverInfo.getServiceId().getGroup(), e.getKickedFrom().getName());
        } else {
            fallback = CloudProxy.getInstance().fallback(e.getPlayer(), e.getKickedFrom().getName());
        }
        ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent(e.getPlayer(), CloudAPI.getInstance().getOnlinePlayer(e.getPlayer().getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.SERVER_KICK, fallback);
        ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
        fallback = proxiedPlayerFallbackEvent.getFallback();
        if (fallback != null) {
            e.setCancelled(true);
            e.setCancelServer((ProxyServer.getInstance().getServerInfo(fallback)));
            e.getPlayer().sendMessage(e.getKickReasonComponent());
        }
    }
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with ProxiedPlayerFallbackEvent

use of de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent in project CloudNet by Dytanic.

the class ProxiedListener method handleServerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleServerConnect(ServerConnectEvent event) {
    if (event.getPlayer().getServer() == null) {
        String fallback = CloudProxy.getInstance().fallback(event.getPlayer());
        ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent(event.getPlayer(), CloudAPI.getInstance().getOnlinePlayer(event.getPlayer().getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.SERVER_KICK, fallback);
        ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
        fallback = proxiedPlayerFallbackEvent.getFallback();
        if (fallback != null) {
            event.setTarget(ProxyServer.getInstance().getServerInfo(fallback));
            CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
            NetworkUtils.sleepUninterruptedly(6);
        } else
            event.setCancelled(true);
    } else {
        CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
        NetworkUtils.sleepUninterruptedly(6);
    }
}
Also used : ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent) Document(de.dytanic.cloudnet.lib.utility.document.Document) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with ProxiedPlayerFallbackEvent

use of de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent in project CloudNet by Dytanic.

the class CommandHub method execute.

@Override
public void execute(CommandSender commandSender, String[] args) {
    if (!(commandSender instanceof ProxiedPlayer))
        return;
    ServerInfo serverInfo = CloudProxy.getInstance().getCachedServers().get(((ProxiedPlayer) commandSender).getServer().getInfo().getName());
    if (serverInfo != null)
        if (CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getNamedFallbackes().contains(serverInfo.getServiceId().getGroup())) {
            commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("hub-already")));
            return;
        }
    String fallback = CloudProxy.getInstance().fallbackOnEnabledKick((((ProxiedPlayer) commandSender)), CloudAPI.getInstance().getGroup(), ((ProxiedPlayer) commandSender).getServer().getInfo().getName());
    ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent((ProxiedPlayer) commandSender, CloudAPI.getInstance().getOnlinePlayer(((ProxiedPlayer) commandSender).getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.HUB_COMMAND, fallback);
    ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
    fallback = proxiedPlayerFallbackEvent.getFallback();
    ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
    if (fallback == null)
        commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("hubCommandNoServerFound")));
    else
        ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(fallback));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent)

Aggregations

ProxiedPlayerFallbackEvent (de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 EventHandler (net.md_5.bungee.event.EventHandler)2 Document (de.dytanic.cloudnet.lib.utility.document.Document)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1