Search in sources :

Example 1 with ServerPing

use of com.velocitypowered.api.proxy.server.ServerPing in project TimoCloud by TimoCloud.

the class ProxyPing method onProxyPingEvent.

@Subscribe(order = PostOrder.EARLY)
public void onProxyPingEvent(ProxyPingEvent event) {
    ProxyObject proxyObject = TimoCloudAPI.getBungeeAPI().getThisProxy();
    ServerPing serverPing = event.getPing();
    serverPing = serverPing.asBuilder().maximumPlayers(proxyObject.getGroup().getMaxPlayerCount()).onlinePlayers(proxyObject.getGroup().getOnlinePlayerCount()).build();
    if (TimoCloudVelocity.getInstance().getFileManager().getConfig().getBoolean("useGlobalMotd"))
        serverPing = serverPing.asBuilder().description(Component.text(ChatColorUtil.translateAlternateColorCodes('&', proxyObject.getGroup().getMotd()))).build();
    event.setPing(serverPing);
}
Also used : ProxyObject(cloud.timo.TimoCloud.api.objects.ProxyObject) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 2 with ServerPing

use of com.velocitypowered.api.proxy.server.ServerPing in project OneVersionRemake by Andre601.

the class VelocityPingListener method onProxyPing.

@Subscribe(order = PostOrder.FIRST)
public void onProxyPing(ProxyPingEvent event) {
    ServerPing ping = event.getPing();
    ServerPing.Version protocolVersion = ping.getVersion();
    if (protocolVersion == null)
        return;
    int userProtocol = protocolVersion.getProtocol();
    List<Integer> serverProtocols = plugin.getConfigHandler().getIntList("Protocol", "Versions");
    if (serverProtocols.isEmpty())
        return;
    serverProtocols.sort(Comparator.reverseOrder());
    boolean majorOnly = plugin.getConfigHandler().getBoolean(false, "Protocol", "MajorOnly");
    String playerCount = plugin.getConfigHandler().getString("", "Messages", "PlayerCount");
    List<String> motd = plugin.getConfigHandler().getStringList("Messages", "Motd");
    List<String> hoverMessage = plugin.getConfigHandler().getStringList("Messages", "Hover");
    if (!serverProtocols.contains(userProtocol)) {
        ServerPing.Builder builder = ping.asBuilder();
        if (!hoverMessage.isEmpty()) {
            ServerPing.SamplePlayer[] players = plugin.getPlayers(hoverMessage, serverProtocols, userProtocol, majorOnly);
            if (players != null)
                builder.samplePlayers(players);
        }
        if (!playerCount.isEmpty()) {
            playerCount = plugin.getComponentParser().toString(playerCount, serverProtocols, userProtocol, majorOnly);
            builder.version(new ServerPing.Version(serverProtocols.get(0), playerCount));
        }
        if (!motd.isEmpty()) {
            if (motd.size() > 2)
                motd = motd.subList(0, 1);
            builder.description(plugin.getComponentParser().toComponent(motd, serverProtocols, userProtocol, majorOnly));
        }
        event.setPing(builder.build());
    }
}
Also used : ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 3 with ServerPing

use of com.velocitypowered.api.proxy.server.ServerPing in project Essential-PlayerInfo by Team-Jackdaw.

the class PingList method onPing.

// listener of player ping
@Subscribe
public void onPing(ProxyPingEvent event) {
    ServerPing response = event.getPing();
    ServerPing.SamplePlayer[] playerInfo = proxyServer.getAllPlayers().stream().map(player -> new ServerPing.SamplePlayer(player.getUsername(), player.getUniqueId())).toArray(ServerPing.SamplePlayer[]::new);
    ServerPing newResponse = response.asBuilder().samplePlayers(playerInfo).build();
    event.setPing(newResponse);
}
Also used : ProxyPingEvent(com.velocitypowered.api.event.proxy.ProxyPingEvent) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Inject(com.google.inject.Inject) ProxyServer(com.velocitypowered.api.proxy.ProxyServer) Subscribe(com.velocitypowered.api.event.Subscribe) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 4 with ServerPing

use of com.velocitypowered.api.proxy.server.ServerPing in project SubServers-2 by ME1312.

the class ExProxy method ping.

@Subscribe(order = PostOrder.LAST)
public void ping(ProxyPingEvent e) {
    int offline = 0;
    RegisteredServer[] overrides;
    if ((overrides = SmartFallback.getForcedHosts(e.getConnection())) != null || (overrides = SmartFallback.getDNS(e.getConnection())) != null) {
        for (RegisteredServer server : overrides) if (server instanceof SubServerData && !((SubServerData) server).isRunning())
            offline++;
        if (offline >= overrides.length) {
            e.setPing(new ServerPing(e.getPing().getVersion(), e.getPing().getPlayers().orElse(null), ChatColor.convertColor(api.getLang("SubServers", "Bungee.Ping.Offline")), e.getPing().getFavicon().orElse(null), e.getPing().getModinfo().orElse(null)));
        }
    } else {
        for (String name : proxy.getConfiguration().getAttemptConnectionOrder()) {
            ServerData server = proxy.getServer(name).map(RegisteredServer::getServerInfo).map(this::getData).orElse(null);
            if (server instanceof SubServerData && !((SubServerData) server).isRunning())
                offline++;
        }
        if (offline >= proxy.getConfiguration().getAttemptConnectionOrder().size()) {
            e.setPing(new ServerPing(e.getPing().getVersion(), e.getPing().getPlayers().orElse(null), ChatColor.convertColor(api.getLang("SubServers", "Bungee.Ping.Offline")), e.getPing().getFavicon().orElse(null), e.getPing().getModinfo().orElse(null)));
        }
    }
}
Also used : SubServerData(net.ME1312.SubServers.Velocity.Server.SubServerData) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) SubServerData(net.ME1312.SubServers.Velocity.Server.SubServerData) ServerData(net.ME1312.SubServers.Velocity.Server.ServerData) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 5 with ServerPing

