Move command timings to Timings::

this avoids duplicate timings entries when command labels are changed and changed back, or if multiple command maps are in use.
In addition, it also solves some PHPStan issues :)
This commit is contained in:
Dylan K. Taylor
2022-10-16 16:57:10 +01:00
parent 53cae8911d
commit bd01a919e5
5 changed files with 20 additions and 29 deletions

View File

@@ -68,6 +68,7 @@ use pocketmine\command\utils\CommandStringHelper;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\utils\TextFormat;
use function array_shift;
use function count;
@@ -199,7 +200,8 @@ class SimpleCommandMap implements CommandMap{
$sentCommandLabel = array_shift($args);
if($sentCommandLabel !== null && ($target = $this->getCommand($sentCommandLabel)) !== null){
$target->timings->startTiming();
$timings = Timings::getCommandDispatchTimings($target->getLabel());
$timings->startTiming();
try{
if($target->testPermission($sender)){
@@ -208,7 +210,7 @@ class SimpleCommandMap implements CommandMap{
}catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($sender->getLanguage()->translate(KnownTranslationFactory::commands_generic_usage($target->getUsage())));
}finally{
$target->timings->stopTiming();
$timings->stopTiming();
}
return true;
}