mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 07:09:56 +00:00
Do async saving only when needed
This commit is contained in:
parent
4f7aac50d3
commit
be6b0656a0
@ -2807,7 +2807,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||||||
/**
|
/**
|
||||||
* Handles player data saving
|
* Handles player data saving
|
||||||
*/
|
*/
|
||||||
public function save(){
|
public function save($async = false){
|
||||||
if($this->closed){
|
if($this->closed){
|
||||||
throw new \InvalidStateException("Tried to save closed player");
|
throw new \InvalidStateException("Tried to save closed player");
|
||||||
}
|
}
|
||||||
@ -2830,7 +2830,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||||||
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
|
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
|
||||||
|
|
||||||
if($this->username != "" and $this->namedtag instanceof Compound){
|
if($this->username != "" and $this->namedtag instanceof Compound){
|
||||||
$this->server->saveOfflinePlayerData($this->username, $this->namedtag);
|
$this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -839,13 +839,18 @@ class Server{
|
|||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param Compound $nbtTag
|
* @param Compound $nbtTag
|
||||||
|
* @param bool $async
|
||||||
*/
|
*/
|
||||||
public function saveOfflinePlayerData($name, Compound $nbtTag){
|
public function saveOfflinePlayerData($name, Compound $nbtTag, $async = false){
|
||||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||||
try{
|
try{
|
||||||
$nbt->setData($nbtTag);
|
$nbt->setData($nbtTag);
|
||||||
|
|
||||||
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
|
if($async){
|
||||||
|
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
|
||||||
|
}else{
|
||||||
|
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
||||||
|
}
|
||||||
}catch(\Exception $e){
|
}catch(\Exception $e){
|
||||||
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
|
||||||
if(\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger){
|
if(\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger){
|
||||||
@ -1402,7 +1407,7 @@ class Server{
|
|||||||
if(($player = $this->getPlayerExact($name)) instanceof Player){
|
if(($player = $this->getPlayerExact($name)) instanceof Player){
|
||||||
$player->recalculatePermissions();
|
$player->recalculatePermissions();
|
||||||
}
|
}
|
||||||
$this->operators->save();
|
$this->operators->save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1422,7 +1427,7 @@ class Server{
|
|||||||
*/
|
*/
|
||||||
public function addWhitelist($name){
|
public function addWhitelist($name){
|
||||||
$this->whitelist->set(strtolower($name), true);
|
$this->whitelist->set(strtolower($name), true);
|
||||||
$this->whitelist->save();
|
$this->whitelist->save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1740,7 +1745,7 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->properties->save();
|
$this->properties->save(true);
|
||||||
|
|
||||||
if(!($this->getDefaultLevel() instanceof Level)){
|
if(!($this->getDefaultLevel() instanceof Level)){
|
||||||
$this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
|
$this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
|
||||||
@ -2283,7 +2288,7 @@ class Server{
|
|||||||
Timings::$worldSaveTimer->startTiming();
|
Timings::$worldSaveTimer->startTiming();
|
||||||
foreach($this->getOnlinePlayers() as $index => $player){
|
foreach($this->getOnlinePlayers() as $index => $player){
|
||||||
if($player->isOnline()){
|
if($player->isOnline()){
|
||||||
$player->save();
|
$player->save(true);
|
||||||
}elseif(!$player->isConnected()){
|
}elseif(!$player->isConnected()){
|
||||||
$this->removePlayer($player);
|
$this->removePlayer($player);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user