Added options to disable saving player.dat

This commit is contained in:
Dylan K. Taylor 2016-10-07 10:25:26 +01:00
parent 16c09e3610
commit d6fd9259cf
2 changed files with 21 additions and 11 deletions

View File

@ -668,6 +668,10 @@ class Server{
$this->craftingManager->registerRecipe($recipe);
}
public function shouldSavePlayerData() : bool{
return (bool) $this->getProperty("player.save-player-data", true);
}
/**
* @param string $name
*
@ -692,7 +696,7 @@ class Server{
public function getOfflinePlayerData($name){
$name = strtolower($name);
$path = $this->getDataPath() . "players/";
if(file_exists($path . "$name.dat")){
if($this->shouldSavePlayerData() and file_exists($path . "$name.dat")){
try{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(file_get_contents($path . "$name.dat"));
@ -806,18 +810,20 @@ class Server{
* @param bool $async
*/
public function saveOfflinePlayerData($name, CompoundTag $nbtTag, $async = false){
$nbt = new NBT(NBT::BIG_ENDIAN);
try{
$nbt->setData($nbtTag);
if($this->shouldSavePlayerData()){
$nbt = new NBT(NBT::BIG_ENDIAN);
try{
$nbt->setData($nbtTag);
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());
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(\Throwable $e){
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
$this->logger->logException($e);
}
}catch(\Throwable $e){
$this->logger->critical($this->getLanguage()->translateString("pocketmine.data.saveError", [$name, $e->getMessage()]));
$this->logger->logException($e);
}
}

View File

@ -89,6 +89,10 @@ debug:
level: 1
#Enables /status, /gc
commands: false
player:
#Choose whether to enable player data saving.
save-player-data: true
level-settings:
#The default format that levels will use when created