PlayerDataManager - Thouvvv/PlayerDataManager GitHub Wiki
\Thouv\PDM\PlayerDataManager
is the class that stores PDM's master instance. It is where instances of PDMPlayer
are managed.
PlayerDataManager::getInstance()
This is a static function that returns PDM's instance and is used to access the the PDM singleton.
PlayerDataManager::getProvider()
This method returns the provider. If enable-sync
is falsy in the config, this will return false
. If, on the other hand, synchronization is enabled in the [configuration
], this will return the master instance of [provider\PDMProvider
]. If PlayerDataManager::provider
is not an instance of provider\PDMProvider
(this can happen for a variety of reasons; the provider may not have been set or a connection may have timed out), PDM will attempt to set the provider. The return value will be normal if the provider can be set again successfully. If PDM fails to re-instantiate the provider, the return value is undefined. If this happens, there may be an error in the credentials set in the [configuration
].
PlayerDataManager::registerPlayer()
public function registerPlayer(string $player_name, bool $sync = false, bool $reset_if_exists = false)
$player_name
string
This is the name under which the player will be registered.
$sync
bool
This determines whether or not the player and its properties will be stored after a restart. By default, players are stored in memory and therefore ephemeral. If sync-enabled
is truthy in the [config
] and this is set to true
, the player will be registered in the provider. Its properties will also be synced unless specified otherwise. This is set to false
by default.
$reset_if_exists
bool
This determines whether attempting to register an existing player will reset said player. By default, doing so will only raise a warning and will not affect any player. However, setting this to true
will re-register the player and therefore reset all its properties, even in the provider.
This method will return the newly-created instance of PDMPlayer
on success, or false
if the player was already registered and $reset_if_exists
is set to false
.
PlayerDataManager::unregisterPlayer()
public function unregisterPlayer(string $player_name)
$player_name
string
This is the name of the player that will be unregistered.
This method will return true
upon success, or false
if the player does not exist.
PlayerDataManager::getPlayer()
public function getPlayer(string $player_name)
$player_name
string
This is the name of the player that will be returned.
This method will return the instance of PDMPlayer
with name $player_name
, or false
if the player does not exist.
$pdm = PlayerDataManager::getInstance();
$pdm_player = $pdm->registerPlayer("Thouvvv", true); // this player will be registered to the provider
var_dump($pdm_player);
/* object(PDMPlayer)#1 (3) { ["properties":protected]=> array(0) { }
["name":protected]=> string(7) "Thouvvv"
["sync":"PDMPlayer":private]=> bool(true) } */
$pdm_player = $pdm->registerPlayer("Thouvvv", false); // raises a warning; nothing happens
var_dump($pdm_player) // bool(false)
$pdm_player = $pdm->registerPlayer("Thouvvv", false, true);
// previous instance is reset; this player will not be registered to the provider
var_dump($pdm_player);
/* object(PDMPlayer)#1 (3) { ["properties":protected]=> array(0) { }
["name":protected]=> string(7) "Thouvvv"
["sync":"PDMPlayer":private]=> bool(false) } */
$pdm->unregisterPlayer("Thouvvv");
var_dump($pdm->getPlayer("Thouvvv")); // bool(true)
$pdm->registerPlayer("Thouvvv", true);
var_dump($pdm->getPlayer("Thouvvv"));
/* object(PDMPlayer)#1 (3) { ["properties":protected]=> array(0) { }
["name":protected]=> string(7) "Thouvvv"
["sync":"PDMPlayer":private]=> bool(true) } */