Changed usage message displaying to exceptions to reduce boilerplate code

Someday this won't need to be done by commands themselves, it'll be done by the parser.
This commit is contained in:
Dylan K. Taylor 2017-07-04 13:44:47 +01:00
parent 409fc282d2
commit 97f6a32557
31 changed files with 128 additions and 108 deletions

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\event\TranslationContainer; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\plugin\Plugin; use pocketmine\plugin\Plugin;
class PluginCommand extends Command implements PluginIdentifiableCommand{ class PluginCommand extends Command implements PluginIdentifiableCommand{
@ -58,7 +58,7 @@ class PluginCommand extends Command implements PluginIdentifiableCommand{
$success = $this->executor->onCommand($sender, $this, $commandLabel, $args); $success = $this->executor->onCommand($sender, $this, $commandLabel, $args);
if(!$success and $this->usageMessage !== ""){ if(!$success and $this->usageMessage !== ""){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
} }
return $success; return $success;

View File

@ -64,6 +64,7 @@ use pocketmine\command\defaults\TransferServerCommand;
use pocketmine\command\defaults\VanillaCommand; use pocketmine\command\defaults\VanillaCommand;
use pocketmine\command\defaults\VersionCommand; use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WhitelistCommand; use pocketmine\command\defaults\WhitelistCommand;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -216,13 +217,17 @@ class SimpleCommandMap implements CommandMap{
} }
$target->timings->startTiming(); $target->timings->startTiming();
try{ try{
$target->execute($sender, $sentCommandLabel, $args); $target->execute($sender, $sentCommandLabel, $args);
}catch(InvalidCommandSyntaxException $e){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$target->getUsage()]));
}catch(\Throwable $e){ }catch(\Throwable $e){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception")); $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
$this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.command.exception", [$commandLine, (string) $target, $e->getMessage()])); $this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.command.exception", [$commandLine, (string) $target, $e->getMessage()]));
$sender->getServer()->getLogger()->logException($e); $sender->getServer()->getLogger()->logException($e);
} }
$target->timings->stopTiming(); $target->timings->stopTiming();
return true; return true;

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
@ -45,9 +46,7 @@ class BanCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$name = array_shift($args); $name = array_shift($args);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
@ -45,9 +46,7 @@ class BanIpCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$value = array_shift($args); $value = array_shift($args);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\permission\BanEntry; use pocketmine\permission\BanEntry;
@ -50,9 +51,7 @@ class BanListCommand extends VanillaCommand{
}elseif($args[0] === "players"){ }elseif($args[0] === "players"){
$list = $sender->getServer()->getNameBans(); $list = $sender->getServer()->getNameBans();
}else{ }else{
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
}else{ }else{
$list = $sender->getServer()->getNameBans(); $list = $sender->getServer()->getNameBans();

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
@ -44,9 +45,7 @@ class DefaultGamemodeCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$gameMode = Server::getGamemodeFromString($args[0]); $gameMode = Server::getGamemodeFromString($args[0]);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -46,9 +47,7 @@ class DeopCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$name = array_shift($args); $name = array_shift($args);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\network\mcpe\protocol\SetDifficultyPacket;
use pocketmine\Server; use pocketmine\Server;
@ -46,9 +47,7 @@ class DifficultyCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$difficulty = Server::getDifficultyFromString($args[0]); $difficulty = Server::getDifficultyFromString($args[0]);
@ -66,9 +65,7 @@ class DifficultyCommand extends VanillaCommand{
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty])); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty]));
}else{ }else{
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
return true; return true;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\entity\Effect; use pocketmine\entity\Effect;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -45,9 +46,7 @@ class EffectCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$player = $sender->getServer()->getPlayer($args[0]); $player = $sender->getServer()->getPlayer($args[0]);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\Enchantment;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -45,9 +46,7 @@ class EnchantCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$player = $sender->getServer()->getPlayer($args[0]); $player = $sender->getServer()->getPlayer($args[0]);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\Server; use pocketmine\Server;
@ -47,9 +48,7 @@ class GamemodeCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$gameMode = Server::getGamemodeFromString($args[0]); $gameMode = Server::getGamemodeFromString($args[0]);
@ -69,9 +68,7 @@ class GamemodeCommand extends VanillaCommand{
return true; return true;
} }
}elseif(!($sender instanceof Player)){ }elseif(!($sender instanceof Player)){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$target->setGamemode($gameMode); $target->setGamemode($gameMode);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\nbt\JsonNBTParser; use pocketmine\nbt\JsonNBTParser;
@ -49,9 +50,7 @@ class GiveCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$player = $sender->getServer()->getPlayer($args[0]); $player = $sender->getServer()->getPlayer($args[0]);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -46,9 +47,7 @@ class KickCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$name = array_shift($args); $name = array_shift($args);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
@ -48,9 +49,7 @@ class KillCommand extends VanillaCommand{
} }
if(count($args) >= 2){ if(count($args) >= 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
if(count($args) === 1){ if(count($args) === 1){
@ -97,9 +96,7 @@ class KillCommand extends VanillaCommand{
$sender->setHealth(0); $sender->setHealth(0);
$sender->sendMessage(new TranslationContainer("commands.kill.successful", [$sender->getName()])); $sender->sendMessage(new TranslationContainer("commands.kill.successful", [$sender->getName()]));
}else{ }else{
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
return true; return true;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -45,9 +46,7 @@ class MeCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$sender->getServer()->broadcastMessage(new TranslationContainer("chat.type.emote", [$sender instanceof Player ? $sender->getDisplayName() : $sender->getName(), TextFormat::WHITE . implode(" ", $args)])); $sender->getServer()->broadcastMessage(new TranslationContainer("chat.type.emote", [$sender instanceof Player ? $sender->getDisplayName() : $sender->getName(), TextFormat::WHITE . implode(" ", $args)]));

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -46,9 +47,7 @@ class OpCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$name = array_shift($args); $name = array_shift($args);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
class PardonCommand extends VanillaCommand{ class PardonCommand extends VanillaCommand{
@ -44,9 +45,7 @@ class PardonCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$sender->getServer()->getNameBans()->remove($args[0]); $sender->getServer()->getNameBans()->remove($args[0]);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
class PardonIpCommand extends VanillaCommand{ class PardonIpCommand extends VanillaCommand{
@ -44,9 +45,7 @@ class PardonIpCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
if(preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/", $args[0])){ if(preg_match("/^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$/", $args[0])){

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\particle\AngryVillagerParticle; use pocketmine\level\particle\AngryVillagerParticle;
@ -77,9 +78,7 @@ class ParticleCommand extends VanillaCommand{
} }
if(count($args) < 7){ if(count($args) < 7){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
if($sender instanceof Player){ if($sender instanceof Player){

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\ConsoleCommandSender; use pocketmine\command\ConsoleCommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -46,9 +47,7 @@ class SayCommand extends VanillaCommand{
} }
if(count($args) === 0){ if(count($args) === 0){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$sender->getServer()->broadcastMessage(new TranslationContainer(TextFormat::LIGHT_PURPLE . "%chat.type.announcement", [$sender instanceof Player ? $sender->getDisplayName() : ($sender instanceof ConsoleCommandSender ? "Server" : $sender->getName()), TextFormat::LIGHT_PURPLE . implode(" ", $args)])); $sender->getServer()->broadcastMessage(new TranslationContainer(TextFormat::LIGHT_PURPLE . "%chat.type.announcement", [$sender instanceof Player ? $sender->getDisplayName() : ($sender instanceof ConsoleCommandSender ? "Server" : $sender->getName()), TextFormat::LIGHT_PURPLE . implode(" ", $args)]));

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -59,9 +60,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
$level = $sender->getServer()->getDefaultLevel(); $level = $sender->getServer()->getDefaultLevel();
$pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2])); $pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2]));
}else{ }else{
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$level->setSpawnLocation($pos); $level->setSpawnLocation($pos);

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\level\Position; use pocketmine\level\Position;
@ -94,8 +95,6 @@ class SpawnpointCommand extends VanillaCommand{
} }
} }
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
@ -50,9 +51,7 @@ class TeleportCommand extends VanillaCommand{
return strlen($arg) > 0; return strlen($arg) > 0;
}); });
if(count($args) < 1 or count($args) > 6){ if(count($args) < 1 or count($args) > 6){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$target = null; $target = null;
@ -121,8 +120,6 @@ class TeleportCommand extends VanillaCommand{
return true; return true;
} }
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -46,9 +47,7 @@ class TellCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$name = strtolower(array_shift($args)); $name = strtolower(array_shift($args));

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\Player; use pocketmine\Player;
@ -43,9 +44,7 @@ class TimeCommand extends VanillaCommand{
public function execute(CommandSender $sender, $currentAlias, array $args){ public function execute(CommandSender $sender, $currentAlias, array $args){
if(count($args) < 1){ if(count($args) < 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
if($args[0] === "start"){ if($args[0] === "start"){
@ -91,9 +90,7 @@ class TimeCommand extends VanillaCommand{
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
if($args[0] === "set"){ if($args[0] === "set"){
@ -132,7 +129,7 @@ class TimeCommand extends VanillaCommand{
} }
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.added", [$value])); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.added", [$value]));
}else{ }else{
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
} }
return true; return true;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TimingsHandler; use pocketmine\event\TimingsHandler;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\Player; use pocketmine\Player;
@ -49,9 +50,7 @@ class TimingsCommand extends VanillaCommand{
} }
if(count($args) !== 1){ if(count($args) !== 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$mode = strtolower($args[0]); $mode = strtolower($args[0]);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\command\defaults; namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
class TitleCommand extends VanillaCommand{ class TitleCommand extends VanillaCommand{
@ -43,8 +44,7 @@ class TitleCommand extends VanillaCommand{
} }
if(count($args) < 2){ if(count($args) < 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
$player = $sender->getServer()->getPlayer($args[0]); $player = $sender->getServer()->getPlayer($args[0]);
@ -62,39 +62,34 @@ class TitleCommand extends VanillaCommand{
break; break;
case "title": case "title":
if(count($args) < 3){ if(count($args) < 3){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$player->addTitle(implode(" ", array_slice($args, 2))); $player->addTitle(implode(" ", array_slice($args, 2)));
break; break;
case "subtitle": case "subtitle":
if(count($args) < 3){ if(count($args) < 3){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$player->addSubTitle(implode(" ", array_slice($args, 2))); $player->addSubTitle(implode(" ", array_slice($args, 2)));
break; break;
case "actionbar": case "actionbar":
if(count($args) < 3){ if(count($args) < 3){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$player->addActionBarMessage(implode(" ", array_slice($args, 2))); $player->addActionBarMessage(implode(" ", array_slice($args, 2)));
break; break;
case "times": case "times":
if(count($args) < 4){ if(count($args) < 4){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$player->setTitleDuration($this->getInteger($sender, $args[2]), $this->getInteger($sender, $args[3]), $this->getInteger($sender, $args[4])); $player->setTitleDuration($this->getInteger($sender, $args[2]), $this->getInteger($sender, $args[3]), $this->getInteger($sender, $args[4]));
break; break;
default: default:
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
} }
$sender->sendMessage(new TranslationContainer("commands.title.success")); $sender->sendMessage(new TranslationContainer("commands.title.success"));

View File

@ -26,7 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer; use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\Player; use pocketmine\Player;
class TransferServerCommand extends VanillaCommand{ class TransferServerCommand extends VanillaCommand{
@ -42,9 +42,7 @@ class TransferServerCommand extends VanillaCommand{
public function execute(CommandSender $sender, $commandLabel, array $args){ public function execute(CommandSender $sender, $commandLabel, array $args){
if(count($args) < 1){ if(count($args) < 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return false;
}elseif(!($sender instanceof Player)){ }elseif(!($sender instanceof Player)){
$sender->sendMessage("This command must be executed as a player"); $sender->sendMessage("This command must be executed as a player");

View File

@ -25,6 +25,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command; use pocketmine\command\Command;
use pocketmine\command\CommandSender; use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\event\TranslationContainer; use pocketmine\event\TranslationContainer;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -45,8 +46,7 @@ class WhitelistCommand extends VanillaCommand{
} }
if(count($args) === 0 or count($args) > 2){ if(count($args) === 0 or count($args) > 2){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); throw new InvalidCommandSyntaxException();
return true;
} }
if(count($args) === 1){ if(count($args) === 1){

View File

@ -0,0 +1,28 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\command\utils;
class CommandException extends \RuntimeException{
}

View File

@ -0,0 +1,28 @@
<?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/
*
*
*/
declare(strict_types=1);
namespace pocketmine\command\utils;
class InvalidCommandSyntaxException extends CommandException{
}