From b63c11c19db01da5053a300c652c78ce5cf61a9d Mon Sep 17 00:00:00 2001 From: xenial Date: Sun, 13 Dec 2020 00:48:39 +0100 Subject: [PATCH] Patch all phpstan errors except casting w/ args --- src/xenialdan/MagicWE2/API.php | 6 ++-- src/xenialdan/MagicWE2/EventListener.php | 3 +- src/xenialdan/MagicWE2/Loader.php | 36 ++++++++++--------- .../MagicWE2/commands/ReportCommand.php | 2 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/xenialdan/MagicWE2/API.php b/src/xenialdan/MagicWE2/API.php index b60e8e91..0c325e18 100644 --- a/src/xenialdan/MagicWE2/API.php +++ b/src/xenialdan/MagicWE2/API.php @@ -457,12 +457,12 @@ public static function evalAsMath(string $str) $operators = ['*', '/']; while (!$error && !empty($operators)) { $operator = array_pop($operators); - while ($operator && strpos($str, $operator) !== false) { + while ($operator !== null && strpos($str, $operator) !== false) { $regex = '/([\d\.]+)\\' . $operator . '(\-?[\d\.]+)/'; preg_match($regex, $str, $matches); if (isset($matches[1], $matches[2])) { - if ($operator === '+') $result = (float)$matches[1] + (float)$matches[2]; - if ($operator === '-') $result = (float)$matches[1] - (float)$matches[2]; + //if ($operator === '+') $result = (float)$matches[1] + (float)$matches[2]; + //if ($operator === '-') $result = (float)$matches[1] - (float)$matches[2]; if ($operator === '*') $result = (float)$matches[1] * (float)$matches[2]; if ($operator === '/') { if ((float)$matches[2]) { diff --git a/src/xenialdan/MagicWE2/EventListener.php b/src/xenialdan/MagicWE2/EventListener.php index 81be5375..81c8220e 100644 --- a/src/xenialdan/MagicWE2/EventListener.php +++ b/src/xenialdan/MagicWE2/EventListener.php @@ -66,8 +66,9 @@ public function onSessionLoad(MWESessionLoadEvent $event): void Loader::getInstance()->wailaBossBar->addPlayer($event->getPlayer()); if (Loader::hasScoreboard()) { try { + if (($session = $event->getSession()) instanceof UserSession && $session->isSidebarEnabled()) /** @var UserSession $session */ - if (($session = $event->getSession()) instanceof UserSession && $session->isSidebarEnabled()) $session->sidebar->handleScoreboard($session); + $session->sidebar->handleScoreboard($session); } catch (InvalidArgumentException $e) { Loader::getInstance()->getLogger()->logException($e); } diff --git a/src/xenialdan/MagicWE2/Loader.php b/src/xenialdan/MagicWE2/Loader.php index 424ad12e..ebb9f4a5 100644 --- a/src/xenialdan/MagicWE2/Loader.php +++ b/src/xenialdan/MagicWE2/Loader.php @@ -322,26 +322,28 @@ public function onEnable(): void #BlockStatesParser::getInstance()::runTests(); $world = Loader::getInstance()->getServer()->getWorldManager()->getDefaultWorld(); $spawn = $world->getSafeSpawn()->asVector3(); - foreach (glob($this->getDataFolder() . 'structures' . DIRECTORY_SEPARATOR . "*.mcstructure") as $file) { - $this->getLogger()->debug(TextFormat::GOLD . "Loading " . basename($file)); - try { - /** @var StructureStore $instance */ - $instance = StructureStore::getInstance(); - $structure = $instance->loadStructure(basename($file)); - //this will dump wrong blocks for now - foreach ($structure->blocks() as $block) { - #$this->getLogger()->debug($block->getPos()->asVector3() . ' ' . BlockStatesParser::printStates(BlockStatesParser::getStateByBlock($block), false)); - $world->setBlock(($at = $spawn->addVector($block->getPos()->asVector3())), $block); - if (($tile = $structure->translateBlockEntity(Position::fromObject($block->getPos()->asVector3(), $world), $at)) instanceof Tile) { - $tileAt = $world->getTileAt($block->getPos()->getFloorX(), $block->getPos()->getFloorY(), $block->getPos()->getFloorZ()); - if ($tileAt !== null) $world->removeTile($tileAt); - $world->addTile($tile); + $structureFiles = glob($this->getDataFolder() . 'structures' . DIRECTORY_SEPARATOR . "*.mcstructure"); + if($structureFiles !== false) + foreach ($structureFiles as $file) { + $this->getLogger()->debug(TextFormat::GOLD . "Loading " . basename($file)); + try { + /** @var StructureStore $instance */ + $instance = StructureStore::getInstance(); + $structure = $instance->loadStructure(basename($file)); + //this will dump wrong blocks for now + foreach ($structure->blocks() as $block) { + #$this->getLogger()->debug($block->getPos()->asVector3() . ' ' . BlockStatesParser::printStates(BlockStatesParser::getStateByBlock($block), false)); + $world->setBlock(($at = $spawn->addVector($block->getPos()->asVector3())), $block); + if (($tile = $structure->translateBlockEntity(Position::fromObject($block->getPos()->asVector3(), $world), $at)) instanceof Tile) { + $tileAt = $world->getTileAt($block->getPos()->getFloorX(), $block->getPos()->getFloorY(), $block->getPos()->getFloorZ()); + if ($tileAt !== null) $world->removeTile($tileAt); + $world->addTile($tile); + } } + } catch (Exception $e) { + $this->getLogger()->debug($e->getMessage()); } - } catch (Exception $e) { - $this->getLogger()->debug($e->getMessage()); } - } //register WAILA bar $this->wailaBossBar = new DiverseBossBar(); diff --git a/src/xenialdan/MagicWE2/commands/ReportCommand.php b/src/xenialdan/MagicWE2/commands/ReportCommand.php index 2ba07047..146e92d7 100644 --- a/src/xenialdan/MagicWE2/commands/ReportCommand.php +++ b/src/xenialdan/MagicWE2/commands/ReportCommand.php @@ -55,7 +55,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo TF::EOL . "" . TF::EOL . "---" . TF::EOL . TF::clean(implode(TF::EOL, Loader::getInfo()))); - $url .= "&title=" . urlencode(TF::clean("[" . Loader::getInstance()->getDescription()->getVersion() . "] " . ($args["title"] ?? ""))); + $url .= "&title=" . urlencode(TF::clean("[" . Loader::getInstance()->getDescription()->getVersion() . "] " . ((string)($args["title"] ?? "")))); if (!$sender instanceof ConsoleCommandSender) $sender->sendMessage(Loader::PREFIX . $url); Loader::getInstance()->getLogger()->alert($url);