mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Catch file saving exceptions
This commit is contained in:
parent
5f4f996efe
commit
99ad65ba44
@ -811,8 +811,15 @@ class Server{
|
|||||||
*/
|
*/
|
||||||
public function saveOfflinePlayerData($name, Compound $nbtTag){
|
public function saveOfflinePlayerData($name, Compound $nbtTag){
|
||||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||||
|
try{
|
||||||
$nbt->setData($nbtTag);
|
$nbt->setData($nbtTag);
|
||||||
file_put_contents($this->getDataPath() . "players/" . strtolower($name) . ".dat", $nbt->writeCompressed());
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace pocketmine\utils;
|
namespace pocketmine\utils;
|
||||||
|
use pocketmine\Server;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,7 +124,7 @@ class Config{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($this->correct === true){
|
if($this->correct === true){
|
||||||
$content = @file_get_contents($this->file);
|
$content = file_get_contents($this->file);
|
||||||
switch($this->type){
|
switch($this->type){
|
||||||
case Config::PROPERTIES:
|
case Config::PROPERTIES:
|
||||||
case Config::CNF:
|
case Config::CNF:
|
||||||
@ -173,6 +174,7 @@ class Config{
|
|||||||
*/
|
*/
|
||||||
public function save(){
|
public function save(){
|
||||||
if($this->correct === true){
|
if($this->correct === true){
|
||||||
|
try{
|
||||||
$content = null;
|
$content = null;
|
||||||
switch($this->type){
|
switch($this->type){
|
||||||
case Config::PROPERTIES:
|
case Config::PROPERTIES:
|
||||||
@ -186,13 +188,20 @@ class Config{
|
|||||||
$content = yaml_emit($this->config, YAML_UTF8_ENCODING);
|
$content = yaml_emit($this->config, YAML_UTF8_ENCODING);
|
||||||
break;
|
break;
|
||||||
case Config::SERIALIZED:
|
case Config::SERIALIZED:
|
||||||
$content = @serialize($this->config);
|
$content = serialize($this->config);
|
||||||
break;
|
break;
|
||||||
case Config::ENUM:
|
case Config::ENUM:
|
||||||
$content = implode("\r\n", array_keys($this->config));
|
$content = implode("\r\n", array_keys($this->config));
|
||||||
break;
|
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;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user