Skip to content

Commit

Permalink
🆗 phpstan, as you wish
Browse files Browse the repository at this point in the history
  • Loading branch information
inxomnyaa committed Dec 25, 2020
1 parent 51be977 commit 7292315
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 47 deletions.
81 changes: 38 additions & 43 deletions src/xenialdan/MagicWE2/commands/selection/info/CountCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/xenialdan/MagicWE2/helper/BlockPalette.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xenialdan/MagicWE2/helper/BlockStatesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7292315

Please sign in to comment.