Added /save-on, /save-off, /save-all

This commit is contained in:
Shoghi Cervantes 2014-04-02 04:37:58 +02:00
parent 9a5ffbe56c
commit a4630372fa
6 changed files with 186 additions and 11 deletions

View File

@ -2272,9 +2272,6 @@ class Player extends Human implements CommandSender, IPlayer{
if($this->loggedIn === true){
parent::close();
$this->save();
if($this->namedtag instanceof Compound){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag);
}
}
}
@ -2331,6 +2328,10 @@ class Player extends Human implements CommandSender, IPlayer{
$this->namedtag["lastPlayed"] = floor(microtime(true) * 1000);
//$this->data->set("health", $this->getHealth());
if($this->username != "" and $this->isOnline() and $this->namedtag instanceof Compound){
$this->server->saveOfflinePlayerData($this->username, $this->namedtag);
}
}
/**

View File

@ -676,12 +676,6 @@ class Server{
}
}
public function saveLevels(){
foreach($this->getLevels() as $level){
$level->save();
}
}
/**
* @return Level[]
*/
@ -1557,8 +1551,14 @@ class Server{
}
public function doAutoSave(){
$this->broadcast(TextFormat::GRAY . "Saving...", self::BROADCAST_CHANNEL_ADMINISTRATIVE);
$this->saveLevels();
/*foreach($this->getOnlinePlayers() as $player){
$player->save();
}*/
foreach($this->getLevels() as $level){
$level->save();
}
}
public function sendUsage(){

View File

@ -35,6 +35,9 @@ use pocketmine\command\defaults\OpCommand;
use pocketmine\command\defaults\PardonCommand;
use pocketmine\command\defaults\PardonIpCommand;
use pocketmine\command\defaults\PluginsCommand;
use pocketmine\command\defaults\SaveCommand;
use pocketmine\command\defaults\SaveOffCommand;
use pocketmine\command\defaults\SaveOnCommand;
use pocketmine\command\defaults\SayCommand;
use pocketmine\command\defaults\SeedCommand;
use pocketmine\command\defaults\StopCommand;
@ -80,6 +83,9 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new OpCommand("op"));
$this->register("pocketmine", new DeopCommand("deop"));
$this->register("pocketmine", new WhitelistCommand("whitelist"));
$this->register("pocketmine", new SaveOnCommand("save-on"));
$this->register("pocketmine", new SaveOffCommand("save-off"));
$this->register("pocketmine", new SaveCommand("save-all"));
}

View File

@ -0,0 +1,60 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
class SaveCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Saves the server to disk",
"/save-all"
);
$this->setPermission("pocketmine.command.save.perform");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(!$this->testPermission($sender)){
return true;
}
Command::broadcastCommandMessage($sender, "Forcing save...");
foreach(Server::getInstance()->getOnlinePlayers() as $player){
$player->save();
}
foreach(Server::getInstance()->getLevels() as $level){
$level->save(true);
}
Command::broadcastCommandMessage($sender, "Save complete.");
return true;
}
}

View File

@ -0,0 +1,54 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
class SaveOffCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Disables server autosaving",
"/save-off"
);
$this->setPermission("pocketmine.command.save.disable");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(!$this->testPermission($sender)){
return true;
}
foreach(Server::getInstance()->getLevels() as $level){
$level->setAutoSave(false);
}
Command::broadcastCommandMessage($sender, "Disabled level saving");
return true;
}
}

View File

@ -0,0 +1,54 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
class SaveOnCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Enables server autosaving",
"/save-on"
);
$this->setPermission("pocketmine.command.save.enable");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(!$this->testPermission($sender)){
return true;
}
foreach(Server::getInstance()->getLevels() as $level){
$level->setAutoSave(true);
}
Command::broadcastCommandMessage($sender, "Enabled level saving");
return true;
}
}