Skip to content

Commit

Permalink
Patch all phpstan errors except casting w/ args
Browse files Browse the repository at this point in the history
  • Loading branch information
xenial committed Dec 12, 2020
1 parent ae2f8d6 commit b63c11c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/xenialdan/MagicWE2/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
3 changes: 2 additions & 1 deletion src/xenialdan/MagicWE2/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
36 changes: 19 additions & 17 deletions src/xenialdan/MagicWE2/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/xenialdan/MagicWE2/commands/ReportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
TF::EOL . "<!-- DO NOT CHANGE MANUALLY -->" .
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);
Expand Down

0 comments on commit b63c11c

Please sign in to comment.