PDMPlayer - Thouvvv/PlayerDataManager GitHub Wiki
Instances of \Thouv\PDM\PDMPlayer
are the main entities that make up this plugin. Each player has its own properties (PDMProperty
).
public function __construct(string $name, bool $sync)
This is the name of the player and is used to identify the instance.
This determines whether or not the player (and by extension its properties) will be stored in the provider. If enable-sync
is falsy in the [configuration
], this will be forcefully set to false
. If no value is provided, this will default to the value of enable-sync
in the [configuration
] (true
if such value is truthy, false
if it is falsy).
This method will return the player's name.
public function setProperties(array $properties, bool $update_if_existent = false, bool $hydrofoil = true)
These are the instances of PDMProperty
that will be set to the player.
This determines whether a property will be updated or ignored if it already exists. When set to false
(the default), attempting to set an existent property will raise a warning and ignore the property. When otherwise set to true
, it will log a notice and update the property. (see PDMPlayer::updateProperties()
).
This is a hacky parameter that is and should only be used internally (this means that you shouldn't use it!). When set to true
, it does not synchronize any of the properties with the provider no matter what. The proper way of achieving this is setting the no_sync
flag
of the property to a truthy value.
This method will return all of the player's properties.
public function updateProperties(array $properties, bool $set_if_nonexistent = false, bool $hydrofoil = true)
These are the instances of PDMProperty
that will be updated.
This determines whether a property will be set or ignored when it does not exist. When set to false
(the default), attempting to update a nonexistent property will raise a warning and ignore the property. When otherwise set to true
, it will log a notice and set the property (see PDMPlayer::setProperties()
).
This is a hacky parameter that is and should only be used internally (this means that you shouldn't use it!). When set to true
, it does not synchronize any of the properties with the provider no matter what. The proper way of achieving this is setting the no_sync
flag
of the property to a truthy value.
This method will return all of the player's properties.
public function unsetProperties(array $property_names)
These are the name of the properties that will be unset. ([See utils\PropertyUtils::propertyToPropertyName()
] on how to achieve this.)
This method will return all of the player's properties.
public function getProperties(array $conditions = null)
When this is null
, the method will return all of the player's properties. Otherwise, this is an array that dictates which properties should be returned. It is in the form [flag_name => [whitelist|blacklist, [value1, value2, value3, ...]], flag_name => [whitelist|blacklist, [value1, value2, value3, ...]], ...]
. When set to whitelist
mode ([flag_name => [whitelist, [value1, value2, value3, ...]]]
), this will return all of the properties whose $flag_name
flag
is one of value1
, value2
, or value3
. When otherwise set to blacklist
mode ([flag_name => [blacklist, [value1, value2, value3, ...]]]
), this will return all the properties whose $flag_name
flag
is not one of value1
, value2
, or value3
.
public function getProperty(string $property_name)
This is the name of the property that will be returned.
This method will return the instance of PDMProperty
with name $property_name
.
$thouv = new PDMPlayer("Thouvvv", true);
// don't do this in practice, you won't be able to access it through PlayerDataManager::getPlayer()
// until after a restart! Use PlayerDataManager::registerPlayer() instead
var_dump($thouv->setProperties(PDMPropertyFactory::makeProperties(
["old_name" => "ZePigThouv", "nickname" => "Thouv"]
)));
/* array(2) { ["first_name"]=> object(PDMProperty)#2 (3) {
["property_name":protected]=> string(10) "old_name" ["value":protected]=> string(10) "ZePigThouv"
["flags":"PDMProperty":private]=> array(0) { } } ["nickname"]=> object(PDMProperty)#3 (3) {
["property_name":protected]=> string(8) "nickname" ["value":protected]=> string(5) "Thouv"
["flags":"PDMProperty":private]=> array(0) { } } } */
$thouv->setProperties(
[PDMPropertyFactory::makeProperty("status", "Admin"),
PDMPropertyFactory::makeProperty("nickname", "Toova")],
false, true);
// "nickname" will be ignored, and "status" will not be synced with the provider
$thouv->updateProperties(PDMPropertyFactory::makeProperties(
["status" => "Head Admin",
"nickname" => "Toova",
"approval rating" => 0.84]),
true);
// this will update "status" and "nickname", and set "approval rating;" all will be synced with the provider
$properties = [$thouv->getProperty("approval rating"),
$thouv->getProperty("disapproval rating")];
foreach($properties as $property) {
if(!$property instanceof PDMProperty) {
echo "Not a property!\n";
var_dump($property);
continue;
}
echo $property->getPropertyName() . " ::: " . $property->getValue();
}
// approval rating ::: 0.84
// Not a property!
// bool(false)
$uuid = PDMPropertyFactory::makeProperty("uuid", "123456789qwertyuiop", ["hidden" => true]);
$thouv->setProperty([$uuid], false); // won't be synced!
$hidden_properties = $thouv->getProperties(
["hidden" =>
["whitelist", [true]]]);
var_dump($hidden_properties);
/* array(1) { ["uuid"]=> object(PDMProperty)#4 (3) {
["property_name":protected]=> string(4) "uuid" ["value":protected]=> string(19) "123456789qwertyuiop"
["flags":"PDMProperty":private]=> array(1) { ["hidden"]=> bool(true) } } } */
[PDMPropertyFactory documentation]