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);
}
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());
}
}
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);
}
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)));
}
}
}
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));
}
}
}
Aggregations