Class MockPlayerList

java.lang.Object
be.seeseemelk.mockbukkit.MockPlayerList

public class MockPlayerList extends Object
Replica of the Bukkit internal PlayerList and CraftPlayerList implementation
  • Constructor Details

    • MockPlayerList

      public MockPlayerList()
  • Method Details

    • setMaxPlayers

      public void setMaxPlayers(int maxPlayers)
      Sets the maximum number of online players. This is not currently enforced.
      Parameters:
      maxPlayers - The maximum amount of players.
    • getMaxPlayers

      public int getMaxPlayers()
      Returns:
      The maximum number of online players.
    • getIPBans

      @NotNull public @NotNull MockIpBanList getIPBans()
      Returns:
      All IP bans.
    • getProfileBans

      @NotNull public @NotNull MockProfileBanList getProfileBans()
      Returns:
      All profile bans.
    • addPlayer

      @Internal public void addPlayer(@NotNull @NotNull PlayerMock player)
      Marks a player as on the server, and sets related data like hasPlayedBefore and lastLogin.
      Parameters:
      player - The player to add.
    • disconnectPlayer

      @Internal public void disconnectPlayer(@NotNull @NotNull PlayerMock player)
      Marks a player as disconnected, and sets related data like lastSeen.
      Parameters:
      player - The player to disconnect.
    • hasPlayedBefore

      public boolean hasPlayedBefore(@NotNull @NotNull UUID uuid)
      Checks if a player has played before.
      Parameters:
      uuid - The UUID of the player.
      Returns:
      Whether the player has played before.
      See Also:
    • addOfflinePlayer

      @Internal public void addOfflinePlayer(@NotNull @NotNull OfflinePlayer player)
      Adds an offline player to the offline players set.
      Parameters:
      player - The player.
    • getFirstPlayed

      public long getFirstPlayed(UUID uuid)
      Gets the first time that this player was seen on the server.
      Parameters:
      uuid - The UUID of the player.
      Returns:
      The time of first log-in, or 0.
      See Also:
    • setFirstPlayed

      public void setFirstPlayed(UUID uuid, long firstPlayed)
      Sets the return value of getFirstPlayed(UUID).
      Parameters:
      uuid - UUID of the player to set first played time for.
      firstPlayed - The first played time. Must be non-negative.
    • getLastSeen

      public long getLastSeen(UUID uuid)
      Gets the last time a player was seen online.
      Parameters:
      uuid - The UUID of the player.
      Returns:
      The last time the player was seen online.
      See Also:
    • setLastSeen

      public void setLastSeen(UUID uuid, long lastSeen)
      Sets the return value of getLastLogin(UUID) while the player is offline. If the player is online, this will not have an effect.
      Parameters:
      uuid - UUID of the player to set last seen time for.
      lastSeen - The last seen time. Must be non-negative.
    • getLastLogin

      public long getLastLogin(UUID uuid)
      Gets the last time a player was seen online.
      Parameters:
      uuid - The UUID of the player.
      Returns:
      The last time the player was seen online.
      See Also:
    • setLastLogin

      public void setLastLogin(UUID uuid, long lastLogin)
      Sets the return value of getLastLogin(UUID).
      Parameters:
      uuid - UUID of the player to set last login time for.
      lastLogin - The last login time. Must be non-negative.
    • getOperators

      @NotNull public @NotNull Set<OfflinePlayer> getOperators()
      Returns:
      All server operators.
    • getOnlinePlayers

      @NotNull public @NotNull Collection<PlayerMock> getOnlinePlayers()
      Returns:
      All online players.
    • getOfflinePlayers

      @NotNull public @NotNull OfflinePlayer @NotNull [] getOfflinePlayers()
      Returns:
      All offline and online players.
    • isSomeoneOnline

      public boolean isSomeoneOnline()
      Returns:
      Whether anyone is online.
    • matchPlayer

      @NotNull public @NotNull List<Player> matchPlayer(@NotNull @NotNull String name)
      Matches a player by partial name.
      Parameters:
      name - The name to match by.
      Returns:
      All online players whose names start with the provided name.
    • getPlayerExact

      @Nullable public @Nullable Player getPlayerExact(@NotNull @NotNull String name)
      Matches a player by their exact name.
      Parameters:
      name - The name to match by.
      Returns:
      The player with the exact name provided, or null.
    • getPlayer

      @Nullable public @Nullable Player getPlayer(@NotNull @NotNull String name)
      Finds the player with the closest matching name.
      Parameters:
      name - The name to search with.
      Returns:
      The closest matching player.
    • getPlayer

      @Nullable public @Nullable Player getPlayer(@NotNull @NotNull UUID id)
      Parameters:
      id - The UUID of the player.
      Returns:
      The player with the provided UUID, or null.
    • getPlayer

      @NotNull public @NotNull PlayerMock getPlayer(int index)
      Gets a player at the provided index. Note player indexes will change whenever they join/leave.
      Parameters:
      index - The index.
      Returns:
      The player at the provided index.
    • getOfflinePlayer

      @NotNull public @NotNull OfflinePlayer getOfflinePlayer(@NotNull @NotNull String name)
      Gets an offline, or online player by name.
      Parameters:
      name - The name to match.
      Returns:
      The player, or offline player with the provided name.
      See Also:
    • getOfflinePlayer

      @Nullable public @Nullable OfflinePlayer getOfflinePlayer(@NotNull @NotNull UUID id)
      Gets an offline, or online player by UUID.
      Parameters:
      id - The UUID to match.
      Returns:
      The player, or offline player with the provided UUID.
      See Also:
    • clearOnlinePlayers

      public void clearOnlinePlayers()
      Clears all online players.
    • clearOfflinePlayers

      public void clearOfflinePlayers()
      Clears all offline players.
    • addOperator

      public void addOperator(UUID operator)
      Adds a Player to the list of known Operators.
      Parameters:
      operator - The UUID of the Operator to add.
    • removeOperator

      public void removeOperator(UUID operator)
      Removes a Player from the list of known Operators.
      Parameters:
      operator - The UUID of the Operator to remove.