#759: Add preview chat option in ServerListPingEvent

By: Doc <nachito94@msn.com>
This commit is contained in:
Bukkit/Spigot 2022-06-18 20:55:23 +10:00
parent 3cdd9f03ce
commit 1a5ff83244

View File

@ -21,15 +21,17 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
private static final int MAGIC_PLAYER_COUNT = Integer.MIN_VALUE;
private static final HandlerList handlers = new HandlerList();
private final InetAddress address;
private final boolean shouldSendChatPreviews;
private String motd;
private final int numPlayers;
private int maxPlayers;
public ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, 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) {
super(true);
Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online", numPlayers);
this.address = address;
this.motd = motd;
this.shouldSendChatPreviews = shouldSendChatPreviews;
this.numPlayers = numPlayers;
this.maxPlayers = maxPlayers;
}
@ -41,13 +43,15 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
*
* @param address the address of the pinger
* @param motd the message of the day
* @param shouldSendChatPreviews if the server should send chat previews
* @param maxPlayers the max number of players
*/
protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, final int maxPlayers) {
protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final String motd, boolean shouldSendChatPreviews, final int maxPlayers) {
super(true);
this.numPlayers = MAGIC_PLAYER_COUNT;
this.address = address;
this.motd = motd;
this.shouldSendChatPreviews = shouldSendChatPreviews;
this.maxPlayers = maxPlayers;
}
@ -105,6 +109,16 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
return maxPlayers;
}
/**
* Gets whether the server needs to send a preview of the chat to the
* client.
*
* @return true if chat preview is enabled, false otherwise
*/
public boolean shouldSendChatPreviews() {
return shouldSendChatPreviews;
}
/**
* Set the maximum number of players sent.
*