use of net.minecraft.network.status.server.SServerInfoPacket 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));
}
use of net.minecraft.network.status.server.SServerInfoPacket in project TheAPI by TheDevTec.
the class v1_16_R3_Mohist method processServerListPing.
@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
SServerInfoPacket status = (SServerInfoPacket) packet;
ServerStatusResponse ping;
try {
ping = (ServerStatusResponse) field.get(status);
} catch (Exception e) {
return false;
}
List<PlayerProfile> players = new ArrayList<>();
for (Player p : Bukkit.getOnlinePlayers()) players.add(new PlayerProfile(p.getName(), p.getUniqueId()));
ServerListPingEvent event = new ServerListPingEvent(Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers(), players, Bukkit.getMotd(), ping.func_151316_d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.func_151322_c().func_151303_a(), ping.func_151322_c().func_151304_b());
HandlerList.callEvent(event);
if (event.isCancelled())
return true;
Players playerSample = new Players(event.getMaxPlayers(), event.getOnlinePlayers());
if (event.getPlayersText() != null) {
GameProfile[] profiles = new GameProfile[event.getPlayersText().size()];
int i = -1;
for (PlayerProfile s : event.getPlayersText()) profiles[++i] = new GameProfile(s.getUUID(), s.getName());
playerSample.func_151330_a(profiles);
} else
playerSample.func_151330_a(new GameProfile[0]);
ping.func_151319_a(playerSample);
if (event.getMotd() != null)
ping.func_151315_a((ITextComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
else
ping.func_151315_a((ITextComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
if (event.getVersion() != null)
ping.func_151321_a(new Version(event.getVersion(), event.getProtocol()));
if (event.getFalvicon() != null)
ping.func_151320_a(event.getFalvicon());
return false;
}
Aggregations