Search in sources :

Example 11 with ServerData

use of net.minecraft.server.v1_11_R1.ServerPing.ServerData in project TheAPI by TheDevTec.

the class v1_15_R1 method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
    ServerPing ping;
    try {
        ping = (ServerPing) 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.d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.getServerData().a(), ping.getServerData().getProtocolVersion());
    HandlerList.callEvent(event);
    if (event.isCancelled())
        return true;
    ServerPingPlayerSample playerSample = new ServerPingPlayerSample(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.a(profiles);
    } else
        playerSample.a(new GameProfile[0]);
    ping.setPlayerSample(playerSample);
    if (event.getMotd() != null)
        ping.setMOTD((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.setMOTD((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.setServerInfo(new ServerData(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.setFavicon(event.getFalvicon());
    return false;
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_15_R1.IChatBaseComponent) ServerPing(net.minecraft.server.v1_15_R1.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_15_R1.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_15_R1.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_15_R1.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 12 with ServerData

use of net.minecraft.server.v1_11_R1.ServerPing.ServerData in project TheAPI by TheDevTec.

the class v1_8_R2 method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
    ServerPing ping;
    try {
        ping = (ServerPing) 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.d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.c().a(), ping.c().b());
    HandlerList.callEvent(event);
    if (event.isCancelled())
        return true;
    ServerPingPlayerSample playerSample = new ServerPingPlayerSample(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.a(profiles);
    } else
        playerSample.a(new GameProfile[0]);
    ping.setPlayerSample(playerSample);
    if (event.getMotd() != null)
        ping.setMOTD((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.setMOTD((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.setServerInfo(new ServerData(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.setFavicon(event.getFalvicon());
    return false;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_8_R2.EntityPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_8_R2.IChatBaseComponent) ServerPing(net.minecraft.server.v1_8_R2.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_8_R2.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_8_R2.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_8_R2.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 13 with ServerData

use of net.minecraft.server.v1_11_R1.ServerPing.ServerData in project TheAPI by TheDevTec.

the class v1_16_R3 method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
    ServerPing ping;
    try {
        ping = (ServerPing) 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.d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.getServerData().a(), ping.getServerData().getProtocolVersion());
    HandlerList.callEvent(event);
    if (event.isCancelled())
        return true;
    ServerPingPlayerSample playerSample = new ServerPingPlayerSample(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.a(profiles);
    } else
        playerSample.a(new GameProfile[0]);
    ping.setPlayerSample(playerSample);
    if (event.getMotd() != null)
        ping.setMOTD((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.setMOTD((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.setServerInfo(new ServerData(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.setFavicon(event.getFalvicon());
    return false;
}
Also used : EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) 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) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) ServerPing(net.minecraft.server.v1_16_R3.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_16_R3.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_16_R3.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_16_R3.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)13 Channel (io.netty.channel.Channel)13 ArrayList (java.util.ArrayList)13 ServerListPingEvent (me.devtec.theapi.bukkit.events.ServerListPingEvent)13 PlayerProfile (me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile)13 Player (org.bukkit.entity.Player)13 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)1 IChatBaseComponent (net.minecraft.server.v1_10_R1.IChatBaseComponent)1 PacketStatusOutServerInfo (net.minecraft.server.v1_10_R1.PacketStatusOutServerInfo)1 ServerPing (net.minecraft.server.v1_10_R1.ServerPing)1 ServerData (net.minecraft.server.v1_10_R1.ServerPing.ServerData)1 ServerPingPlayerSample (net.minecraft.server.v1_10_R1.ServerPing.ServerPingPlayerSample)1 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)1 IChatBaseComponent (net.minecraft.server.v1_11_R1.IChatBaseComponent)1 PacketStatusOutServerInfo (net.minecraft.server.v1_11_R1.PacketStatusOutServerInfo)1 ServerPing (net.minecraft.server.v1_11_R1.ServerPing)1 ServerData (net.minecraft.server.v1_11_R1.ServerPing.ServerData)1 ServerPingPlayerSample (net.minecraft.server.v1_11_R1.ServerPing.ServerPingPlayerSample)1 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)1 IChatBaseComponent (net.minecraft.server.v1_12_R1.IChatBaseComponent)1