Package com.destroystokyo.paper.event.server

# Class PaperServerListPingEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.server.ServerEvent
org.bukkit.event.server.ServerListPingEvent
com.destroystokyo.paper.event.server.PaperServerListPingEvent

All Implemented Interfaces:
  `Iterable<Player>`, `Cancellable`

public class PaperServerListPingEvent extends ServerListPingEvent implements Cancellable
Extended version of `ServerListPingEvent` that allows full control of the response sent to the client.

## Nested Class Summary

## Nested classes/interfaces inherited from class org.bukkit.event.Event

`Event.Result`

## Constructor Summary

Constructors
Constructor
Description
`PaperServerListPingEvent(@NotNull StatusClient client, @NotNull String motd, int numPlayers, int maxPlayers, @NotNull String version, int protocolVersion, @Nullable CachedServerIcon favicon)`
Deprecated.
`PaperServerListPingEvent(@NotNull StatusClient client, Component motd, int numPlayers, int maxPlayers, @NotNull String version, int protocolVersion, @Nullable CachedServerIcon favicon)`

## Method Summary

Modifier and Type
Method
Description
`protected @NotNull Player`
`getBukkitPlayer(@NotNull Object player)`
`@NotNull StatusClient`
`getClient()`
Returns the `StatusClient` pinging the server.
`int`
`getMaxPlayers()`
Get the maximum number of players sent.
`int`
`getNumPlayers()`
Get the number of players sent.
`protected @NotNull Object[]`
`getOnlinePlayers()`
`@NotNull List<PlayerProfile>`
`getPlayerSample()`
Returns a mutable list of `PlayerProfile` that will be displayed as online players on the client.
`int`
`getProtocolVersion()`
Returns the protocol version that will be sent as the protocol version of the server to the client.
`@Nullable CachedServerIcon`
`getServerIcon()`
Gets the server icon sent to the client.
`@NotNull String`
`getVersion()`
Returns the version that will be sent as server version on the client.
`boolean`
`isCancelled()`
Gets the cancellation state of this event.
`@NotNull Iterator<Player>`
`iterator()`
`void`
`setCancelled(boolean cancel)`
Sets the cancellation state of this event.
`void`
`setHidePlayers(boolean hidePlayers)`
Sets whether all player related information is hidden in the server list.
`void`
`setNumPlayers(int numPlayers)`
Sets the number of players displayed in the server list.
`void`
`setProtocolVersion(int protocolVersion)`
Sets the protocol version that will be sent as the protocol version of the server to the client.
`void`
`setServerIcon(@Nullable CachedServerIcon icon)`
Sets the server icon sent to the client.
`void`
`setVersion(@NotNull String version)`
Sets the version that will be sent as server version to the client.
`boolean`
`shouldHidePlayers()`
Returns whether all player related information is hidden in the server list.

### Methods inherited from class org.bukkit.event.server.ServerListPingEvent

`getAddress, getHandlerList, getHandlers, getMotd, motd, motd, setMaxPlayers, setMotd`

### Methods inherited from class org.bukkit.event.Event

`callEvent, getEventName, isAsynchronous`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Constructor Details

### PaperServerListPingEvent

@Deprecated public PaperServerListPingEvent(@NotNull @NotNull StatusClient client, @NotNull @NotNull String motd, int numPlayers, int maxPlayers, @NotNull @NotNull String version, int protocolVersion, @Nullable @Nullable CachedServerIcon favicon)
Deprecated.

### PaperServerListPingEvent

public PaperServerListPingEvent(@NotNull @NotNull StatusClient client, @NotNull Component motd, int numPlayers, int maxPlayers, @NotNull @NotNull String version, int protocolVersion, @Nullable @Nullable CachedServerIcon favicon)

## Method Details

### getClient

@NotNull public @NotNull StatusClient getClient()
Returns the `StatusClient` pinging the server.

Returns:
  The client

### getNumPlayers

public int getNumPlayers()
Get the number of players sent.

Returns `-1` if players are hidden using `shouldHidePlayers()`.

Overrides:
  `getNumPlayers` in class `ServerListPingEvent`
Returns:
  the number of players

