From dd98e4aaed3731f0d23447d52825b9100826523f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 14 Nov 2023 12:47:33 +0000 Subject: [PATCH 1/4] block: clean up unnecessary getter usages with the assistance of a custom phpstan rule this inconsistent mess has been bothering me for a long time --- src/block/Bamboo.php | 2 +- src/block/Barrel.php | 8 ++++---- src/block/BaseBigDripleaf.php | 10 +++++----- src/block/Bed.php | 2 +- src/block/ChiseledBookshelf.php | 2 +- src/block/ChorusFlower.php | 4 ++-- src/block/ChorusPlant.php | 2 +- src/block/Farmland.php | 2 +- src/block/Fire.php | 2 +- src/block/FloorCoralFan.php | 2 +- src/block/Jukebox.php | 6 +++--- src/block/NetherVines.php | 4 ++-- src/block/PinkPetals.php | 8 ++++---- src/block/RedMushroom.php | 2 +- src/block/SmallDripleaf.php | 4 ++-- src/block/Stair.php | 4 ++-- src/block/inventory/AnimatedBlockInventoryTrait.php | 8 ++++---- src/block/tile/Chest.php | 2 +- 18 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index 5df71f696..9f605bca6 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -173,7 +173,7 @@ class Bamboo extends Transparent{ $newHeight = $height + $growAmount; $stemBlock = (clone $this)->setReady(false)->setLeafSize(self::NO_LEAVES); - if($newHeight >= 4 && !$stemBlock->isThick()){ //don't change it to false if height is less, because it might have been chopped + if($newHeight >= 4 && !$stemBlock->thick){ //don't change it to false if height is less, because it might have been chopped $stemBlock = $stemBlock->setThick(true); } $smallLeavesBlock = (clone $stemBlock)->setLeafSize(self::SMALL_LEAVES); diff --git a/src/block/Barrel.php b/src/block/Barrel.php index 1dce2376b..0f0499ab9 100644 --- a/src/block/Barrel.php +++ b/src/block/Barrel.php @@ -55,12 +55,12 @@ class Barrel extends Opaque{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ - if(abs($player->getPosition()->getX() - $this->position->getX()) < 2 && abs($player->getPosition()->getZ() - $this->position->getZ()) < 2){ - $y = $player->getEyePos()->getY(); + if(abs($player->getPosition()->x - $this->position->x) < 2 && abs($player->getPosition()->z - $this->position->z) < 2){ + $y = $player->getEyePos()->y; - if($y - $this->position->getY() > 2){ + if($y - $this->position->y > 2){ $this->facing = Facing::UP; - }elseif($this->position->getY() - $y > 0){ + }elseif($this->position->y - $y > 0){ $this->facing = Facing::DOWN; }else{ $this->facing = Facing::opposite($player->getHorizontalFacing()); diff --git a/src/block/BaseBigDripleaf.php b/src/block/BaseBigDripleaf.php index b2547447c..f0ff59cf0 100644 --- a/src/block/BaseBigDripleaf.php +++ b/src/block/BaseBigDripleaf.php @@ -65,8 +65,8 @@ abstract class BaseBigDripleaf extends Transparent{ $this->facing = Facing::opposite($player->getHorizontalFacing()); } if($block instanceof BaseBigDripleaf){ - $this->facing = $block->getFacing(); - $tx->addBlock($block->getPosition(), VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($this->facing)); + $this->facing = $block->facing; + $tx->addBlock($block->position, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($this->facing)); } return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } @@ -98,7 +98,7 @@ abstract class BaseBigDripleaf extends Transparent{ if($head === null){ return false; } - $pos = $head->getPosition(); + $pos = $head->position; $up = $pos->up(); $world = $pos->getWorld(); if( @@ -110,8 +110,8 @@ abstract class BaseBigDripleaf extends Transparent{ $tx = new BlockTransaction($world); - $tx->addBlock($pos, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($head->getFacing())); - $tx->addBlock($up, VanillaBlocks::BIG_DRIPLEAF_HEAD()->setFacing($head->getFacing())); + $tx->addBlock($pos, VanillaBlocks::BIG_DRIPLEAF_STEM()->setFacing($head->facing)); + $tx->addBlock($up, VanillaBlocks::BIG_DRIPLEAF_HEAD()->setFacing($head->facing)); $ev = new StructureGrowEvent($head, $tx, $player); $ev->call(); diff --git a/src/block/Bed.php b/src/block/Bed.php index d4dca17d6..8efbdfe01 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -145,7 +145,7 @@ class Bed extends Transparent{ $b = ($this->isHeadPart() ? $this : $other); - if($b->isOccupied()){ + if($b->occupied){ $player->sendMessage(KnownTranslationFactory::tile_bed_occupied()->prefix(TextFormat::GRAY)); return true; diff --git a/src/block/ChiseledBookshelf.php b/src/block/ChiseledBookshelf.php index 021ed58e9..89340a8f3 100644 --- a/src/block/ChiseledBookshelf.php +++ b/src/block/ChiseledBookshelf.php @@ -97,7 +97,7 @@ class ChiseledBookshelf extends Opaque{ return false; } - $x = Facing::axis($face) === Axis::X ? $clickVector->getZ() : $clickVector->getX(); + $x = Facing::axis($face) === Axis::X ? $clickVector->z : $clickVector->x; $slot = ChiseledBookshelfSlot::fromBlockFaceCoordinates( Facing::isPositive(Facing::rotateY($face, true)) ? 1 - $x : $x, $clickVector->y diff --git a/src/block/ChorusFlower.php b/src/block/ChorusFlower.php index 2dcf4bb70..cc3c606d9 100644 --- a/src/block/ChorusFlower.php +++ b/src/block/ChorusFlower.php @@ -54,7 +54,7 @@ final class ChorusFlower extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - $position = $block->getPosition(); + $position = $block->position; $world = $position->getWorld(); $down = $world->getBlock($position->down()); @@ -152,7 +152,7 @@ final class ChorusFlower extends Flowable{ if($tx === null){ $tx = new BlockTransaction($this->position->getWorld()); } - $tx->addBlock($this->position->getSide($facing), (clone $this)->setAge(min(self::MAX_AGE, $this->getAge() + $ageChange))); + $tx->addBlock($this->position->getSide($facing), (clone $this)->setAge(min(self::MAX_AGE, $this->age + $ageChange))); return $tx; } diff --git a/src/block/ChorusPlant.php b/src/block/ChorusPlant.php index e3cc8de9d..9013f6825 100644 --- a/src/block/ChorusPlant.php +++ b/src/block/ChorusPlant.php @@ -51,7 +51,7 @@ final class ChorusPlant extends Flowable{ } private function canBeSupportedAt(Block $block) : bool{ - $position = $block->getPosition(); + $position = $block->position; $world = $position->getWorld(); $down = $world->getBlock($position->down()); diff --git a/src/block/Farmland.php b/src/block/Farmland.php index c2694dd83..a17a220f0 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -152,7 +152,7 @@ class Farmland extends Transparent{ $ev = new EntityTrampleFarmlandEvent($entity, $this); $ev->call(); if(!$ev->isCancelled()){ - $this->getPosition()->getWorld()->setBlock($this->getPosition(), VanillaBlocks::DIRT()); + $this->position->getWorld()->setBlock($this->position, VanillaBlocks::DIRT()); } } return null; diff --git a/src/block/Fire.php b/src/block/Fire.php index 5487c34ed..35a7a696c 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -140,7 +140,7 @@ class Fire extends BaseFire{ $block->onIncinerate(); $world = $this->position->getWorld(); - if($world->getBlock($block->getPosition())->isSameState($block)){ + if($world->getBlock($block->position)->isSameState($block)){ $spreadedFire = false; if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain $fire = clone $this; diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index 81ea88186..5b74d08af 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -58,7 +58,7 @@ final class FloorCoralFan extends BaseCoral{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ $playerBlockPos = $player->getPosition()->floor(); - $directionVector = $blockReplace->getPosition()->subtractVector($playerBlockPos)->normalize(); + $directionVector = $blockReplace->position->subtractVector($playerBlockPos)->normalize(); $angle = rad2deg(atan2($directionVector->getZ(), $directionVector->getX())); if($angle <= 45 || 315 <= $angle || (135 <= $angle && $angle <= 225)){ diff --git a/src/block/Jukebox.php b/src/block/Jukebox.php index 20c3cab61..a61dd06db 100644 --- a/src/block/Jukebox.php +++ b/src/block/Jukebox.php @@ -61,7 +61,7 @@ class Jukebox extends Opaque{ public function ejectRecord() : void{ if($this->record !== null){ - $this->getPosition()->getWorld()->dropItem($this->getPosition()->add(0.5, 1, 0.5), $this->record); + $this->position->getWorld()->dropItem($this->position->add(0.5, 1, 0.5), $this->record); $this->record = null; $this->stopSound(); } @@ -76,12 +76,12 @@ class Jukebox extends Opaque{ public function startSound() : void{ if($this->record !== null){ - $this->getPosition()->getWorld()->addSound($this->getPosition(), new RecordSound($this->record->getRecordType())); + $this->position->getWorld()->addSound($this->position, new RecordSound($this->record->getRecordType())); } } public function stopSound() : void{ - $this->getPosition()->getWorld()->addSound($this->getPosition(), new RecordStopSound()); + $this->position->getWorld()->addSound($this->position, new RecordStopSound()); } public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{ diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index eb459a0f1..e8729c00f 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -108,8 +108,8 @@ class NetherVines extends Flowable{ private function grow(?Player $player, int $growthAmount = 1) : bool{ $top = $this->seekToTip(); - $age = $top->getAge(); - $pos = $top->getPosition(); + $age = $top->age; + $pos = $top->position; $world = $pos->getWorld(); $changedBlocks = 0; diff --git a/src/block/PinkPetals.php b/src/block/PinkPetals.php index 872798df0..17bc4c50a 100644 --- a/src/block/PinkPetals.php +++ b/src/block/PinkPetals.php @@ -70,13 +70,13 @@ class PinkPetals extends Flowable{ } public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ - return ($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); + return ($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($blockReplace instanceof PinkPetals && $blockReplace->getCount() < self::MAX_COUNT){ - $this->count = $blockReplace->getCount() + 1; - $this->facing = $blockReplace->getFacing(); + if($blockReplace instanceof PinkPetals && $blockReplace->count < self::MAX_COUNT){ + $this->count = $blockReplace->count + 1; + $this->facing = $blockReplace->facing; }elseif($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index 553957fe6..81ab940f5 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -43,7 +43,7 @@ class RedMushroom extends Flowable{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $down = $this->getSide(Facing::DOWN); - $position = $this->getPosition(); + $position = $this->position; $lightLevel = $position->getWorld()->getFullLightAt($position->x, $position->y, $position->z); $downId = $down->getTypeId(); //TODO: nylium support diff --git a/src/block/SmallDripleaf.php b/src/block/SmallDripleaf.php index ad23608bf..d192e43db 100644 --- a/src/block/SmallDripleaf.php +++ b/src/block/SmallDripleaf.php @@ -83,7 +83,7 @@ class SmallDripleaf extends Transparent{ $this->facing = Facing::opposite($player->getHorizontalFacing()); } - $tx->addBlock($block->getPosition(), VanillaBlocks::SMALL_DRIPLEAF() + $tx->addBlock($block->position, VanillaBlocks::SMALL_DRIPLEAF() ->setFacing($this->facing) ->setTop(true) ); @@ -117,7 +117,7 @@ class SmallDripleaf extends Transparent{ $height = mt_rand(2, 5); $grown = 0; for($i = 0; $i < $height; $i++){ - $pos = $bottomBlock->getSide(Facing::UP, $i)->getPosition(); + $pos = $bottomBlock->getSide(Facing::UP, $i)->position; if(!$this->canGrowTo($pos)){ break; } diff --git a/src/block/Stair.php b/src/block/Stair.php index 1acaac962..d66a9ce5c 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -106,8 +106,8 @@ class Stair extends Transparent{ public function getSupportType(int $facing) : SupportType{ if( - $facing === Facing::UP && $this->isUpsideDown() || - $facing === Facing::DOWN && !$this->isUpsideDown() || + $facing === Facing::UP && $this->upsideDown || + $facing === Facing::DOWN && !$this->upsideDown || ($facing === $this->facing && $this->shape !== StairShape::OUTER_LEFT && $this->shape !== StairShape::OUTER_RIGHT) || ($facing === Facing::rotate($this->facing, Axis::Y, false) && $this->shape === StairShape::INNER_LEFT) || ($facing === Facing::rotate($this->facing, Axis::Y, true) && $this->shape === StairShape::INNER_RIGHT) diff --git a/src/block/inventory/AnimatedBlockInventoryTrait.php b/src/block/inventory/AnimatedBlockInventoryTrait.php index a9965190c..8720c985b 100644 --- a/src/block/inventory/AnimatedBlockInventoryTrait.php +++ b/src/block/inventory/AnimatedBlockInventoryTrait.php @@ -47,20 +47,20 @@ trait AnimatedBlockInventoryTrait{ public function onOpen(Player $who) : void{ parent::onOpen($who); - if($this->getHolder()->isValid() && $this->getViewerCount() === 1){ + if($this->holder->isValid() && $this->getViewerCount() === 1){ //TODO: this crap really shouldn't be managed by the inventory $this->animateBlock(true); - $this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); + $this->holder->getWorld()->addSound($this->holder->add(0.5, 0.5, 0.5), $this->getOpenSound()); } } abstract protected function animateBlock(bool $isOpen) : void; public function onClose(Player $who) : void{ - if($this->getHolder()->isValid() && $this->getViewerCount() === 1){ + if($this->holder->isValid() && $this->getViewerCount() === 1){ //TODO: this crap really shouldn't be managed by the inventory $this->animateBlock(false); - $this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); + $this->holder->getWorld()->addSound($this->holder->add(0.5, 0.5, 0.5), $this->getCloseSound()); } parent::onClose($who); } diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 46d97191b..4f97eed23 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -139,7 +139,7 @@ class Chest extends Spawnable implements Container, Nameable{ if($pair->doubleInventory !== null){ $this->doubleInventory = $pair->doubleInventory; }else{ - if(($pair->getPosition()->x + ($pair->getPosition()->z << 15)) > ($this->position->x + ($this->position->z << 15))){ //Order them correctly + if(($pair->position->x + ($pair->position->z << 15)) > ($this->position->x + ($this->position->z << 15))){ //Order them correctly $this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($pair->inventory, $this->inventory); }else{ $this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($this->inventory, $pair->inventory); From e5c96faa4b51b91e32fb9ff764ec85611d20e7c0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 14 Nov 2023 12:59:05 +0000 Subject: [PATCH 2/4] Server: clean up inconsistent getter vs property access usages --- src/Server.php | 78 +++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Server.php b/src/Server.php index f4d4a0958..dcadf4ce7 100644 --- a/src/Server.php +++ b/src/Server.php @@ -523,7 +523,7 @@ class Server{ return $this->playerDataProvider->loadData($name); }catch(PlayerDataLoadException $e){ $this->logger->debug("Failed to load player data for $name: " . $e->getMessage()); - $this->logger->error($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_data_playerCorrupted($name))); + $this->logger->error($this->language->translate(KnownTranslationFactory::pocketmine_data_playerCorrupted($name))); return null; } }); @@ -542,7 +542,7 @@ class Server{ try{ $this->playerDataProvider->saveData($name, $ev->getSaveData()); }catch(PlayerDataSaveException $e){ - $this->logger->critical($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_data_saveError($name, $e->getMessage()))); + $this->logger->critical($this->language->translate(KnownTranslationFactory::pocketmine_data_saveError($name, $e->getMessage()))); $this->logger->logException($e); } }); @@ -854,7 +854,7 @@ class Server{ } } - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::language_selected($this->getLanguage()->getName(), $this->getLanguage()->getLang()))); + $this->logger->info($this->language->translate(KnownTranslationFactory::language_selected($this->language->getName(), $this->language->getLang()))); if(VersionInfo::IS_DEVELOPMENT_BUILD){ if(!$this->configGroup->getPropertyBool(Yml::SETTINGS_ENABLE_DEV_BUILDS, false)){ @@ -877,7 +877,7 @@ class Server{ $this->memoryManager = new MemoryManager($this); - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_start(TextFormat::AQUA . $this->getVersion() . TextFormat::RESET))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_start(TextFormat::AQUA . $this->getVersion() . TextFormat::RESET))); if(($poolSize = $this->configGroup->getPropertyString(Yml::SETTINGS_ASYNC_WORKERS, "auto")) === "auto"){ $poolSize = 2; @@ -937,11 +937,11 @@ class Server{ $this->onlineMode = $this->configGroup->getConfigBool(ServerProperties::XBOX_AUTH, true); if($this->onlineMode){ - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_auth_enabled())); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_auth_enabled())); }else{ - $this->logger->warning($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_auth_disabled())); - $this->logger->warning($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_authWarning())); - $this->logger->warning($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_authProperty_disabled())); + $this->logger->warning($this->language->translate(KnownTranslationFactory::pocketmine_server_auth_disabled())); + $this->logger->warning($this->language->translate(KnownTranslationFactory::pocketmine_server_authWarning())); + $this->logger->warning($this->language->translate(KnownTranslationFactory::pocketmine_server_authProperty_disabled())); } if($this->configGroup->getConfigBool(ServerProperties::HARDCORE, false) && $this->getDifficulty() < World::DIFFICULTY_HARD){ @@ -952,17 +952,17 @@ class Server{ $this->serverID = Utils::getMachineUniqueId($this->getIp() . $this->getPort()); - $this->getLogger()->debug("Server unique id: " . $this->getServerUniqueId()); - $this->getLogger()->debug("Machine unique id: " . Utils::getMachineUniqueId()); + $this->logger->debug("Server unique id: " . $this->getServerUniqueId()); + $this->logger->debug("Machine unique id: " . Utils::getMachineUniqueId()); $this->network = new Network($this->logger); $this->network->setName($this->getMotd()); - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_info( + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_info( $this->getName(), (VersionInfo::IS_DEVELOPMENT_BUILD ? TextFormat::YELLOW : "") . $this->getPocketMineVersion() . TextFormat::RESET ))); - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_license($this->getName()))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_license($this->getName()))); TimingsHandler::setEnabled($this->configGroup->getPropertyBool(Yml::SETTINGS_ENABLE_PROFILING, false)); $this->profilingTickRate = $this->configGroup->getPropertyInt(Yml::SETTINGS_PROFILE_REPORT_TRIGGER, self::TARGET_TICKS_PER_SECOND); @@ -973,7 +973,7 @@ class Server{ $this->craftingManager = CraftingManagerFromDataHelper::make(Path::join(\pocketmine\BEDROCK_DATA_PATH, "recipes")); - $this->resourceManager = new ResourcePackManager(Path::join($this->getDataPath(), "resource_packs"), $this->logger); + $this->resourceManager = new ResourcePackManager(Path::join($this->dataPath, "resource_packs"), $this->logger); $pluginGraylist = null; $graylistFile = Path::join($this->dataPath, "plugin_list.yml"); @@ -987,7 +987,7 @@ class Server{ $this->forceShutdownExit(); return; } - $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool(Yml::PLUGINS_LEGACY_DATA_DIR, true) ? null : Path::join($this->getDataPath(), "plugin_data"), $pluginGraylist); + $this->pluginManager = new PluginManager($this, $this->configGroup->getPropertyBool(Yml::PLUGINS_LEGACY_DATA_DIR, true) ? null : Path::join($this->dataPath, "plugin_data"), $pluginGraylist); $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); $this->pluginManager->registerInterface(new ScriptPluginLoader()); @@ -1049,9 +1049,9 @@ class Server{ $this->configGroup->save(); - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_defaultGameMode($this->getGamemode()->getTranslatableName()))); - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_donate(TextFormat::AQUA . "https://patreon.com/pocketminemp" . TextFormat::RESET))); - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_startFinished(strval(round(microtime(true) - $this->startTime, 3))))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_defaultGameMode($this->getGamemode()->getTranslatableName()))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_donate(TextFormat::AQUA . "https://patreon.com/pocketminemp" . TextFormat::RESET))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_startFinished(strval(round(microtime(true) - $this->startTime, 3))))); $forwarder = new BroadcastLoggerForwarder($this, $this->logger, $this->language); $this->subscribeToBroadcastChannel(self::BROADCAST_CHANNEL_ADMINISTRATIVE, $forwarder); @@ -1139,13 +1139,13 @@ class Server{ if($this->worldManager->getDefaultWorld() === null){ $default = $this->configGroup->getConfigString(ServerProperties::DEFAULT_WORLD_NAME, "world"); if(trim($default) == ""){ - $this->getLogger()->warning("level-name cannot be null, using default"); + $this->logger->warning("level-name cannot be null, using default"); $default = "world"; $this->configGroup->setConfigString(ServerProperties::DEFAULT_WORLD_NAME, "world"); } if(!$this->worldManager->loadWorld($default, true)){ if($this->worldManager->isWorldGenerated($default)){ - $this->getLogger()->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_defaultError())); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_level_defaultError())); return false; } @@ -1154,7 +1154,7 @@ class Server{ $generatorClass = $getGenerator($generatorName, $generatorOptions, $default); if($generatorClass === null){ - $this->getLogger()->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_level_defaultError())); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_level_defaultError())); return false; } $creationOptions = WorldCreationOptions::create() @@ -1200,7 +1200,7 @@ class Server{ return false; } if($rakLibRegistered){ - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_networkStart($prettyIp, (string) $port))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_networkStart($prettyIp, (string) $port))); } if($useQuery){ if(!$rakLibRegistered){ @@ -1208,7 +1208,7 @@ class Server{ //if it's not registered we need to make sure Query still works $this->network->registerInterface(new DedicatedQueryNetworkInterface($ip, $port, $ipV6, new \PrefixedLogger($this->logger, "Dedicated Query Interface"))); } - $this->logger->info($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_query_running($prettyIp, (string) $port))); + $this->logger->info($this->language->translate(KnownTranslationFactory::pocketmine_server_query_running($prettyIp, (string) $port))); } return true; } @@ -1456,7 +1456,7 @@ class Server{ $this->shutdown(); if(isset($this->pluginManager)){ - $this->getLogger()->debug("Disabling all plugins"); + $this->logger->debug("Disabling all plugins"); $this->pluginManager->disablePlugins(); } @@ -1465,34 +1465,34 @@ class Server{ } if(isset($this->worldManager)){ - $this->getLogger()->debug("Unloading all worlds"); + $this->logger->debug("Unloading all worlds"); foreach($this->worldManager->getWorlds() as $world){ $this->worldManager->unloadWorld($world, true); } } - $this->getLogger()->debug("Removing event handlers"); + $this->logger->debug("Removing event handlers"); HandlerListManager::global()->unregisterAll(); if(isset($this->asyncPool)){ - $this->getLogger()->debug("Shutting down async task worker pool"); + $this->logger->debug("Shutting down async task worker pool"); $this->asyncPool->shutdown(); } if(isset($this->configGroup)){ - $this->getLogger()->debug("Saving properties"); + $this->logger->debug("Saving properties"); $this->configGroup->save(); } if($this->console !== null){ - $this->getLogger()->debug("Closing console"); + $this->logger->debug("Closing console"); $this->console->quit(); } if(isset($this->network)){ - $this->getLogger()->debug("Stopping network interfaces"); + $this->logger->debug("Stopping network interfaces"); foreach($this->network->getInterfaces() as $interface){ - $this->getLogger()->debug("Stopping network interface " . get_class($interface)); + $this->logger->debug("Stopping network interface " . get_class($interface)); $this->network->unregisterInterface($interface); } } @@ -1560,7 +1560,7 @@ class Server{ } private function writeCrashDumpFile(CrashDump $dump) : string{ - $crashFolder = Path::join($this->getDataPath(), "crashdumps"); + $crashFolder = Path::join($this->dataPath, "crashdumps"); if(!is_dir($crashFolder)){ mkdir($crashFolder); } @@ -1591,17 +1591,17 @@ class Server{ ini_set("error_reporting", '0'); ini_set("memory_limit", '-1'); //Fix error dump not dumped on memory problems try{ - $this->logger->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_create())); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_crash_create())); $dump = new CrashDump($this, $this->pluginManager ?? null); $crashDumpPath = $this->writeCrashDumpFile($dump); - $this->logger->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_submit($crashDumpPath))); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_crash_submit($crashDumpPath))); if($this->configGroup->getPropertyBool(Yml::AUTO_REPORT_ENABLED, true)){ $report = true; - $stamp = Path::join($this->getDataPath(), "crashdumps", ".last_crash"); + $stamp = Path::join($this->dataPath, "crashdumps", ".last_crash"); $crashInterval = 120; //2 minutes if(($lastReportTime = @filemtime($stamp)) !== false && $lastReportTime + $crashInterval >= time()){ $report = false; @@ -1632,7 +1632,7 @@ class Server{ if(isset($data->crashId) && is_int($data->crashId) && isset($data->crashUrl) && is_string($data->crashUrl)){ $reportId = $data->crashId; $reportUrl = $data->crashUrl; - $this->logger->emergency($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_archive($reportUrl, (string) $reportId))); + $this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_crash_archive($reportUrl, (string) $reportId))); }elseif(isset($data->error) && is_string($data->error)){ $this->logger->emergency("Automatic crash report submission failed: $data->error"); }else{ @@ -1646,7 +1646,7 @@ class Server{ }catch(\Throwable $e){ $this->logger->logException($e); try{ - $this->logger->critical($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_crash_error($e->getMessage()))); + $this->logger->critical($this->language->translate(KnownTranslationFactory::pocketmine_crash_error($e->getMessage()))); }catch(\Throwable $e){} } @@ -1764,7 +1764,7 @@ class Server{ echo "\x1b]0;" . $this->getName() . " " . $this->getPocketMineVersion() . - " | Online $online/" . $this->getMaxPlayers() . + " | Online $online/" . $this->maxPlayers . ($connecting > 0 ? " (+$connecting connecting)" : "") . " | Memory " . $usage . " | U " . round($bandwidthStats->getSend()->getAverageBytes() / 1024, 2) . @@ -1829,10 +1829,10 @@ class Server{ } if(($this->tickCounter % self::TICKS_PER_TPS_OVERLOAD_WARNING) === 0 && $this->getTicksPerSecondAverage() < self::TPS_OVERLOAD_WARNING_THRESHOLD){ - $this->logger->warning($this->getLanguage()->translate(KnownTranslationFactory::pocketmine_server_tickOverload())); + $this->logger->warning($this->language->translate(KnownTranslationFactory::pocketmine_server_tickOverload())); } - $this->getMemoryManager()->check(); + $this->memoryManager->check(); if($this->console !== null){ Timings::$serverCommand->startTiming(); From 13f34a500cd6efdebaed7557c6b3b6d4d07584a6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 14 Nov 2023 12:59:38 +0000 Subject: [PATCH 3/4] PluginBase: clean up inconsistent getter vs property access usages --- src/plugin/PluginBase.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index 1b537a11c..47ed3add3 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -70,7 +70,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{ $this->configFile = Path::join($this->dataFolder, "config.yml"); - $prefix = $this->getDescription()->getPrefix(); + $prefix = $this->description->getPrefix(); $this->logger = new PluginLogger($server->getLogger(), $prefix !== "" ? $prefix : $this->getName()); $this->scheduler = new TaskScheduler($this->getFullName()); @@ -145,14 +145,14 @@ abstract class PluginBase implements Plugin, CommandExecutor{ private function registerYamlCommands() : void{ $pluginCmds = []; - foreach(Utils::stringifyKeys($this->getDescription()->getCommands()) as $key => $data){ + foreach(Utils::stringifyKeys($this->description->getCommands()) as $key => $data){ if(str_contains($key, ":")){ - $this->logger->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_commandError($key, $this->getDescription()->getFullName(), ":"))); + $this->logger->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_commandError($key, $this->description->getFullName(), ":"))); continue; } $newCmd = new PluginCommand($key, $this, $this); - if(($description = $data->getDescription()) !== null){ + if(($description = $data->description) !== null){ $newCmd->setDescription($description); } @@ -163,7 +163,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{ $aliasList = []; foreach($data->getAliases() as $alias){ if(str_contains($alias, ":")){ - $this->logger->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_aliasError($alias, $this->getDescription()->getFullName(), ":"))); + $this->logger->error($this->server->getLanguage()->translate(KnownTranslationFactory::pocketmine_plugin_aliasError($alias, $this->description->getFullName(), ":"))); continue; } $aliasList[] = $alias; @@ -181,7 +181,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{ } if(count($pluginCmds) > 0){ - $this->server->getCommandMap()->registerAll($this->getDescription()->getName(), $pluginCmds); + $this->server->getCommandMap()->registerAll($this->description->getName(), $pluginCmds); } } @@ -190,9 +190,9 @@ abstract class PluginBase implements Plugin, CommandExecutor{ * @phpstan-return (Command&PluginOwned)|null */ public function getCommand(string $name){ - $command = $this->getServer()->getPluginCommand($name); + $command = $this->server->getPluginCommand($name); if($command === null || $command->getOwningPlugin() !== $this){ - $command = $this->getServer()->getPluginCommand(strtolower($this->description->getName()) . ":" . $name); + $command = $this->server->getPluginCommand(strtolower($this->description->getName()) . ":" . $name); } if($command instanceof PluginOwned && $command->getOwningPlugin() === $this){ From 69f197dbecff1923cdcc95376ca6e73fe68ae38a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 14 Nov 2023 13:04:14 +0000 Subject: [PATCH 4/4] PluginBase: fixed erroneous replacement --- src/plugin/PluginBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index 47ed3add3..da2eae824 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -152,7 +152,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{ } $newCmd = new PluginCommand($key, $this, $this); - if(($description = $data->description) !== null){ + if(($description = $data->getDescription()) !== null){ $newCmd->setDescription($description); }