PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
TimeCommand.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\command\defaults;
23 
28 
30 
31  public function __construct($name){
32  parent::__construct(
33  $name,
34  "Changes the time on each world",
35  "/time set <value>\n/time add <value>\n/time start|stop"
36  );
37  $this->setPermission("pocketmine.command.time.add;pocketmine.command.time.set;pocketmine.command.time.start;pocketmine.command.time.stop");
38  }
39 
40  public function execute(CommandSender $sender, $currentAlias, array $args){
41  if(count($args) < 1){
42  $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
43 
44  return false;
45  }
46 
47  if($args[0] === "start"){
48  if(!$sender->hasPermission("pocketmine.command.time.start")){
49  $sender->sendMessage(TextFormat::RED . "You don't have permission to restart the time");
50 
51  return true;
52  }
53  foreach($sender->getServer()->getLevels() as $level){
54  $level->checkTime();
55  $level->startTime();
56  $level->checkTime();
57  }
58  Command::broadcastCommandMessage($sender, "Restarted the time");
59  return true;
60  }elseif($args[0] === "stop"){
61  if(!$sender->hasPermission("pocketmine.command.time.stop")){
62  $sender->sendMessage(TextFormat::RED . "You don't have permission to stop the time");
63 
64  return true;
65  }
66  foreach($sender->getServer()->getLevels() as $level){
67  $level->checkTime();
68  $level->stopTime();
69  $level->checkTime();
70  }
71  Command::broadcastCommandMessage($sender, "Stopped the time");
72  return true;
73  }
74 
75 
76  if(count($args) < 2){
77  $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
78 
79  return false;
80  }
81 
82  if($args[0] === "set"){
83  if(!$sender->hasPermission("pocketmine.command.time.set")){
84  $sender->sendMessage(TextFormat::RED . "You don't have permission to set the time");
85 
86  return true;
87  }
88 
89  if($args[1] === "day"){
90  $value = 0;
91  }elseif($args[1] === "night"){
92  $value = Level::TIME_NIGHT;
93  }else{
94  $value = $this->getInteger($sender, $args[1], 0);
95  }
96 
97  foreach($sender->getServer()->getLevels() as $level){
98  $level->checkTime();
99  $level->setTime($value);
100  $level->checkTime();
101  }
102  Command::broadcastCommandMessage($sender, "Set time to " . $value);
103  }elseif($args[0] === "add"){
104  if(!$sender->hasPermission("pocketmine.command.time.add")){
105  $sender->sendMessage(TextFormat::RED . "You don't have permission to add the time");
106 
107  return true;
108  }
109 
110  $value = $this->getInteger($sender, $args[1], 0);
111  foreach($sender->getServer()->getLevels() as $level){
112  $level->checkTime();
113  $level->setTime($level->getTime() + $value);
114  $level->checkTime();
115  }
116  Command::broadcastCommandMessage($sender, "Added " . $value . " to time");
117  }else{
118  $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
119  }
120 
121  return true;
122  }
123 }
static broadcastCommandMessage(CommandSender $source, $message, $sendToSource=true)
Definition: Command.php:287
setPermission($permission)
Definition: Command.php:112