mirror of
https://github.com/PaperMC/Paper.git
synced 2025-03-02 11:22:01 +01:00
SPIGOT-7171: Ability to get the IP/hostname players are requesting status of
By: md_5 <git@md-5.net>
This commit is contained in:
parent
cbb1dd46c0
commit
b5059609a9
@ -20,15 +20,22 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class ServerListPingEvent extends ServerEvent implements Iterable<Player> {
|
public class ServerListPingEvent extends ServerEvent implements Iterable<Player> {
|
||||||
private static final int MAGIC_PLAYER_COUNT = Integer.MIN_VALUE;
|
private static final int MAGIC_PLAYER_COUNT = Integer.MIN_VALUE;
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final String hostname;
|
||||||
private final InetAddress address;
|
private final InetAddress address;
|
||||||
private final boolean shouldSendChatPreviews;
|
private final boolean shouldSendChatPreviews;
|
||||||
private String motd;
|
private String motd;
|
||||||
private final int numPlayers;
|
private final int numPlayers;
|
||||||
private int maxPlayers;
|
private int maxPlayers;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, final boolean shouldSendChatPreviews, final int numPlayers, final int maxPlayers) {
|
public ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, final boolean shouldSendChatPreviews, final int numPlayers, final int maxPlayers) {
|
||||||
|
this("", address, motd, shouldSendChatPreviews, numPlayers, maxPlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final boolean shouldSendChatPreviews, final int numPlayers, final int maxPlayers) {
|
||||||
super(true);
|
super(true);
|
||||||
Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online", numPlayers);
|
Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online", numPlayers);
|
||||||
|
this.hostname = hostname;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.motd = motd;
|
this.motd = motd;
|
||||||
this.shouldSendChatPreviews = shouldSendChatPreviews;
|
this.shouldSendChatPreviews = shouldSendChatPreviews;
|
||||||
@ -36,25 +43,43 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
|
|||||||
this.maxPlayers = maxPlayers;
|
this.maxPlayers = maxPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
|
||||||
|
this("", address, motd, shouldSendChatPreviews, maxPlayers);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is intended for implementations that provide the
|
* This constructor is intended for implementations that provide the
|
||||||
* {@link #iterator()} method, thus provided the {@link #getNumPlayers()}
|
* {@link #iterator()} method, thus provided the {@link #getNumPlayers()}
|
||||||
* count.
|
* count.
|
||||||
*
|
*
|
||||||
|
* @param hostname The hostname that was used to connect to the server
|
||||||
* @param address the address of the pinger
|
* @param address the address of the pinger
|
||||||
* @param motd the message of the day
|
* @param motd the message of the day
|
||||||
* @param shouldSendChatPreviews if the server should send chat previews
|
* @param shouldSendChatPreviews if the server should send chat previews
|
||||||
* @param maxPlayers the max number of players
|
* @param maxPlayers the max number of players
|
||||||
*/
|
*/
|
||||||
protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
|
protected ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
|
||||||
super(true);
|
super(true);
|
||||||
this.numPlayers = MAGIC_PLAYER_COUNT;
|
this.numPlayers = MAGIC_PLAYER_COUNT;
|
||||||
|
this.hostname = hostname;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.motd = motd;
|
this.motd = motd;
|
||||||
this.shouldSendChatPreviews = shouldSendChatPreviews;
|
this.shouldSendChatPreviews = shouldSendChatPreviews;
|
||||||
this.maxPlayers = maxPlayers;
|
this.maxPlayers = maxPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the hostname that the player used to connect to the server, or
|
||||||
|
* blank if unknown
|
||||||
|
*
|
||||||
|
* @return The hostname
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public String getHostname() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the address the ping is coming from.
|
* Get the address the ping is coming from.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user