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