diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c7674a53f..191400cab 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3439,11 +3439,20 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function addTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1){ $this->setTitleDuration($fadeIn, $stay, $fadeOut); if($subtitle !== ""){ - $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SET_SUBTITLE); + $this->addSubTitle($subtitle); } $this->sendTitleText($title, SetTitlePacket::TYPE_SET_TITLE); } + /** + * Sets the subtitle message, without sending a title. + * + * @param string $subtitle + */ + public function addSubTitle(string $subtitle){ + $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SET_SUBTITLE); + } + /** * Adds small text to the user's screen. * @@ -3462,6 +3471,15 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->dataPacket($pk); } + /** + * Resets the title duration settings. + */ + public function resetTitles(){ + $pk = new SetTitlePacket(); + $pk->type = SetTitlePacket::TYPE_RESET_TITLE; + $this->dataPacket($pk); + } + /** * Sets the title duration. * diff --git a/src/pocketmine/command/SimpleCommandMap.php b/src/pocketmine/command/SimpleCommandMap.php index ae959c8ad..9d934bede 100644 --- a/src/pocketmine/command/SimpleCommandMap.php +++ b/src/pocketmine/command/SimpleCommandMap.php @@ -57,6 +57,7 @@ use pocketmine\command\defaults\TeleportCommand; use pocketmine\command\defaults\TellCommand; use pocketmine\command\defaults\TimeCommand; use pocketmine\command\defaults\TimingsCommand; +use pocketmine\command\defaults\TitleCommand; use pocketmine\command\defaults\TransferServerCommand; use pocketmine\command\defaults\VanillaCommand; use pocketmine\command\defaults\VersionCommand; @@ -115,6 +116,7 @@ class SimpleCommandMap implements CommandMap{ $this->register("pocketmine", new TeleportCommand("tp")); $this->register("pocketmine", new TimeCommand("time")); $this->register("pocketmine", new TimingsCommand("timings")); + $this->register("pocketmine", new TitleCommand("title")); $this->register("pocketmine", new ReloadCommand("reload")); $this->register("pocketmine", new TransferServerCommand("transferserver")); @@ -302,4 +304,4 @@ class SimpleCommandMap implements CommandMap{ } -} \ No newline at end of file +} diff --git a/src/pocketmine/command/defaults/TitleCommand.php b/src/pocketmine/command/defaults/TitleCommand.php new file mode 100644 index 000000000..1b4314722 --- /dev/null +++ b/src/pocketmine/command/defaults/TitleCommand.php @@ -0,0 +1,102 @@ +setPermission("pocketmine.command.title"); + } + + public function execute(CommandSender $sender, $currentAlias, array $args){ + if(!$this->testPermission($sender)){ + return true; + } + + if(count($args) < 2){ + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + return true; + } + + $player = $sender->getServer()->getPlayer($args[0]); + if($player === null){ + $sender->sendMessage(new TranslationContainer("commands.generic.player.notFound")); + return true; + } + + switch($args[1]){ + case "clear": + $player->removeTitles(); + break; + case "reset": + $player->resetTitles(); + break; + case "title": + if(count($args) < 3){ + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + return false; + } + + $player->addTitle(implode(" ", array_slice($args, 2))); + break; + case "subtitle": + if(count($args) < 3){ + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + return false; + } + + $player->addSubTitle(implode(" ", array_slice($args, 2))); + break; + case "actionbar": + if(count($args) < 3){ + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + return false; + } + + $player->addActionBarMessage(implode(" ", array_slice($args, 2))); + break; + case "times": + if(count($args) < 4){ + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + return false; + } + + $player->setTitleDuration($this->getInteger($sender, $args[2]), $this->getInteger($sender, $args[3]), $this->getInteger($sender, $args[4])); + break; + default: + $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); + return false; + } + + $sender->sendMessage(new TranslationContainer("commands.title.success")); + } +} diff --git a/src/pocketmine/permission/DefaultPermissions.php b/src/pocketmine/permission/DefaultPermissions.php index 079db04ff..10852f80a 100644 --- a/src/pocketmine/permission/DefaultPermissions.php +++ b/src/pocketmine/permission/DefaultPermissions.php @@ -124,6 +124,7 @@ abstract class DefaultPermissions{ self::registerPermission(new Permission(self::ROOT . ".command.spawnpoint", "Allows the user to change player's spawnpoint", Permission::DEFAULT_OP), $commands); self::registerPermission(new Permission(self::ROOT . ".command.setworldspawn", "Allows the user to change the world spawn", Permission::DEFAULT_OP), $commands); self::registerPermission(new Permission(self::ROOT . ".command.transferserver", "Allows the user to transfer self to another server", Permission::DEFAULT_OP), $commands); + self::registerPermission(new Permission(self::ROOT . ".command.title", "Allows the user to send a title to the specified player", Permission::DEFAULT_OP), $commands); $commands->recalculatePermissibles();