PocketMine-MP 5.15.1 git-fb9a74e8799c71ed8292cfa53abe7a4c9204629d
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
22declare(strict_types=1);
23
24namespace pocketmine\command\defaults;
25
33use function count;
34
36
37 public function __construct(){
38 parent::__construct(
39 "time",
40 KnownTranslationFactory::pocketmine_command_time_description(),
41 KnownTranslationFactory::pocketmine_command_time_usage()
42 );
43 $this->setPermissions([
44 DefaultPermissionNames::COMMAND_TIME_ADD,
45 DefaultPermissionNames::COMMAND_TIME_SET,
46 DefaultPermissionNames::COMMAND_TIME_START,
47 DefaultPermissionNames::COMMAND_TIME_STOP,
48 DefaultPermissionNames::COMMAND_TIME_QUERY
49 ]);
50 }
51
52 public function execute(CommandSender $sender, string $commandLabel, array $args){
53 if(count($args) < 1){
55 }
56
57 if($args[0] === "start"){
58 if(!$this->testPermission($sender, DefaultPermissionNames::COMMAND_TIME_START)){
59 return true;
60 }
61 foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
62 $world->startTime();
63 }
64 Command::broadcastCommandMessage($sender, "Restarted the time");
65 return true;
66 }elseif($args[0] === "stop"){
67 if(!$this->testPermission($sender, DefaultPermissionNames::COMMAND_TIME_STOP)){
68 return true;
69 }
70 foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
71 $world->stopTime();
72 }
73 Command::broadcastCommandMessage($sender, "Stopped the time");
74 return true;
75 }elseif($args[0] === "query"){
76 if(!$this->testPermission($sender, DefaultPermissionNames::COMMAND_TIME_QUERY)){
77 return true;
78 }
79 if($sender instanceof Player){
80 $world = $sender->getWorld();
81 }else{
82 $world = $sender->getServer()->getWorldManager()->getDefaultWorld();
83 }
84 $sender->sendMessage($sender->getLanguage()->translate(KnownTranslationFactory::commands_time_query((string) $world->getTime())));
85 return true;
86 }
87
88 if(count($args) < 2){
90 }
91
92 if($args[0] === "set"){
93 if(!$this->testPermission($sender, DefaultPermissionNames::COMMAND_TIME_SET)){
94 return true;
95 }
96
97 switch($args[1]){
98 case "day":
99 $value = World::TIME_DAY;
100 break;
101 case "noon":
102 $value = World::TIME_NOON;
103 break;
104 case "sunset":
105 $value = World::TIME_SUNSET;
106 break;
107 case "night":
108 $value = World::TIME_NIGHT;
109 break;
110 case "midnight":
111 $value = World::TIME_MIDNIGHT;
112 break;
113 case "sunrise":
114 $value = World::TIME_SUNRISE;
115 break;
116 default:
117 $value = $this->getInteger($sender, $args[1], 0);
118 break;
119 }
120
121 foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
122 $world->setTime($value);
123 }
124 Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_time_set((string) $value));
125 }elseif($args[0] === "add"){
126 if(!$this->testPermission($sender, DefaultPermissionNames::COMMAND_TIME_ADD)){
127 return true;
128 }
129
130 $value = $this->getInteger($sender, $args[1], 0);
131 foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
132 $world->setTime($world->getTime() + $value);
133 }
134 Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_time_added((string) $value));
135 }else{
137 }
138
139 return true;
140 }
141}
setPermissions(array $permissions)
Definition: Command.php:96
execute(CommandSender $sender, string $commandLabel, array $args)
Definition: TimeCommand.php:52