Class PlayerManager
- java.lang.Object
-
- be.yildizgames.engine.feature.player.PlayerManager
-
- All Implemented Interfaces:
PlayerProvider
public final class PlayerManager extends Object implements PlayerProvider
Create and manage players.- Author:
- Grégory Van den Borre
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPlayerManager.PlayerRelationRelation between 2 players.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(be.yildizgames.common.model.PlayerCreationListener l)voidclear()Clear all registered players, this is only useful for tests.PlayercreatePlayer(be.yildizgames.common.model.PlayerId id, String name)Create a new player.PlayercreatePlayer(be.yildizgames.common.model.PlayerId id, String name, PlayerRight right)Create a new player.booleanexists(be.yildizgames.common.model.PlayerId id)Check if a player exists from its Id.booleanexists(String name)Check if a player exists.PlayerfindFromId(be.yildizgames.common.model.PlayerId id)Retrieve a player from its id.PlayergetFromId(be.yildizgames.common.model.PlayerId id)PlayergetFromName(String name)Retrieve a player from its name.static PlayerManagergetInstance()List<Player>getPlayerList()PlayerManager.PlayerRelationgetRelation(Player player, Player other)Retrieve the relation between two players.booleanisHostile(be.yildizgames.common.model.PlayerId p1, be.yildizgames.common.model.PlayerId p2)Check if player 1 is hostile toward player 2.booleanisValid(be.yildizgames.common.model.PlayerId p1, be.yildizgames.common.model.PlayerId p2, PlayerManager.PlayerRelation r)Check if the relation between player 1 and player 2 is valid, the check is done for the player 1, the relation between player 2 and player 1 is not taken into account.booleanisWorld(be.yildizgames.common.model.PlayerId id)booleanisWorld(Player p)
-
-
-
Method Detail
-
getInstance
public static PlayerManager getInstance()
-
findFromId
public Player findFromId(be.yildizgames.common.model.PlayerId id)
Retrieve a player from its id.- Parameters:
id- Id of the player to retrieve.- Returns:
- The player matching the id, or world if the player is not found.
-
getFromId
public Player getFromId(be.yildizgames.common.model.PlayerId id)
-
getFromName
public Player getFromName(String name)
Retrieve a player from its name.- Parameters:
name- Name of the player to retrieve.- Returns:
- The player matching the name.
- Throws:
be.yildizgames.engine.feature.player.PlayerManager.PlayerNotFoundException- If a matching player is not found in the list.
-
exists
public boolean exists(be.yildizgames.common.model.PlayerId id)
Check if a player exists from its Id.- Parameters:
id- Id to check.- Returns:
trueif the id is found.
-
createPlayer
public Player createPlayer(be.yildizgames.common.model.PlayerId id, String name, PlayerRight right)
Create a new player.- Parameters:
id- Player unique Id.name- Player unique name.right- Player rights,nullis allowed and the player will have Player right.- Returns:
- The created player.
- Throws:
be.yildizgames.engine.feature.player.PlayerManager.ExistingPlayerException- if the name already exists.be.yildizgames.engine.feature.player.PlayerManager.ExistingPlayerException- if the id already exists.
-
createPlayer
public Player createPlayer(be.yildizgames.common.model.PlayerId id, String name)
Create a new player.- Parameters:
id- Player unique Id.name- Player unique name.- Returns:
- The created player.
- Throws:
be.yildizgames.engine.feature.player.PlayerManager.ExistingPlayerException- if the name already exists.be.yildizgames.engine.feature.player.PlayerManager.ExistingPlayerException- if the id already exists.
-
getRelation
public PlayerManager.PlayerRelation getRelation(Player player, Player other)
Retrieve the relation between two players.- Parameters:
player- Player to test.other- Other player to test.- Returns:
- The relation between the two players.
-
getPlayerList
public List<Player> getPlayerList()
- Specified by:
getPlayerListin interfacePlayerProvider- Returns:
- The list of all players.
-
isWorld
public boolean isWorld(Player p)
- Parameters:
p- Player to check.- Returns:
trueif the player is world.
-
isWorld
public boolean isWorld(be.yildizgames.common.model.PlayerId id)
- Parameters:
id- Player to check.- Returns:
trueif the player is world.
-
isValid
public boolean isValid(be.yildizgames.common.model.PlayerId p1, be.yildizgames.common.model.PlayerId p2, PlayerManager.PlayerRelation r)Check if the relation between player 1 and player 2 is valid, the check is done for the player 1, the relation between player 2 and player 1 is not taken into account.- Parameters:
p1- Player to check for relation validity.p2- Player to be checked against.r- Relation to test.- Returns:
trueif the given relation is valid for player 1 toward player 2.
-
isHostile
public boolean isHostile(be.yildizgames.common.model.PlayerId p1, be.yildizgames.common.model.PlayerId p2)Check if player 1 is hostile toward player 2.- Parameters:
p1- Player 1 to check.p2- Player to be checked against.- Returns:
trueif player 1 is hostile to player 2.
-
exists
public boolean exists(String name)
Check if a player exists.- Parameters:
name- Name of the player to check.- Returns:
trueif the player is found.
-
addListener
public void addListener(be.yildizgames.common.model.PlayerCreationListener l)
-
clear
public void clear()
Clear all registered players, this is only useful for tests.
-
-