use of io.izzel.arclight.common.mod.util.ArclightPingEvent in project Arclight by IzzelAliz.
the class ServerStatusNetHandlerMixin method arclight$handleServerPing.
@Redirect(method = "processServerQuery", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;sendPacket(Lnet/minecraft/network/IPacket;)V"))
private void arclight$handleServerPing(NetworkManager networkManager, IPacket<?> packetIn) {
Object[] players = this.server.getPlayerList().players.toArray();
ArclightPingEvent event = new ArclightPingEvent(networkManager, server);
Bukkit.getPluginManager().callEvent(event);
List<GameProfile> profiles = new ArrayList<>(players.length);
Object[] array;
for (int length = (array = players).length, i = 0; i < length; ++i) {
Object player = array[i];
if (player != null) {
profiles.add(((ServerPlayerEntity) player).getGameProfile());
}
}
ServerStatusResponse.Players playerSample = new ServerStatusResponse.Players(event.getMaxPlayers(), profiles.size());
if (!profiles.isEmpty()) {
Collections.shuffle(profiles);
profiles = profiles.subList(0, Math.min(profiles.size(), SpigotConfig.playerSample));
}
playerSample.setPlayers(profiles.toArray(new GameProfile[0]));
ServerStatusResponse ping = new ServerStatusResponse();
ping.setFavicon(event.icon.value);
ping.setServerDescription(new StringTextComponent(event.getMotd()));
ping.setPlayers(playerSample);
int version = SharedConstants.getVersion().getProtocolVersion();
ping.setVersion(new ServerStatusResponse.Version(this.server.getServerModName() + " " + this.server.getMinecraftVersion(), version));
ping.setForgeData(this.server.getServerStatusResponse().getForgeData());
networkManager.sendPacket(new SServerInfoPacket(ping));
}
Aggregations