mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
PlayerDataSaveEvent: provide online player if possible, otherwise don't load offline data from disk for no reason (we already have it, that's the whole point of the event ...)
This commit is contained in:
parent
614891f8a2
commit
97a4d80854
@ -553,7 +553,7 @@ class Server{
|
||||
}
|
||||
|
||||
public function saveOfflinePlayerData(string $name, CompoundTag $nbtTag) : void{
|
||||
$ev = new PlayerDataSaveEvent($nbtTag, $name);
|
||||
$ev = new PlayerDataSaveEvent($nbtTag, $name, $this->getPlayerExact($name));
|
||||
if(!$this->shouldSavePlayerData()){
|
||||
$ev->cancel();
|
||||
}
|
||||
|
@ -27,8 +27,7 @@ use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\CancellableTrait;
|
||||
use pocketmine\event\Event;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\player\IPlayer;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\player\Player;
|
||||
|
||||
/**
|
||||
* Called when a player's data is about to be saved to disk.
|
||||
@ -40,10 +39,13 @@ class PlayerDataSaveEvent extends Event implements Cancellable{
|
||||
protected $data;
|
||||
/** @var string */
|
||||
protected $playerName;
|
||||
/** @var Player|null */
|
||||
private $player;
|
||||
|
||||
public function __construct(CompoundTag $nbt, string $playerName){
|
||||
public function __construct(CompoundTag $nbt, string $playerName, ?Player $player){
|
||||
$this->data = $nbt;
|
||||
$this->playerName = $playerName;
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,10 +67,10 @@ class PlayerDataSaveEvent extends Event implements Cancellable{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player whose data is being saved. This may be a Player or an OfflinePlayer.
|
||||
* @return IPlayer (Player or OfflinePlayer)
|
||||
* Returns the player whose data is being saved, if online.
|
||||
* If null, this data is for an offline player (possibly just disconnected).
|
||||
*/
|
||||
public function getPlayer() : IPlayer{
|
||||
return Server::getInstance()->getOfflinePlayer($this->playerName);
|
||||
public function getPlayer() : ?Player{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user