Commits

md_5 authored 9a4de097690
SPIGOT-7171: Ability to get the IP/hostname players are requesting status of
No tags

src/main/java/org/bukkit/event/server/ServerListPingEvent.java

Modified
13 13 /**
14 14 * Called when a server list ping is coming in. Displayed players can be
15 15 * checked and removed by {@link #iterator() iterating} over this event.
16 16 * <br>
17 17 * <b>Note:</b> The players in {@link #iterator()} will not be shown in the
18 18 * server info if {@link Bukkit#getHideOnlinePlayers()} is true.
19 19 */
20 20 public class ServerListPingEvent extends ServerEvent implements Iterable<Player> {
21 21 private static final int MAGIC_PLAYER_COUNT = Integer.MIN_VALUE;
22 22 private static final HandlerList handlers = new HandlerList();
23 + private final String hostname;
23 24 private final InetAddress address;
24 25 private final boolean shouldSendChatPreviews;
25 26 private String motd;
26 27 private final int numPlayers;
27 28 private int maxPlayers;
28 29
30 + @Deprecated
29 31 public ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, final boolean shouldSendChatPreviews, final int numPlayers, final int maxPlayers) {
32 + this("", address, motd, shouldSendChatPreviews, numPlayers, maxPlayers);
33 + }
34 +
35 + public ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final boolean shouldSendChatPreviews, final int numPlayers, final int maxPlayers) {
30 36 super(true);
31 37 Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online", numPlayers);
38 + this.hostname = hostname;
32 39 this.address = address;
33 40 this.motd = motd;
34 41 this.shouldSendChatPreviews = shouldSendChatPreviews;
35 42 this.numPlayers = numPlayers;
36 43 this.maxPlayers = maxPlayers;
37 44 }
38 45
46 + @Deprecated
47 + protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
48 + this("", address, motd, shouldSendChatPreviews, maxPlayers);
49 + }
50 +
39 51 /**
40 52 * This constructor is intended for implementations that provide the
41 53 * {@link #iterator()} method, thus provided the {@link #getNumPlayers()}
42 54 * count.
43 55 *
56 + * @param hostname The hostname that was used to connect to the server
44 57 * @param address the address of the pinger
45 58 * @param motd the message of the day
46 59 * @param shouldSendChatPreviews if the server should send chat previews
47 60 * @param maxPlayers the max number of players
48 61 */
49 - protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
62 + protected ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
50 63 super(true);
51 64 this.numPlayers = MAGIC_PLAYER_COUNT;
65 + this.hostname = hostname;
52 66 this.address = address;
53 67 this.motd = motd;
54 68 this.shouldSendChatPreviews = shouldSendChatPreviews;
55 69 this.maxPlayers = maxPlayers;
56 70 }
57 71
72 + /**
73 + * Gets the hostname that the player used to connect to the server, or
74 + * blank if unknown
75 + *
76 + * @return The hostname
77 + */
78 + @NotNull
79 + public String getHostname() {
80 + return hostname;
81 + }
82 +
58 83 /**
59 84 * Get the address the ping is coming from.
60 85 *
61 86 * @return the address
62 87 */
63 88 @NotNull
64 89 public InetAddress getAddress() {
65 90 return address;
66 91 }
67 92

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut