Merge branch 'release/3.4'

This commit is contained in:
Dylan K. Taylor 2018-11-04 23:25:05 +00:00
commit 0028ce0ed2
3 changed files with 14 additions and 40 deletions

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\command; namespace pocketmine\command;
use pocketmine\lang\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
@ -49,11 +48,6 @@ class FormattedCommandAlias extends Command{
$commands[] = $this->buildCommand($formatString, $args); $commands[] = $this->buildCommand($formatString, $args);
}catch(\InvalidArgumentException $e){ }catch(\InvalidArgumentException $e){
$sender->sendMessage(TextFormat::RED . $e->getMessage()); $sender->sendMessage(TextFormat::RED . $e->getMessage());
return false;
}catch(\Throwable $e){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
$sender->getServer()->getLogger()->logException($e);
return false; return false;
} }
} }

View File

@ -65,9 +65,7 @@ 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\command\utils\InvalidCommandSyntaxException;
use pocketmine\lang\TranslationContainer;
use pocketmine\Server; use pocketmine\Server;
use pocketmine\utils\TextFormat;
class SimpleCommandMap implements CommandMap{ class SimpleCommandMap implements CommandMap{
@ -258,14 +256,10 @@ class SimpleCommandMap implements CommandMap{
$target->execute($sender, $sentCommandLabel, $args); $target->execute($sender, $sentCommandLabel, $args);
}catch(InvalidCommandSyntaxException $e){ }catch(InvalidCommandSyntaxException $e){
$sender->sendMessage($this->server->getLanguage()->translateString("commands.generic.usage", [$target->getUsage()])); $sender->sendMessage($this->server->getLanguage()->translateString("commands.generic.usage", [$target->getUsage()]));
}catch(\Throwable $e){ }finally{
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception")); $target->timings->stopTiming();
$this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.command.exception", [$commandLine, (string) $target, $e->getMessage()]));
$sender->getServer()->getLogger()->logException($e);
} }
$target->timings->stopTiming();
return true; return true;
} }

View File

@ -30,8 +30,6 @@ namespace pocketmine\scheduler;
use pocketmine\utils\ReversePriorityQueue; use pocketmine\utils\ReversePriorityQueue;
class TaskScheduler{ class TaskScheduler{
/** @var \Logger */
private $logger;
/** @var string|null */ /** @var string|null */
private $owner; private $owner;
@ -54,9 +52,11 @@ class TaskScheduler{
/** @var int */ /** @var int */
protected $currentTick = 0; protected $currentTick = 0;
/**
* @param \Logger $logger @deprecated
* @param null|string $owner
*/
public function __construct(\Logger $logger, ?string $owner = null){ public function __construct(\Logger $logger, ?string $owner = null){
$this->logger = $logger;
$this->owner = $owner; $this->owner = $owner;
$this->queue = new ReversePriorityQueue(); $this->queue = new ReversePriorityQueue();
} }
@ -108,11 +108,9 @@ class TaskScheduler{
if(isset($this->tasks[$taskId])){ if(isset($this->tasks[$taskId])){
try{ try{
$this->tasks[$taskId]->cancel(); $this->tasks[$taskId]->cancel();
}catch(\Throwable $e){ }finally{
$this->logger->critical("Task " . $this->tasks[$taskId]->getTaskName() . " threw an exception when trying to cancel: " . $e->getMessage()); unset($this->tasks[$taskId]);
$this->logger->logException($e);
} }
unset($this->tasks[$taskId]);
} }
} }
@ -198,26 +196,14 @@ class TaskScheduler{
unset($this->tasks[$task->getTaskId()]); unset($this->tasks[$task->getTaskId()]);
continue; continue;
} }
$crashed = false; $task->run($this->currentTick);
try{
$task->run($this->currentTick);
}catch(\Throwable $e){
$crashed = true;
$this->logger->critical("Could not execute task " . $task->getTaskName() . ": " . $e->getMessage());
$this->logger->logException($e);
}
if($task->isRepeating()){ if($task->isRepeating()){
if($crashed){ $task->setNextRun($this->currentTick + $task->getPeriod());
$this->logger->debug("Dropping repeating task " . $task->getTaskName() . " due to exceptions thrown while running"); $this->queue->insert($task, $this->currentTick + $task->getPeriod());
}else{ }else{
$task->setNextRun($this->currentTick + $task->getPeriod()); $task->remove();
$this->queue->insert($task, $this->currentTick + $task->getPeriod()); unset($this->tasks[$task->getTaskId()]);
continue;
}
} }
$task->remove();
unset($this->tasks[$task->getTaskId()]);
} }
} }