Class PlayerManager

  • All Implemented Interfaces:
    PlayerProvider

    public final class PlayerManager
    extends Object
    implements PlayerProvider
    Create and manage players.
    Author:
    Grégory Van den Borre
    • Method Detail

      • 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:
        true if 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, null is 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.
      • isWorld

        public boolean isWorld​(Player p)
        Parameters:
        p - Player to check.
        Returns:
        true if the player is world.
      • isWorld

        public boolean isWorld​(be.yildizgames.common.model.PlayerId id)
        Parameters:
        id - Player to check.
        Returns:
        true if 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:
        true if 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:
        true if 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:
        true if 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.