Package com.tenio.entity.manager
Class PlayerManager
- java.lang.Object
-
- com.tenio.logger.AbstractLogger
-
- com.tenio.entity.manager.PlayerManager
-
- All Implemented Interfaces:
IManager
,IPlayerManager
public final class PlayerManager extends AbstractLogger implements IPlayerManager
Manage all your players (AbstractPlayer
) on the server. It is a singleton pattern class, which can be called anywhere. But it's better that you use thePlayerApi
interface for easy management.- Author:
- kong
- See Also:
IPlayerManager
-
-
Constructor Summary
Constructors Constructor Description PlayerManager(IEventManager eventManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(AbstractPlayer player)
Add a new player to your server (this player is known as one NCP or a BOT) without a attached connection.void
add(AbstractPlayer player, Connection connection)
Add a new player to your server (this player was upgraded from one connection).void
clean(AbstractPlayer player)
Make sure one player is removed from this management (as well as your server).void
clear()
Remove all players.boolean
contain(java.lang.String name)
Determine if the player has existed or not.int
count()
int
countPlayers()
AbstractPlayer
get(java.lang.String name)
Retrieve a player by the player's name.java.util.Map<java.lang.String,AbstractPlayer>
gets()
void
initialize(BaseConfiguration configuration)
Initializationvoid
remove(AbstractPlayer player)
Remove a player from your server.void
removeAllConnections(AbstractPlayer player)
When a player is disconnected, all the related connections need to be deleted too.
-
-
-
Constructor Detail
-
PlayerManager
public PlayerManager(IEventManager eventManager)
-
-
Method Detail
-
initialize
public void initialize(BaseConfiguration configuration)
Description copied from interface:IManager
Initialization- Specified by:
initialize
in interfaceIManager
- Parameters:
configuration
- the configuration, seeBaseConfiguration
-
count
public int count()
- Specified by:
count
in interfaceIPlayerManager
- Returns:
- the number of all current players' instance (include NPC or BOT)
-
countPlayers
public int countPlayers()
- Specified by:
countPlayers
in interfaceIPlayerManager
- Returns:
- the number of all current players that have connections (without NPC or BOT)
-
gets
public java.util.Map<java.lang.String,AbstractPlayer> gets()
- Specified by:
gets
in interfaceIPlayerManager
- Returns:
- all current players
-
clear
public void clear()
Description copied from interface:IPlayerManager
Remove all players.- Specified by:
clear
in interfaceIPlayerManager
-
contain
public boolean contain(java.lang.String name)
Description copied from interface:IPlayerManager
Determine if the player has existed or not.- Specified by:
contain
in interfaceIPlayerManager
- Parameters:
name
- the player's name (unique ID)- Returns:
- true if the player has existed, false otherwise
-
get
public AbstractPlayer get(java.lang.String name)
Description copied from interface:IPlayerManager
Retrieve a player by the player's name.- Specified by:
get
in interfaceIPlayerManager
- Parameters:
name
- the player's name (unique ID)- Returns:
- the player's instance if that player has existed, null otherwise
-
add
public void add(AbstractPlayer player, Connection connection)
Description copied from interface:IPlayerManager
Add a new player to your server (this player was upgraded from one connection).- Specified by:
add
in interfaceIPlayerManager
- Parameters:
player
- that is created from your server, see:AbstractPlayer
connection
- the main corresponding connection, see:Connection
-
add
public void add(AbstractPlayer player)
Description copied from interface:IPlayerManager
Add a new player to your server (this player is known as one NCP or a BOT) without a attached connection.- Specified by:
add
in interfaceIPlayerManager
- Parameters:
player
- that is created from your server, see:AbstractPlayer
-
remove
public void remove(AbstractPlayer player)
Description copied from interface:IPlayerManager
Remove a player from your server.- Specified by:
remove
in interfaceIPlayerManager
- Parameters:
player
- that is removed, seeAbstractPlayer
-
removeAllConnections
public void removeAllConnections(AbstractPlayer player)
Description copied from interface:IPlayerManager
When a player is disconnected, all the related connections need to be deleted too.- Specified by:
removeAllConnections
in interfaceIPlayerManager
- Parameters:
player
- the corresponding player, seeAbstractPlayer
-
clean
public void clean(AbstractPlayer player)
Description copied from interface:IPlayerManager
Make sure one player is removed from this management (as well as your server). It is used when you don't want your player can re-connect with any interruption's reason.- Specified by:
clean
in interfaceIPlayerManager
- Parameters:
player
- that is removed, seeAbstractPlayer
-
-