Added auto save to PlayerQuitEvent

This commit is contained in:
Shoghi Cervantes 2015-06-06 17:56:36 +02:00
parent 6ee61cce7b
commit 96f67bdadf
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
2 changed files with 17 additions and 5 deletions

View File

@ -1726,7 +1726,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
$nbt->lastPlayed = new Long(floor(microtime(true) * 1000));
$this->server->saveOfflinePlayerData($this->username, $nbt, true);
if($this->server->getAutoSave()){
$this->server->saveOfflinePlayerData($this->username, $nbt, true);
}
parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt);
$this->loggedIn = true;
@ -2864,8 +2866,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->connected = false;
if(strlen($this->getName()) > 0){
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));
if($this->server->getAutoSave() and $this->loggedIn === true){
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message, true));
if($this->loggedIn === true and $ev->getAutoSave()){
$this->save();
}
}
@ -2948,7 +2950,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
$this->namedtag["playerGameType"] = $this->gamemode;
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
$this->namedtag["lastPlayed"] = new Long(floor(microtime(true) * 1000));
if($this->username != "" and $this->namedtag instanceof Compound){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async);

View File

@ -31,10 +31,12 @@ class PlayerQuitEvent extends PlayerEvent{
/** @var string */
protected $quitMessage;
protected $autoSave = true;
public function __construct(Player $player, $quitMessage){
public function __construct(Player $player, $quitMessage, $autoSave = true){
$this->player = $player;
$this->quitMessage = $quitMessage;
$this->autoSave = true;
}
public function setQuitMessage($quitMessage){
@ -45,4 +47,12 @@ class PlayerQuitEvent extends PlayerEvent{
return $this->quitMessage;
}
public function getAutoSave(){
}
public function setAutoSave($value = true){
$this->autoSave = (bool) $value;
}
}