Search in sources :

Example 1 with Motd

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

the class ProxiedListener method handleProxyPing.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleProxyPing(ProxyPingEvent event) {
    ProxyGroup proxyGroup = CloudAPI.getInstance().getProxyGroupData(CloudAPI.getInstance().getGroup());
    if (proxyGroup != null && proxyGroup.getProxyConfig().isEnabled()) {
        ProxyConfig proxyConfig = proxyGroup.getProxyConfig();
        ServerPing serverPing = event.getResponse();
        if (!proxyConfig.isMaintenance()) {
            Motd motd = proxyConfig.getMotdsLayouts().get(NetworkUtils.RANDOM.nextInt(proxyConfig.getMotdsLayouts().size()));
            serverPing.setDescription(ChatColor.translateAlternateColorCodes('&', motd.getFirstLine() + "\n" + motd.getSecondLine()).replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%version%", CloudProxy.class.getPackage().getImplementationVersion()));
        } else {
            serverPing.setDescription(ChatColor.translateAlternateColorCodes('&', proxyConfig.getMaintenanceMotdLayout().getFirstLine() + "\n" + proxyConfig.getMaintenanceMotdLayout().getSecondLine()).replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%version%", CloudProxy.class.getPackage().getImplementationVersion()));
        }
        int onlineCount = CloudAPI.getInstance().getOnlineCount();
        int max = (proxyConfig.getAutoSlot().isEnabled() ? onlineCount + proxyConfig.getAutoSlot().getDynamicSlotSize() : proxyConfig.getMaxPlayers());
        ServerPing.PlayerInfo[] playerInfos = new ServerPing.PlayerInfo[proxyConfig.getPlayerInfo().length];
        for (short i = 0; i < playerInfos.length; i++) {
            playerInfos[i] = new ServerPing.PlayerInfo(ChatColor.translateAlternateColorCodes('&', proxyConfig.getPlayerInfo()[i]), UUID.randomUUID());
        }
        serverPing.setPlayers(new ServerPing.Players(max, onlineCount, playerInfos));
        if (proxyConfig.isMaintenance())
            serverPing.setVersion(new ServerPing.Protocol(proxyConfig.getMaintenaceProtocol(), 1));
        event.setResponse(serverPing);
    }
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) Motd(de.dytanic.cloudnet.lib.proxylayout.Motd) ProxyConfig(de.dytanic.cloudnet.lib.proxylayout.ProxyConfig) CloudProxy(de.dytanic.cloudnet.bridge.CloudProxy) ServerPing(net.md_5.bungee.api.ServerPing) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

CloudProxy (de.dytanic.cloudnet.bridge.CloudProxy)1 Motd (de.dytanic.cloudnet.lib.proxylayout.Motd)1 ProxyConfig (de.dytanic.cloudnet.lib.proxylayout.ProxyConfig)1 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)1 ServerPing (net.md_5.bungee.api.ServerPing)1 EventHandler (net.md_5.bungee.event.EventHandler)1