Search in sources :

Example 1 with ServerFallback

use of de.dytanic.cloudnet.lib.proxylayout.ServerFallback in project CloudNet by Dytanic.

the class CloudProxy method fallback.

public String fallback(ProxiedPlayer cloudPlayer) {
    for (ServerFallback serverFallback : CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getFallbacks()) {
        if (serverFallback.getGroup().equals(CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback()))
            continue;
        if (serverFallback.getPermission() != null) {
            if (!cloudPlayer.hasPermission(serverFallback.getPermission()))
                continue;
            List<String> servers = CloudProxy.getInstance().getServers(serverFallback.getGroup());
            if (servers.size() != 0) {
                return servers.get(NetworkUtils.RANDOM.nextInt(servers.size()));
            }
        }
    }
    String fallback = getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback();
    List<String> liste = new ArrayList<>(MapWrapper.filter(cachedServers, new Acceptable<ServerInfo>() {

        @Override
        public boolean isAccepted(ServerInfo value) {
            return value.getServiceId().getGroup().equalsIgnoreCase(fallback);
        }
    }).keySet());
    if (liste.size() == 0)
        return null;
    else
        return liste.get(NetworkUtils.RANDOM.nextInt(liste.size()));
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ServerFallback(de.dytanic.cloudnet.lib.proxylayout.ServerFallback) ArrayList(java.util.ArrayList)

Example 2 with ServerFallback

use of de.dytanic.cloudnet.lib.proxylayout.ServerFallback in project CloudNet by Dytanic.

the class CloudProxy method fallbackOnEnabledKick.

public String fallbackOnEnabledKick(ProxiedPlayer cloudPlayer, String group, String kickedFrom) {
    for (ServerFallback serverFallback : CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getFallbacks()) {
        if (serverFallback.getGroup().equals(CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback()))
            continue;
        if (serverFallback.getPermission() != null) {
            if (!cloudPlayer.hasPermission(serverFallback.getPermission()))
                continue;
            List<String> servers = CloudProxy.getInstance().getServers(serverFallback.getGroup());
            servers.remove(kickedFrom);
            if (servers.size() != 0) {
                return servers.get(NetworkUtils.RANDOM.nextInt(servers.size()));
            }
        }
    }
    {
        List<String> liste = new ArrayList<>(MapWrapper.filter(cachedServers, new Acceptable<ServerInfo>() {

            @Override
            public boolean isAccepted(ServerInfo value) {
                return value.getServiceId().getGroup().equalsIgnoreCase(group);
            }
        }).keySet());
        liste.remove(kickedFrom);
        if (liste.size() != 0) {
            return liste.get(NetworkUtils.RANDOM.nextInt(liste.size()));
        }
    }
    String fallback = getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback();
    List<String> liste = new ArrayList<>(MapWrapper.filter(cachedServers, new Acceptable<ServerInfo>() {

        @Override
        public boolean isAccepted(ServerInfo value) {
            return value.getServiceId().getGroup().equalsIgnoreCase(fallback);
        }
    }).keySet());
    liste.remove(kickedFrom);
    if (liste.size() == 0)
        return null;
    else
        return liste.get(NetworkUtils.RANDOM.nextInt(liste.size()));
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) Acceptable(de.dytanic.cloudnet.lib.utility.Acceptable) ServerFallback(de.dytanic.cloudnet.lib.proxylayout.ServerFallback) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) TabList(de.dytanic.cloudnet.lib.proxylayout.TabList) List(java.util.List)

Example 3 with ServerFallback

use of de.dytanic.cloudnet.lib.proxylayout.ServerFallback in project CloudNet by Dytanic.

the class CloudProxy method fallback.

public String fallback(ProxiedPlayer cloudPlayer, String kickedFrom) {
    for (ServerFallback serverFallback : CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getFallbacks()) {
        if (serverFallback.getGroup().equals(CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback()))
            continue;
        if (serverFallback.getPermission() != null) {
            if (!cloudPlayer.hasPermission(serverFallback.getPermission()))
                continue;
            List<String> servers = CloudProxy.getInstance().getServers(serverFallback.getGroup());
            servers.remove(kickedFrom);
            if (servers.size() != 0) {
                return servers.get(NetworkUtils.RANDOM.nextInt(servers.size()));
            }
        }
    }
    String fallback = getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback();
    List<String> liste = new ArrayList<>(MapWrapper.filter(cachedServers, new Acceptable<ServerInfo>() {

        @Override
        public boolean isAccepted(ServerInfo value) {
            return value.getServiceId().getGroup().equalsIgnoreCase(fallback);
        }
    }).keySet());
    liste.remove(kickedFrom);
    if (liste.size() == 0)
        return null;
    else
        return liste.get(NetworkUtils.RANDOM.nextInt(liste.size()));
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ServerFallback(de.dytanic.cloudnet.lib.proxylayout.ServerFallback) ArrayList(java.util.ArrayList)

Aggregations

ServerFallback (de.dytanic.cloudnet.lib.proxylayout.ServerFallback)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)3 ArrayList (java.util.ArrayList)3 TabList (de.dytanic.cloudnet.lib.proxylayout.TabList)1 Acceptable (de.dytanic.cloudnet.lib.utility.Acceptable)1 List (java.util.List)1