PocketMine-MP 5.15.1 git-fb9a74e8799c71ed8292cfa53abe7a4c9204629d
TitleCommand.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
30use function array_slice;
31use function count;
32use function implode;
33
35
36 public function __construct(){
37 parent::__construct(
38 "title",
39 KnownTranslationFactory::pocketmine_command_title_description(),
40 KnownTranslationFactory::commands_title_usage()
41 );
42 $this->setPermissions([
43 DefaultPermissionNames::COMMAND_TITLE_SELF,
44 DefaultPermissionNames::COMMAND_TITLE_OTHER
45 ]);
46 }
47
48 public function execute(CommandSender $sender, string $commandLabel, array $args){
49 if(count($args) < 2){
51 }
52
53 $player = $this->fetchPermittedPlayerTarget($sender, $args[0], DefaultPermissionNames::COMMAND_TITLE_SELF, DefaultPermissionNames::COMMAND_TITLE_OTHER);
54 if($player === null){
55 return true;
56 }
57
58 switch($args[1]){
59 case "clear":
60 $player->removeTitles();
61 break;
62 case "reset":
63 $player->resetTitles();
64 break;
65 case "title":
66 if(count($args) < 3){
68 }
69
70 $player->sendTitle(implode(" ", array_slice($args, 2)));
71 break;
72 case "subtitle":
73 if(count($args) < 3){
75 }
76
77 $player->sendSubTitle(implode(" ", array_slice($args, 2)));
78 break;
79 case "actionbar":
80 if(count($args) < 3){
82 }
83
84 $player->sendActionBarMessage(implode(" ", array_slice($args, 2)));
85 break;
86 case "times":
87 if(count($args) < 5){
89 }
90
91 $player->setTitleDuration($this->getInteger($sender, $args[2]), $this->getInteger($sender, $args[3]), $this->getInteger($sender, $args[4]));
92 break;
93 default:
95 }
96
97 $sender->sendMessage(KnownTranslationFactory::commands_title_success());
98
99 return true;
100 }
101}
setPermissions(array $permissions)
Definition: Command.php:96
execute(CommandSender $sender, string $commandLabel, array $args)