Added /time command

This commit is contained in:
Shoghi Cervantes 2014-06-17 18:36:39 +02:00
parent b27637c926
commit f14fecbb5f
2 changed files with 84 additions and 0 deletions

View File

@ -101,6 +101,7 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new SpawnpointCommand("spawnpoint")); $this->register("pocketmine", new SpawnpointCommand("spawnpoint"));
$this->register("pocketmine", new SetWorldSpawnCommand("setworldspawn")); $this->register("pocketmine", new SetWorldSpawnCommand("setworldspawn"));
$this->register("pocketmine", new TeleportCommand("tp")); $this->register("pocketmine", new TeleportCommand("tp"));
$this->register("pocketmine", new TimeCommand("time"));
$this->register("pocketmine", new ReloadCommand("reload")); $this->register("pocketmine", new ReloadCommand("reload"));
if($this->server->getProperty("debug.commands", false) === true){ if($this->server->getProperty("debug.commands", false) === true){

View File

@ -0,0 +1,83 @@
<?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\utils\TextFormat;
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.time.set");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(count($args) < 2){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
return false;
}
if($args[0] === "set"){
if(!$sender->hasPermission("pocketmine.command.time.set")){
$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($sender->getServer()->getLevels() as $level){
$level->checkTime();
$level->setTime($value);
$level->checkTime();
}
Command::broadcastCommandMessage($sender, "Set time to " . $value);
}elseif($args[0] === "add"){
if(!$sender->hasPermission("pocketmine.command.time.add")){
$sender->sendMessage(TextFormat::RED . "You don't have permission to add the time");
return true;
}
$value = $this->getInteger($sender, $args[1], 0);
foreach($sender->getServer()->getLevels() as $level){
$level->checkTime();
$level->setTime($level->getTime() + $value);
$level->checkTime();
}
}else{
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
}
return true;
}
}