Class 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.
  • Constructor Details

  • 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)