Search in sources :

Example 1 with ProxyPingEvent

use of com.velocitypowered.api.event.proxy.ProxyPingEvent 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 2 with ProxyPingEvent

use of com.velocitypowered.api.event.proxy.ProxyPingEvent in project Geyser by GeyserMC.

the class GeyserVelocityPingPassthrough method getPingInformation.

@Override
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
    ProxyPingEvent event;
    try {
        event = server.getEventManager().fire(new ProxyPingEvent(new GeyserInboundConnection(inetSocketAddress), ServerPing.builder().description(server.getConfiguration().getMotd()).onlinePlayers(server.getPlayerCount()).maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get();
    } catch (ExecutionException | InterruptedException e) {
        throw new RuntimeException(e);
    }
    GeyserPingInfo geyserPingInfo = new GeyserPingInfo(LegacyComponentSerializer.legacy('§').serialize(event.getPing().getDescriptionComponent()), new GeyserPingInfo.Players(event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getMax(), event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getOnline()), new GeyserPingInfo.Version(event.getPing().getVersion().getName(), event.getPing().getVersion().getProtocol()));
    event.getPing().getPlayers().get().getSample().stream().map(ServerPing.SamplePlayer::getName).forEach(geyserPingInfo.getPlayerList()::add);
    return geyserPingInfo;
}
Also used : ProxyPingEvent(com.velocitypowered.api.event.proxy.ProxyPingEvent) ExecutionException(java.util.concurrent.ExecutionException) GeyserPingInfo(org.geysermc.geyser.ping.GeyserPingInfo) ServerPing(com.velocitypowered.api.proxy.server.ServerPing)

Example 3 with ProxyPingEvent

use of com.velocitypowered.api.event.proxy.ProxyPingEvent 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

ProxyPingEvent (com.velocitypowered.api.event.proxy.ProxyPingEvent)3 ServerPing (com.velocitypowered.api.proxy.server.ServerPing)3 Subscribe (com.velocitypowered.api.event.Subscribe)2 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 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 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 LegacyComponentSerializer (net.kyori.text.serializer.legacy.LegacyComponentSerializer)1 GeyserPingInfo (org.geysermc.geyser.ping.GeyserPingInfo)1