Merge pull request #1453 from onebone/Core-Rewrite

Added time command
This commit is contained in:
Shoghi Cervantes 2014-05-18 15:59:17 +02:00
commit b9502b9c2c
2 changed files with 69 additions and 0 deletions

View File

@ -53,6 +53,7 @@ use pocketmine\command\defaults\TellCommand;
use pocketmine\command\defaults\VanillaCommand;
use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\command\defaults\TimeCommand;
use pocketmine\Server;
class SimpleCommandMap implements CommandMap{
@ -101,6 +102,7 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new SetWorldSpawnCommand("setworldspawn"));
$this->register("pocketmine", new TeleportCommand("tp"));
$this->register("pocketmine", new ReloadCommand("reload"));
$this->register("pocketmine", new TimeCommand("time"));
if($this->server->getConfigBoolean("debug.commands", false) === true){
$this->register("pocketmine", new StatusCommand("status"));

View File

@ -0,0 +1,67 @@
<?php
namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
use pocketmine\network\protocol\SetTimePacket;
class TimeCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Changes the time on each world",
"/time set <value>\n/time add <value>"
);
$this->setPermission("pocketmine.command.time.add;pocketmine.command.set;");
}
public function execute(CommandSender $sender, $label, array $args){
if (count($args) < 2) {
$sender->sendMessage(TextFormat::RED."Incorrect usage. Correct usage:\n".$this->getUsage());
return false;
}
switch(strtolower($args[0])){
case "set":
if(!$sender->hasPermission("pocketmine.command.time.add")){
$sender->sendMessage(TextFormat::RED."You don't have permission to set the time");
return true;
}
if($args[1] === "day"){
$value = 0;
}elseif($args[1] === "night"){
$value = 12500;
}else{
$value = $this->getInteger($sender, $args[1], 0);
}
foreach(Server::getInstance()->getLevels() as $level){
$level->setTime($value);
}
Command::broadcastCommandMessage($sender, "Set time to ".$value);
return true;
case "add":
if (!$sender->hasPermission("pocketmine.command.time.add")){
$sender->sendMessage(TextFormat::RED."You don't have permission to set the time");
return true;
}
$value = $this->getInteger($sender, $args[1], 0);
foreach(Server::getInstance()->getLevels() as $level){
$level->setTime($level->getTime() + $value);
}
Command::broadcastCommandMessage($sender, "Added ".$value." to time");
return true;
default:
$sender->sendMessage("Unknown method. Usage: ".$this->getUsage());
}
}
}