From a3597e195ae8b1c17470584850d934a91b3d6c2d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 7 Jan 2021 23:37:47 +0000 Subject: [PATCH] Player: extract getSaveData() from save() this allows plugins to request this data whenever they want it (e.g. to save offline any time they want, instead of being confined to the server autosave interval). --- src/player/Player.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index 57c5c4e6ae..cdcd24aa86 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -2031,10 +2031,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ throw new \BadMethodCallException("Players can't be saved with chunks"); } - /** - * Handles player data saving - */ - public function save() : void{ + public function getSaveData() : CompoundTag{ $nbt = $this->saveNBT(); if($this->location->isValid()){ @@ -2063,7 +2060,14 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $nbt->setLong("firstPlayed", $this->firstPlayed); $nbt->setLong("lastPlayed", (int) floor(microtime(true) * 1000)); - $this->server->saveOfflinePlayerData($this->username, $nbt); + return $nbt; + } + + /** + * Handles player data saving + */ + public function save() : void{ + $this->server->saveOfflinePlayerData($this->username, $this->getSaveData()); } protected function onDeath() : void{