mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
Merge pull request #14 from pmmp/disable-player-dat
Added options to disable saving <player>.dat
This commit is contained in:
commit
beabc5a85c
@ -668,6 +668,10 @@ class Server{
|
|||||||
$this->craftingManager->registerRecipe($recipe);
|
$this->craftingManager->registerRecipe($recipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shouldSavePlayerData() : bool{
|
||||||
|
return (bool) $this->getProperty("player.save-player-data", true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
@ -692,18 +696,20 @@ class Server{
|
|||||||
public function getOfflinePlayerData($name){
|
public function getOfflinePlayerData($name){
|
||||||
$name = strtolower($name);
|
$name = strtolower($name);
|
||||||
$path = $this->getDataPath() . "players/";
|
$path = $this->getDataPath() . "players/";
|
||||||
if(file_exists($path . "$name.dat")){
|
if($this->shouldSavePlayerData()){
|
||||||
try{
|
if(file_exists($path . "$name.dat")){
|
||||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
try{
|
||||||
$nbt->readCompressed(file_get_contents($path . "$name.dat"));
|
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||||
|
$nbt->readCompressed(file_get_contents($path . "$name.dat"));
|
||||||
|
|
||||||
return $nbt->getData();
|
return $nbt->getData();
|
||||||
}catch(\Throwable $e){ //zlib decode error / corrupt data
|
}catch(\Throwable $e){ //zlib decode error / corrupt data
|
||||||
rename($path . "$name.dat", $path . "$name.dat.bak");
|
rename($path . "$name.dat", $path . "$name.dat.bak");
|
||||||
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerCorrupted", [$name]));
|
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerCorrupted", [$name]));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerNotFound", [$name]));
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
$this->logger->notice($this->getLanguage()->translateString("pocketmine.data.playerNotFound", [$name]));
|
|
||||||
}
|
}
|
||||||
$spawn = $this->getDefaultLevel()->getSafeSpawn();
|
$spawn = $this->getDefaultLevel()->getSafeSpawn();
|
||||||
$nbt = new CompoundTag("", [
|
$nbt = new CompoundTag("", [
|
||||||
@ -806,18 +812,20 @@ class Server{
|
|||||||
* @param bool $async
|
* @param bool $async
|
||||||
*/
|
*/
|
||||||
public function saveOfflinePlayerData($name, CompoundTag $nbtTag, $async = false){
|
public function saveOfflinePlayerData($name, CompoundTag $nbtTag, $async = false){
|
||||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
if($this->shouldSavePlayerData()){
|
||||||
try{
|
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||||
$nbt->setData($nbtTag);
|
try{
|
||||||
|
$nbt->setData($nbtTag);
|
||||||
|
|
||||||
if($async){
|
if($async){
|
||||||
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
|
$this->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed()));
|
||||||
}else{
|
}else{
|
||||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,10 @@ debug:
|
|||||||
level: 1
|
level: 1
|
||||||
#Enables /status, /gc
|
#Enables /status, /gc
|
||||||
commands: false
|
commands: false
|
||||||
|
|
||||||
|
player:
|
||||||
|
#Choose whether to enable player data saving.
|
||||||
|
save-player-data: true
|
||||||
|
|
||||||
level-settings:
|
level-settings:
|
||||||
#The default format that levels will use when created
|
#The default format that levels will use when created
|
||||||
|
Loading…
x
Reference in New Issue
Block a user