Search in sources :

Example 6 with ServerListPingEvent

use of me.devtec.theapi.bukkit.events.ServerListPingEvent in project TheAPI by TheDevTec.

the class v1_14_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 : EntityPlayer(net.minecraft.server.v1_14_R1.EntityPlayer) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_14_R1.IChatBaseComponent) ServerPing(net.minecraft.server.v1_14_R1.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_14_R1.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_14_R1.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_14_R1.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 7 with ServerListPingEvent

use of me.devtec.theapi.bukkit.events.ServerListPingEvent in project TheAPI by TheDevTec.

the class v1_16_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.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 : CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_16_R2.IChatBaseComponent) ServerPing(net.minecraft.server.v1_16_R2.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_16_R2.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_16_R2.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_16_R2.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 8 with ServerListPingEvent

use of me.devtec.theapi.bukkit.events.ServerListPingEvent 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)

Example 9 with ServerListPingEvent

use of me.devtec.theapi.bukkit.events.ServerListPingEvent in project TheAPI by TheDevTec.

the class v1_18_R2 method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
    ServerPing ping = status.b();
    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.a(playerSample);
    if (event.getMotd() != null)
        ping.a((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.a((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.a(new ServerData(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.a(event.getFalvicon());
    return false;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.level.EntityPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.network.chat.IChatBaseComponent) ServerPing(net.minecraft.network.protocol.status.ServerPing) ServerPingPlayerSample(net.minecraft.network.protocol.status.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.network.protocol.status.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.network.protocol.status.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 10 with ServerListPingEvent

use of me.devtec.theapi.bukkit.events.ServerListPingEvent in project TheAPI by TheDevTec.

the class v1_7_R4 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().length, 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 ServerPingServerData(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_7_R4.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_7_R4.EntityPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(net.minecraft.util.io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_7_R4.IChatBaseComponent) ServerPing(net.minecraft.server.v1_7_R4.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_7_R4.ServerPingPlayerSample) ServerPingServerData(net.minecraft.server.v1_7_R4.ServerPingServerData) GameProfile(net.minecraft.util.com.mojang.authlib.GameProfile) PacketStatusOutServerInfo(net.minecraft.server.v1_7_R4.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Aggregations

ArrayList (java.util.ArrayList)19 ServerListPingEvent (me.devtec.theapi.bukkit.events.ServerListPingEvent)19 PlayerProfile (me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile)19 Player (org.bukkit.entity.Player)19 GameProfile (com.mojang.authlib.GameProfile)18 Channel (io.netty.channel.Channel)18 IChatBaseComponent (net.minecraft.network.chat.IChatBaseComponent)3 PacketStatusOutServerInfo (net.minecraft.network.protocol.status.PacketStatusOutServerInfo)3 ServerPing (net.minecraft.network.protocol.status.ServerPing)3 ServerData (net.minecraft.network.protocol.status.ServerPing.ServerData)3 ServerPingPlayerSample (net.minecraft.network.protocol.status.ServerPing.ServerPingPlayerSample)3 EntityPlayer (net.minecraft.server.level.EntityPlayer)3 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 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