use of com.velocitypowered.api.proxy.server.ServerPing in project CloudNet-v3 by CloudNetService.

the class VelocitySyncProxyPlayerListener method handle.

@Subscribe
public void handle(ProxyPingEvent event) {
    SyncProxyProxyLoginConfiguration syncProxyProxyLoginConfiguration = this.syncProxyManagement.getLoginConfiguration();
    if (syncProxyProxyLoginConfiguration != null) {
        SyncProxyMotd syncProxyMotd = this.syncProxyManagement.getRandomMotd();
        if (syncProxyMotd != null) {
            int onlinePlayers = this.syncProxyManagement.getSyncProxyOnlineCount();
            int maxPlayers = syncProxyMotd.isAutoSlot() ? Math.min(this.syncProxyManagement.getLoginConfiguration().getMaxPlayers(), onlinePlayers + syncProxyMotd.getAutoSlotMaxPlayersDistance()) : this.syncProxyManagement.getLoginConfiguration().getMaxPlayers();
            event.setPing(new ServerPing(syncProxyMotd.getProtocolText() != null ? new ServerPing.Version(1, syncProxyMotd.getProtocolText().replace("%proxy%", Wrapper.getInstance().getServiceId().getName()).replace("%proxy_uniqueId%", String.valueOf(Wrapper.getInstance().getServiceId().getUniqueId())).replace("%task%", Wrapper.getInstance().getServiceId().getTaskName()).replace("%node%", Wrapper.getInstance().getServiceId().getNodeUniqueId()).replace("%online_players%", String.valueOf(onlinePlayers)).replace("%max_players%", String.valueOf(maxPlayers)).replace("&", "§")) : event.getPing().getVersion(), new ServerPing.Players(onlinePlayers, maxPlayers, syncProxyMotd.getPlayerInfo() != null ? Arrays.stream(syncProxyMotd.getPlayerInfo()).map(s -> new ServerPing.SamplePlayer(s.replace("&", "§"), UUID.randomUUID())).collect(Collectors.toList()) : Collections.EMPTY_LIST), LegacyComponentSerializer.legacyLinking().deserialize((syncProxyMotd.getFirstLine() + "\n" + syncProxyMotd.getSecondLine()).replace("%proxy%", Wrapper.getInstance().getServiceId().getName()).replace("%proxy_uniqueId%", String.valueOf(Wrapper.getInstance().getServiceId().getUniqueId())).replace("%task%", Wrapper.getInstance().getServiceId().getTaskName()).replace("%node%", Wrapper.getInstance().getServiceId().getNodeUniqueId()).replace("&", "§")), event.getPing().getFavicon().isPresent() ? event.getPing().getFavicon().get() : null, event.getPing().getModinfo().isPresent() ? event.getPing().getModinfo().get() : null));
        }
    }
}
Also used : Arrays(java.util.Arrays) Wrapper(de.dytanic.cloudnet.wrapper.Wrapper) SyncProxyMotd(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) VelocitySyncProxyManagement(de.dytanic.cloudnet.ext.syncproxy.velocity.VelocitySyncProxyManagement) ProxyPingEvent(com.velocitypowered.api.event.proxy.ProxyPingEvent) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) ServerConnectedEvent(com.velocitypowered.api.event.player.ServerConnectedEvent) Subscribe(com.velocitypowered.api.event.Subscribe) LoginEvent(com.velocitypowered.api.event.connection.LoginEvent) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration) Collections(java.util.Collections) LegacyComponentSerializer(net.kyori.text.serializer.legacy.LegacyComponentSerializer) SyncProxyMotd(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

Subscribe (com.velocitypowered.api.event.Subscribe)5 ServerPing (com.velocitypowered.api.proxy.server.ServerPing)5 ProxyPingEvent (com.velocitypowered.api.event.proxy.ProxyPingEvent)2 ProxyObject (cloud.timo.TimoCloud.api.objects.ProxyObject)1 Inject (com.google.inject.Inject)1 LoginEvent (com.velocitypowered.api.event.connection.LoginEvent)1 ServerConnectedEvent (com.velocitypowered.api.event.player.ServerConnectedEvent)1 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)1 RegisteredServer (com.velocitypowered.api.proxy.server.RegisteredServer)1 SyncProxyMotd (de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd)1 SyncProxyProxyLoginConfiguration (de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration)1 VelocitySyncProxyManagement (de.dytanic.cloudnet.ext.syncproxy.velocity.VelocitySyncProxyManagement)1 Wrapper (de.dytanic.cloudnet.wrapper.Wrapper)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 ServerData (net.ME1312.SubServers.Velocity.Server.ServerData)1 SubServerData (net.ME1312.SubServers.Velocity.Server.SubServerData)1 LegacyComponentSerializer (net.kyori.text.serializer.legacy.LegacyComponentSerializer)1