Added title command and API for resetting title duration

This commit is contained in:
TheDiamondYT1
2017-04-27 16:38:51 +01:00
committed by Dylan K. Taylor
parent 84ec944b6b
commit 653b6b55a9
4 changed files with 125 additions and 2 deletions

View File

@ -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{
}
}
}

View File

@ -0,0 +1,102 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\plugin\Plugin;
use pocketmine\utils\TextFormat;
class TitleCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"%pocketmine.command.title.description",
"%commands.title.usage"
);
$this->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"));
}
}