2015-05-25 12:37:24 +02:00
|
|
|
--- a/net/minecraft/server/PacketStatusListener.java
|
|
|
|
+++ b/net/minecraft/server/PacketStatusListener.java
|
2015-02-05 20:04:03 +01:00
|
|
|
@@ -1,5 +1,16 @@
|
2014-11-25 22:32:16 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
+// CraftBukkit start
|
|
|
|
+import com.mojang.authlib.GameProfile;
|
2015-02-05 20:04:03 +01:00
|
|
|
+import io.netty.channel.ChannelFutureListener;
|
2014-11-25 22:32:16 +01:00
|
|
|
+import java.net.InetSocketAddress;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+
|
|
|
|
+import org.bukkit.craftbukkit.util.CraftIconCache;
|
|
|
|
+import org.bukkit.entity.Player;
|
|
|
|
+
|
|
|
|
+// CraftBukkit end
|
|
|
|
+
|
|
|
|
public class PacketStatusListener implements PacketStatusInListener {
|
|
|
|
|
2018-07-15 02:00:00 +02:00
|
|
|
private static final IChatBaseComponent a = new ChatMessage("multiplayer.status.request_handled", new Object[0]);
|
2019-07-20 01:00:00 +02:00
|
|
|
@@ -26,8 +37,96 @@
|
2015-07-27 14:19:19 +02:00
|
|
|
this.networkManager.close(PacketStatusListener.a);
|
2016-02-29 22:32:46 +01:00
|
|
|
} else {
|
|
|
|
this.d = true;
|
|
|
|
- this.networkManager.sendPacket(new PacketStatusOutServerInfo(this.minecraftServer.getServerPing()));
|
|
|
|
+ // CraftBukkit start
|
|
|
|
+ // this.networkManager.sendPacket(new PacketStatusOutServerInfo(this.minecraftServer.getServerPing()));
|
|
|
|
+ final Object[] players = minecraftServer.getPlayerList().players.toArray();
|
|
|
|
+ class ServerListPingEvent extends org.bukkit.event.server.ServerListPingEvent {
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ CraftIconCache icon = minecraftServer.server.getServerIcon();
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ ServerListPingEvent() {
|
|
|
|
+ super(((InetSocketAddress) networkManager.getSocketAddress()).getAddress(), minecraftServer.getMotd(), minecraftServer.getPlayerList().getMaxPlayers());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setServerIcon(org.bukkit.util.CachedServerIcon icon) {
|
|
|
|
+ if (!(icon instanceof CraftIconCache)) {
|
|
|
|
+ throw new IllegalArgumentException(icon + " was not created by " + org.bukkit.craftbukkit.CraftServer.class);
|
|
|
|
+ }
|
|
|
|
+ this.icon = (CraftIconCache) icon;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ @Override
|
|
|
|
+ public Iterator<Player> iterator() throws UnsupportedOperationException {
|
|
|
|
+ return new Iterator<Player>() {
|
|
|
|
+ int i;
|
|
|
|
+ int ret = Integer.MIN_VALUE;
|
|
|
|
+ EntityPlayer player;
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ @Override
|
|
|
|
+ public boolean hasNext() {
|
2014-11-25 22:32:16 +01:00
|
|
|
+ if (player != null) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
2016-02-29 22:32:46 +01:00
|
|
|
+ final Object[] currentPlayers = players;
|
|
|
|
+ for (int length = currentPlayers.length, i = this.i; i < length; i++) {
|
|
|
|
+ final EntityPlayer player = (EntityPlayer) currentPlayers[i];
|
|
|
|
+ if (player != null) {
|
|
|
|
+ this.i = i + 1;
|
|
|
|
+ this.player = player;
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ @Override
|
|
|
|
+ public Player next() {
|
|
|
|
+ if (!hasNext()) {
|
|
|
|
+ throw new java.util.NoSuchElementException();
|
|
|
|
+ }
|
|
|
|
+ final EntityPlayer player = this.player;
|
|
|
|
+ this.player = null;
|
|
|
|
+ this.ret = this.i - 1;
|
|
|
|
+ return player.getBukkitEntity();
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ @Override
|
|
|
|
+ public void remove() {
|
|
|
|
+ final Object[] currentPlayers = players;
|
|
|
|
+ final int i = this.ret;
|
|
|
|
+ if (i < 0 || currentPlayers[i] == null) {
|
|
|
|
+ throw new IllegalStateException();
|
|
|
|
+ }
|
|
|
|
+ currentPlayers[i] = null;
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
2016-02-29 22:32:46 +01:00
|
|
|
+ };
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ ServerListPingEvent event = new ServerListPingEvent();
|
|
|
|
+ this.minecraftServer.server.getPluginManager().callEvent(event);
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ java.util.List<GameProfile> profiles = new java.util.ArrayList<GameProfile>(players.length);
|
|
|
|
+ for (Object player : players) {
|
|
|
|
+ if (player != null) {
|
|
|
|
+ profiles.add(((EntityPlayer) player).getProfile());
|
|
|
|
+ }
|
2014-11-25 22:32:16 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ ServerPing.ServerPingPlayerSample playerSample = new ServerPing.ServerPingPlayerSample(event.getMaxPlayers(), profiles.size());
|
|
|
|
+ playerSample.a(profiles.toArray(new GameProfile[profiles.size()]));
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ ServerPing ping = new ServerPing();
|
|
|
|
+ ping.setFavicon(event.icon.value);
|
|
|
|
+ ping.setMOTD(new ChatComponentText(event.getMotd()));
|
|
|
|
+ ping.setPlayerSample(playerSample);
|
2019-12-10 23:00:00 +01:00
|
|
|
+ int version = SharedConstants.getGameVersion().getProtocolVersion();
|
2016-03-16 06:49:50 +01:00
|
|
|
+ ping.setServerInfo(new ServerPing.ServerData(minecraftServer.getServerModName() + " " + minecraftServer.getVersion(), version));
|
2014-11-25 22:32:16 +01:00
|
|
|
+
|
2016-02-29 22:32:46 +01:00
|
|
|
+ this.networkManager.sendPacket(new PacketStatusOutServerInfo(ping));
|
|
|
|
}
|
2014-11-25 22:32:16 +01:00
|
|
|
+ // CraftBukkit end
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:00:00 +02:00
|
|
|
@Override
|