Search in sources :

Example 1 with CloudPlayerCommandSender

use of de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender in project CloudNet by Dytanic.

the class ProxiedListener method handleLogin.

@EventHandler(priority = EventPriority.LOWEST)
public void handleLogin(LoginEvent e) {
    PlayerConnection playerConnection = new PlayerConnection(e.getConnection().getUniqueId(), e.getConnection().getName(), e.getConnection().getVersion(), e.getConnection().getAddress().getAddress().getHostAddress(), e.getConnection().getAddress().getPort(), e.getConnection().isOnlineMode(), e.getConnection().isLegacy());
    CloudPlayer cloudPlayer = CloudAPI.getInstance().getNetworkConnection().getPacketManager().sendQuery(new PacketOutPlayerLoginRequest(playerConnection), CloudAPI.getInstance().getNetworkConnection()).getResult().getObject("player", new TypeToken<CloudPlayer>() {
    }.getType());
    if (cloudPlayer == null) {
        e.setCancelReason(TextComponent.fromLegacyText("§cYou are already on the network!"));
        e.setCancelled(true);
    }
    CommandSender cloudCommandSender = new CloudPlayerCommandSender(cloudPlayer);
    if (CloudProxy.getInstance().getProxyGroup() != null) {
        ProxyConfig proxyConfig = CloudProxy.getInstance().getProxyGroup().getProxyConfig();
        if ((proxyConfig.isEnabled() && proxyConfig.isMaintenance())) {
            PermissionCheckEvent permissionCheckEvent = new PermissionCheckEvent(cloudCommandSender, "cloudnet.maintenance", false);
            if (!proxyConfig.getWhitelist().contains(e.getConnection().getName()) && !ProxyServer.getInstance().getPluginManager().callEvent(permissionCheckEvent).hasPermission()) {
                e.setCancelled(true);
                e.setCancelReason(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("kick-maintenance")));
                return;
            }
        }
    }
    ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
    if (proxyGroup.getProxyConfig().isEnabled())
        if (CloudAPI.getInstance().getOnlineCount() >= CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers()) {
            PermissionCheckEvent permissionCheckEvent = new PermissionCheckEvent(cloudCommandSender, "cloudnet.fulljoin", false);
            if (!ProxyServer.getInstance().getPluginManager().callEvent(permissionCheckEvent).hasPermission()) {
                e.setCancelled(true);
                e.setCancelReason(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("full-join")));
                return;
            }
        }
    CloudProxy.getInstance().getCloudPlayers().put(cloudPlayer.getUniqueId(), cloudPlayer);
}
Also used : CloudPlayerCommandSender(de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) TypeToken(com.google.gson.reflect.TypeToken) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) CommandSender(net.md_5.bungee.api.CommandSender) CloudPlayerCommandSender(de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender) ProxyConfig(de.dytanic.cloudnet.lib.proxylayout.ProxyConfig) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 CloudPlayerCommandSender (de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender)1 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)1 PlayerConnection (de.dytanic.cloudnet.lib.player.PlayerConnection)1 ProxyConfig (de.dytanic.cloudnet.lib.proxylayout.ProxyConfig)1 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)1 CommandSender (net.md_5.bungee.api.CommandSender)1 EventHandler (net.md_5.bungee.event.EventHandler)1