From 9ddc73b6c418ef36220f358f8cbd2ac0d34e0fd3 Mon Sep 17 00:00:00 2001 From: VennV <111500380+VennDev@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:21:42 +0700 Subject: [PATCH 1/5] Fix ! --- src/Ifera/ScoreHud/session/PlayerSession.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Ifera/ScoreHud/session/PlayerSession.php b/src/Ifera/ScoreHud/session/PlayerSession.php index 23c6660..950bfd2 100644 --- a/src/Ifera/ScoreHud/session/PlayerSession.php +++ b/src/Ifera/ScoreHud/session/PlayerSession.php @@ -40,6 +40,7 @@ use Ifera\ScoreHud\utils\HelperUtils; use jackmd\scorefactory\ScoreFactory; use pocketmine\player\Player; +use pocketmine\Server; use function is_null; class PlayerSession{ @@ -75,6 +76,8 @@ public function handle(string $world = null, bool $calledFromTask = false): void $world = $world ?? $player->getWorld()->getFolderName(); + if(!Server::getInstance()->getWorldManager()->getWorldByName($world)->isLoaded()) return; + // remove scoreboard if player is in a world where scoreboard is disabled if(ScoreHudSettings::isInDisabledWorld($world)){ ScoreFactory::removeObjective($player); From 4f5c5c6a2fe1601771840a58665e7aa3f067d416 Mon Sep 17 00:00:00 2001 From: poggit-bot Date: Sun, 4 Aug 2024 16:22:17 +0700 Subject: [PATCH 2/5] Create .poggit.yml Poggit-CI is enabled for this repo by @VennDev Visit the Poggit-CI page for this repo at https://poggit.pmmp.io/ci/VennDev/ScoreHud From 6beeeab3d42cc5ff53213880c0654ab90e3f1e48 Mon Sep 17 00:00:00 2001 From: poggit-bot Date: Sun, 4 Aug 2024 16:24:17 +0700 Subject: [PATCH 3/5] Create .poggit.yml Poggit-CI is enabled for this repo by @VennDev Visit the Poggit-CI page for this repo at https://poggit.pmmp.io/ci/VennDev/ScoreHud From 2f1f60f1a1953ddea877463be99005b6f74e1dca Mon Sep 17 00:00:00 2001 From: VennV <111500380+VennDev@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:24:42 +0700 Subject: [PATCH 4/5] Update plugin.yml --- plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index 8a59f4d..bf7c214 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,4 +1,4 @@ -name: ScoreHud +name: ScoreHud-F main: Ifera\ScoreHud\ScoreHud api: 5.0.0 version: 8.0.0 From eaf0fc19ee8cd4303eccbbd958d5c5056606fb66 Mon Sep 17 00:00:00 2001 From: VennV <111500380+VennDev@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:37:21 +0700 Subject: [PATCH 5/5] Fix! --- .../ScoreHud/factory/listener/FactoryListener.php | 14 +++++++++----- src/Ifera/ScoreHud/session/PlayerSession.php | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Ifera/ScoreHud/factory/listener/FactoryListener.php b/src/Ifera/ScoreHud/factory/listener/FactoryListener.php index 3c8413a..0f14f13 100644 --- a/src/Ifera/ScoreHud/factory/listener/FactoryListener.php +++ b/src/Ifera/ScoreHud/factory/listener/FactoryListener.php @@ -38,10 +38,14 @@ public function onJoin(PlayerJoinEvent $event) { public function onQuit(PlayerQuitEvent $event) { $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function() use($event): void { (new ServerTagUpdateEvent(new ScoreTag("scorehud.online", (string) count($this->plugin->getServer()->getOnlinePlayers()))))->call(); - $worldPlayers = $event->getPlayer()->getWorld()->getPlayers(); - $worldCount = count($worldPlayers); - foreach ($worldPlayers as $player) { - (new PlayerTagUpdateEvent($player, new ScoreTag("scorehud.world_player_count", (string) $worldCount)))->call(); + try { + $worldPlayers = $event->getPlayer()->getWorld()->getPlayers(); + $worldCount = count($worldPlayers); + foreach ($worldPlayers as $player) { + (new PlayerTagUpdateEvent($player, new ScoreTag("scorehud.world_player_count", (string) $worldCount)))->call(); + } + } catch (\Throwable $e) { + ScoreHud::getInstance()->getLogger()->debug("Error on PlayerQuitEvent: " . $e->getMessage()); } }), 20); } @@ -94,7 +98,7 @@ public function onTeleport(EntityTeleportEvent $event) { $worldPlayers = $target->getPlayers(); $prevWorldPlayers = $prevWorld->getPlayers(); - if($target !== $event->getFrom()->getWorld()){ + if($target !== $prevWorld){ $worldCount = count($worldPlayers) + 1; $worldPlayers[$player->getId()] = $player; $prevWorldCount = count($prevWorldPlayers) - 1; diff --git a/src/Ifera/ScoreHud/session/PlayerSession.php b/src/Ifera/ScoreHud/session/PlayerSession.php index 950bfd2..d9c2a27 100644 --- a/src/Ifera/ScoreHud/session/PlayerSession.php +++ b/src/Ifera/ScoreHud/session/PlayerSession.php @@ -76,6 +76,7 @@ public function handle(string $world = null, bool $calledFromTask = false): void $world = $world ?? $player->getWorld()->getFolderName(); + // check if the world is loaded if(!Server::getInstance()->getWorldManager()->getWorldByName($world)->isLoaded()) return; // remove scoreboard if player is in a world where scoreboard is disabled