diff --git a/src/xenialdan/MagicWE2/commands/selection/info/CountCommand.php b/src/xenialdan/MagicWE2/commands/selection/info/CountCommand.php index 71c313b1..ba220907 100644 --- a/src/xenialdan/MagicWE2/commands/selection/info/CountCommand.php +++ b/src/xenialdan/MagicWE2/commands/selection/info/CountCommand.php @@ -42,53 +42,48 @@ protected function prepare(): void * @param string $aliasUsed * @param mixed[] $args */ - public function onRun(CommandSender $sender, string $aliasUsed, array $args): void - { - $lang = Loader::getInstance()->getLanguage(); - if ($sender instanceof Player && SessionHelper::hasSession($sender)) { - try { - $lang = SessionHelper::getUserSession($sender)->getLanguage(); - } catch (SessionException $e) { - } - } - if (!$sender instanceof Player) { - $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); - return; - } - /** @var Player $sender */ - try { - $error = false; + public function onRun(CommandSender $sender, string $aliasUsed, array $args): void + { + $lang = Loader::getInstance()->getLanguage(); + if ($sender instanceof Player && SessionHelper::hasSession($sender)) { + try { + $lang = SessionHelper::getUserSession($sender)->getLanguage(); + } catch (SessionException $e) { + } + } + if (!$sender instanceof Player) { + $sender->sendMessage(TF::RED . $lang->translateString('error.runingame')); + return; + } + /** @var Player $sender */ + try { if (isset($args["blocks"])) { $filterBlocks = $args["blocks"]; } else $filterBlocks = BlockPalette::CREATE(); - if (!$error) { - $session = SessionHelper::getUserSession($sender); - if (is_null($session)) { - throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); - } - $selection = $session->getLatestSelection(); - if (is_null($selection)) { - throw new SelectionException($lang->translateString('error.noselection')); - } - if (!$selection->isValid()) { - throw new SelectionException($lang->translateString('error.selectioninvalid')); - } - if ($selection->getWorld() !== $sender->getWorld()) { - $session->sendMessage(TF::GOLD . $lang->translateString('warning.differentworld')); - } - Server::getInstance()->getAsyncPool()->submitTask( - new AsyncActionTask( - $session->getUUID(), - $selection, - new CountAction(), - $selection->getShape()->getTouchedChunks($selection->getWorld()), - BlockPalette::CREATE(), - $filterBlocks - ) - ); - } else { - throw new InvalidArgumentException("Could not count the selected blocks"); + $session = SessionHelper::getUserSession($sender); + if (is_null($session)) { + throw new SessionException($lang->translateString('error.nosession', [Loader::getInstance()->getName()])); + } + $selection = $session->getLatestSelection(); + if (is_null($selection)) { + throw new SelectionException($lang->translateString('error.noselection')); + } + if (!$selection->isValid()) { + throw new SelectionException($lang->translateString('error.selectioninvalid')); + } + if ($selection->getWorld() !== $sender->getWorld()) { + $session->sendMessage(TF::GOLD . $lang->translateString('warning.differentworld')); } + Server::getInstance()->getAsyncPool()->submitTask( + new AsyncActionTask( + $session->getUUID(), + $selection, + new CountAction(), + $selection->getShape()->getTouchedChunks($selection->getWorld()), + BlockPalette::CREATE(), + $filterBlocks + ) + ); } catch (Exception $error) { $sender->sendMessage(Loader::PREFIX . TF::RED . $lang->translateString('error.command-error')); $sender->sendMessage(Loader::PREFIX . TF::RED . $error->getMessage()); diff --git a/src/xenialdan/MagicWE2/helper/BlockPalette.php b/src/xenialdan/MagicWE2/helper/BlockPalette.php index ae65d428..cd6ebe79 100644 --- a/src/xenialdan/MagicWE2/helper/BlockPalette.php +++ b/src/xenialdan/MagicWE2/helper/BlockPalette.php @@ -32,11 +32,11 @@ public function __construct(string $name = "") /** * @param string $blocksQuery - * @return static + * @return BlockPalette * @throws InvalidArgumentException * @throws BlockQueryAlreadyParsedException */ - public static function fromString(string $blocksQuery): self + public static function fromString(string $blocksQuery): BlockPalette { $palette = self::CREATE(); @@ -56,7 +56,7 @@ public static function fromString(string $blocksQuery): self return $palette; } - public function addBlockQuery(BlockQuery $query) + public function addBlockQuery(BlockQuery $query): void { $this->randomBlockQueries->add($query, $query->weight); } diff --git a/src/xenialdan/MagicWE2/helper/BlockStatesParser.php b/src/xenialdan/MagicWE2/helper/BlockStatesParser.php index 5038defb..088b2a26 100644 --- a/src/xenialdan/MagicWE2/helper/BlockStatesParser.php +++ b/src/xenialdan/MagicWE2/helper/BlockStatesParser.php @@ -276,7 +276,7 @@ public static function fromString(BlockQuery $query): Block $blocks[] = $block; } } - if (empty($blocks) && !$block instanceof Block) throw new InvalidArgumentException("No block $namespacedSelectedBlockName matching $query->query could be found");//no block found //TODO r12 map only has blocks up to id 255. On 4.0.0, return Item::fromString()? + if (count($blocks) < 1) throw new InvalidArgumentException("No block $namespacedSelectedBlockName matching $query->query could be found");//no block found //TODO r12 map only has blocks up to id 255. On 4.0.0, return Item::fromString()? if (count($blocks) === 1) { $block = $blocks[0]; $query->blockFullId = $block->getFullId();