### setNumPlayers

public void setNumPlayers(int numPlayers)
Sets the number of players displayed in the server list.

Note that this won't have any effect if `shouldHidePlayers()` is enabled.

Parameters:
  `numPlayers` - The number of online players

### getMaxPlayers

public int getMaxPlayers()
Get the maximum number of players sent.

Returns `-1` if players are hidden using `shouldHidePlayers()`.

Overrides:
  `getMaxPlayers` in class `ServerListPingEvent`
Returns:
  the maximum number of players

### shouldHidePlayers

public boolean shouldHidePlayers()
Returns whether all player related information is hidden in the server list. This will cause `getNumPlayers()`, `getMaxPlayers()` and `getPlayerSample()` to be skipped in the response.

The Vanilla Minecraft client will display the player count as `???` when this option is enabled.

Returns:
  `true` if the player count is hidden

### setHidePlayers

public void setHidePlayers(boolean hidePlayers)
Sets whether all player related information is hidden in the server list. This will cause `getNumPlayers()`, `getMaxPlayers()` and `getPlayerSample()` to be skipped in the response.

The Vanilla Minecraft client will display the player count as `???` when this option is enabled.

Parameters:
  `hidePlayers` - `true` if the player count should be hidden

### getPlayerSample

@NotNull public @NotNull List<PlayerProfile> getPlayerSample()
Returns a mutable list of `PlayerProfile` that will be displayed as online players on the client.

The Vanilla Minecraft client will display them when hovering the player count with the mouse.

Returns:
  The mutable player sample list

### getVersion

@NotNull public @NotNull String getVersion()
Returns the version that will be sent as server version on the client.

Returns:
  The server version

### setVersion

public void setVersion(@NotNull @NotNull String version)
Sets the version that will be sent as server version to the client.

Parameters:
  `version` - The server version

### getProtocolVersion

public int getProtocolVersion()
Returns the protocol version that will be sent as the protocol version of the server to the client.

Returns:
  The protocol version of the server, or `-1` if the server has not finished initialization yet

### setProtocolVersion

public void setProtocolVersion(int protocolVersion)
Sets the protocol version that will be sent as the protocol version of the server to the client.

Parameters:
  `protocolVersion` - The protocol version of the server

### getServerIcon

@Nullable public @Nullable CachedServerIcon getServerIcon()
Gets the server icon sent to the client.

Returns:
  The icon to send to the client, or `null` for none

### setServerIcon

public void setServerIcon(@Nullable @Nullable CachedServerIcon icon)
Sets the server icon sent to the client.

Overrides:
  `setServerIcon` in class `ServerListPingEvent`
Parameters:
  `icon` - The icon to send to the client, or `null` for none

### isCancelled

public boolean isCancelled()
Gets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins

Cancelling this event will cause the connection to be closed immediately, without sending a response to the client.

Specified by:
  `isCancelled` in interface `Cancellable`
Returns:
  true if this event is cancelled

### setCancelled

public void setCancelled(boolean cancel)
Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.

Cancelling this event will cause the connection to be closed immediately, without sending a response to the client.

Specified by:
  `setCancelled` in interface `Cancellable`
Parameters:
  `cancel` - true if you wish to cancel this event

### iterator

@NotNull public @NotNull Iterator<Player> iterator()

Calling the `Iterator.remove()` method will force that particular player to not be displayed on the player list, decrease the size returned by `ServerListPingEvent.getNumPlayers()`, and will not be returned again by any new iterator.

Note: For compatibility reasons, this method will return all online players, not just the ones referenced in `getPlayerSample()`. Removing a player will:

- Decrement the online player count (if and only if) the player count wasn't changed by another plugin before.
- Remove all entries from `getPlayerSample()` that refer to the removed player (based on their `UUID`).

Specified by:
  `iterator` in interface `Iterable<Player>`
Overrides:
  `iterator` in class `ServerListPingEvent`

### getOnlinePlayers

@NotNull protected @NotNull Object[] getOnlinePlayers()

### getBukkitPlayer

@NotNull protected @NotNull Player getBukkitPlayer(@NotNull @NotNull Object player)