mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Fixed auto-save configuration, made it global
This commit is contained in:
parent
aa27c28e65
commit
2ded2013bf
@ -1136,7 +1136,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if(!$revert and !$this->isSleeping() and $this->isSurvival()){
|
||||
if($diff > 0.0625){
|
||||
$revert = true;
|
||||
$this->server->getLogger()->warning($this->getName()." moved wrongly!");
|
||||
//$this->server->getLogger()->warning($this->getName()." moved wrongly!");
|
||||
}elseif($diff > 0){
|
||||
$revert = !$this->setPosition($this->newPosition);
|
||||
}
|
||||
@ -2239,7 +2239,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->connected === true){
|
||||
if($this->username != ""){
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));
|
||||
if($this->loggedIn === true){
|
||||
if($this->server->getAutoSave() and $this->loggedIn === true){
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
@ -2313,11 +2313,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->dead === true or $this->spawned === false){
|
||||
return;
|
||||
}
|
||||
parent::kill();
|
||||
|
||||
if($this->inventory !== null){
|
||||
$this->inventory->clearAll();
|
||||
}
|
||||
|
||||
$message = $this->getName() . " died";
|
||||
$cause = $this->getLastDamageCause();
|
||||
@ -2400,7 +2395,20 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
}
|
||||
|
||||
if($this->dead){
|
||||
return;
|
||||
}
|
||||
|
||||
Entity::kill();
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), $message));
|
||||
foreach($ev->getDrops() as $item){
|
||||
$this->getLevel()->dropItem($this, $item);
|
||||
}
|
||||
|
||||
if($this->inventory !== null){
|
||||
$this->inventory->clearAll();
|
||||
}
|
||||
|
||||
if($ev->getDeathMessage() != ""){
|
||||
$this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
|
||||
|
@ -154,6 +154,9 @@ class Server{
|
||||
/** @var int */
|
||||
private $maxPlayers;
|
||||
|
||||
/** @var bool */
|
||||
private $autoSave;
|
||||
|
||||
/** @var RCON */
|
||||
private $rcon;
|
||||
|
||||
@ -296,6 +299,23 @@ class Server{
|
||||
return $this->getConfigString("server-name", "Unknown server");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getAutoSave(){
|
||||
return $this->autoSave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $value
|
||||
*/
|
||||
public function setAutoSave($value){
|
||||
$this->autoSave = (bool) $value;
|
||||
foreach($this->getLevels() as $level){
|
||||
$level->setAutoSave($this->autoSave);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@ -1480,6 +1500,7 @@ class Server{
|
||||
}
|
||||
|
||||
$this->maxPlayers = $this->getConfigInt("max-players", 20);
|
||||
$this->autoSave = $this->getConfigBoolean("auto-save", true);
|
||||
|
||||
if(($memory = str_replace("B", "", strtoupper($this->getConfigString("memory-limit", "256M")))) !== false){
|
||||
$value = ["M" => 1, "G" => 1024];
|
||||
@ -1612,7 +1633,7 @@ class Server{
|
||||
}
|
||||
|
||||
$this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([Cache::class, "cleanup"]), $this->getProperty("ticks-per.cache-cleanup", 900), $this->getProperty("ticks-per.cache-cleanup", 900));
|
||||
if($this->getConfigBoolean("auto-save", true) === true and $this->getProperty("ticks-per.autosave", 6000) > 0){
|
||||
if($this->getAutoSave() and $this->getProperty("ticks-per.autosave", 6000) > 0){
|
||||
$this->scheduler->scheduleDelayedRepeatingTask(new CallbackTask([$this, "doAutoSave"]), $this->getProperty("ticks-per.autosave", 6000), $this->getProperty("ticks-per.autosave", 6000));
|
||||
}
|
||||
|
||||
@ -1983,19 +2004,21 @@ class Server{
|
||||
}
|
||||
|
||||
public function doAutoSave(){
|
||||
Timings::$worldSaveTimer->startTiming();
|
||||
foreach($this->getOnlinePlayers() as $index => $player){
|
||||
if($player->isOnline()){
|
||||
$player->save();
|
||||
}elseif(!$player->isConnected()){
|
||||
unset($this->players[$index]);
|
||||
if($this->getAutoSave()){
|
||||
Timings::$worldSaveTimer->startTiming();
|
||||
foreach($this->getOnlinePlayers() as $index => $player){
|
||||
if($player->isOnline()){
|
||||
$player->save();
|
||||
}elseif(!$player->isConnected()){
|
||||
unset($this->players[$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->getLevels() as $level){
|
||||
$level->save(false);
|
||||
foreach($this->getLevels() as $level){
|
||||
$level->save(false);
|
||||
}
|
||||
Timings::$worldSaveTimer->stopTiming();
|
||||
}
|
||||
Timings::$worldSaveTimer->stopTiming();
|
||||
}
|
||||
|
||||
public function doLevelGC(){
|
||||
|
@ -41,9 +41,7 @@ class SaveOffCommand extends VanillaCommand{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach($sender->getServer()->getLevels() as $level){
|
||||
$level->setAutoSave(false);
|
||||
}
|
||||
$sender->getServer()->setAutoSave(false);
|
||||
|
||||
Command::broadcastCommandMessage($sender, "Disabled level saving");
|
||||
|
||||
|
@ -41,9 +41,7 @@ class SaveOnCommand extends VanillaCommand{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach($sender->getServer()->getLevels() as $level){
|
||||
$level->setAutoSave(true);
|
||||
}
|
||||
$sender->getServer()->setAutoSave(true);
|
||||
|
||||
Command::broadcastCommandMessage($sender, "Enabled level saving");
|
||||
|
||||
|
@ -239,6 +239,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->levelId = static::$levelIdCounter++;
|
||||
$this->blockMetadata = new BlockMetadataStore($this);
|
||||
$this->server = $server;
|
||||
$this->autoSave = $server->getAutoSave();
|
||||
|
||||
/** @var LevelProvider $provider */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user