Interface PlayerContainer
This interface provides low-level access to the player cache, which maintains
wrapped IPlayer instances for all players in the current world view,
including the local player. The container is responsible for creating, updating,
and removing player wrappers as players spawn, change, or despawn in the game.
The container is updated each game tick and responds to player-related events to ensure the cache remains synchronized with the game state. Each player is indexed by their server-assigned ID, allowing O(1) retrieval.
For most use cases, prefer using IPlayers which
provides a higher-level API with filtering and searching capabilities.
Example usage:
// Get a player by index
IPlayer player = playerContainer.get(123);
// Get the local player
IPlayer me = playerContainer.getLocalPlayer();
// Get all cached players
Collection<IPlayer> allPlayers = playerContainer.getAll();
// Get the hint-arrowed player
IPlayer hinted = playerContainer.getHintArrowed();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreate(net.runelite.api.Player player) Creates or updates a player wrapper for the given RuneLite Player.get(int index) Gets a player by their server-assigned index (player ID).getAll()Gets all players currently in the cache.Gets the player that currently has the hint arrow pointing to them.Gets the local player (the player controlled by this client).
-
Method Details
-
get
Gets a player by their server-assigned index (player ID).The index is unique to each player in the current game session and is assigned by the server. This index is used to identify players in the player list.
- Parameters:
index- the server-assigned player index- Returns:
- the cached player wrapper, or null if no player exists at that index
-
getAll
Collection<IPlayer> getAll()Gets all players currently in the cache.Returns a collection of all player wrappers that are currently being tracked by this container. The collection represents a snapshot of all visible players in the current world view, including the local player.
- Returns:
- a collection of all cached players; never null but may be empty
-
getHintArrowed
IPlayer getHintArrowed()Gets the player that currently has the hint arrow pointing to them.The hint arrow is a visual indicator typically used by the game to highlight players that are relevant to the current activity, such as in minigames or certain quest scenarios.
- Returns:
- the hint-arrowed player, or null if no player has a hint arrow
-
getLocalPlayer
IPlayer getLocalPlayer()Gets the local player (the player controlled by this client).The local player is the character that the current game client is controlling. This is always available when logged into the game.
- Returns:
- the local player, or null if not logged in
-
create
Creates or updates a player wrapper for the given RuneLite Player.If a wrapper already exists for this player (based on their ID), the existing wrapper is updated with the new player data. Otherwise, a new wrapper is created and added to the cache.
This method is primarily used internally by the container to maintain the cache in response to game events.
- Parameters:
player- the RuneLite Player to wrap- Returns:
- the created or updated player wrapper
-