Search in sources :

Example 1 with Players

use of net.minecraft.network.ServerStatusResponse.Players 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;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) Player(org.bukkit.entity.Player) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) GameProfile(com.mojang.authlib.GameProfile) Version(net.minecraft.network.ServerStatusResponse.Version) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent) SServerInfoPacket(net.minecraft.network.status.server.SServerInfoPacket) Players(net.minecraft.network.ServerStatusResponse.Players)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 Channel (io.netty.channel.Channel)1 ArrayList (java.util.ArrayList)1 ServerListPingEvent (me.devtec.theapi.bukkit.events.ServerListPingEvent)1 PlayerProfile (me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile)1 ServerStatusResponse (net.minecraft.network.ServerStatusResponse)1 Players (net.minecraft.network.ServerStatusResponse.Players)1 Version (net.minecraft.network.ServerStatusResponse.Version)1 SServerInfoPacket (net.minecraft.network.status.server.SServerInfoPacket)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)1 Player (org.bukkit.entity.Player)1