Catch file saving exceptions

This commit is contained in:
Shoghi Cervantes 2015-02-15 20:01:47 +01:00
parent 5f4f996efe
commit 99ad65ba44
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
2 changed files with 38 additions and 22 deletions

View File

@ -811,8 +811,15 @@ class Server{
*/
public function saveOfflinePlayerData($name, Compound $nbtTag){
$nbt = new NBT(NBT::BIG_ENDIAN);
try{
$nbt->setData($nbtTag);
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
}catch(\Exception $e){
$this->logger->critical("Could not save player " . $name . ": " . $e->getMessage());
if(\pocketmine\DEBUG > 1 and $this->logger instanceof MainLogger){
$this->logger->logException($e);
}
}
}
/**

View File

@ -20,6 +20,7 @@
*/
namespace pocketmine\utils;
use pocketmine\Server;
/**
@ -123,7 +124,7 @@ class Config{
}
}
if($this->correct === true){
$content = @file_get_contents($this->file);
$content = file_get_contents($this->file);
switch($this->type){
case Config::PROPERTIES:
case Config::CNF:
@ -173,6 +174,7 @@ class Config{
*/
public function save(){
if($this->correct === true){
try{
$content = null;
switch($this->type){
case Config::PROPERTIES:
@ -186,13 +188,20 @@ class Config{
$content = yaml_emit($this->config, YAML_UTF8_ENCODING);
break;
case Config::SERIALIZED:
$content = @serialize($this->config);
$content = serialize($this->config);
break;
case Config::ENUM:
$content = implode("\r\n", array_keys($this->config));
break;
}
@file_put_contents($this->file, $content, LOCK_EX);
file_put_contents($this->file, $content);
}catch(\Exception $e){
$logger = Server::getInstance()->getLogger();
$logger->critical("Could not save Config " . $this->file . ": " . $e->getMessage());
if(\pocketmine\DEBUG > 1 and $logger instanceof MainLogger){
$logger->logException($e);
}
}
return true;
}else{