Skip to content

Commit

Permalink
fix f promote crash (addons scorehud)
Browse files Browse the repository at this point in the history
  • Loading branch information
FahZoh committed Apr 25, 2023
1 parent 7c2f564 commit f64214d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
46 changes: 37 additions & 9 deletions src/DaPigGuy/PiggyFactions/addons/scorehud/ScoreHudListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public function onFactionJoin(FactionJoinEvent $event): void
{
if ($event->isCancelled()) return;
$member = $event->getMember();
ScoreHudManager::getInstance()->updatePlayerTags(ScoreHudManager::getInstance()->getPlayer($member),
$player = ScoreHudManager::getInstance()->getPlayer($member);
if ($player === null) {
return;
}
ScoreHudManager::getInstance()->updatePlayerTags($player,
$event->getFaction()->getName(),
$this->plugin->getLanguageManager()->getMessage($member->getLanguage(), "role.recruit"),
$member->getPower()
Expand All @@ -73,28 +77,52 @@ public function onFactionJoin(FactionJoinEvent $event): void

public function onFactionLeave(FactionLeaveEvent $event): void
{
if ($event->isCancelled()) return;
ScoreHudManager::getInstance()->updatePlayerTags(ScoreHudManager::getInstance()->getPlayer($event->getMember()));
if ($event->isCancelled()) {
return;
}
$player = ScoreHudManager::getInstance()->getPlayer($event->getMember());
if ($player === null) {
return;
}
ScoreHudManager::getInstance()->updatePlayerTags($player);
}

public function onFactionRename(FactionRenameEvent $event): void
{
if ($event->isCancelled()) return;
ScoreHudManager::getInstance()->updatePlayerFactionTag(ScoreHudManager::getInstance()->getPlayer($event->getMember()), $event->getName());
if ($event->isCancelled()) {
return;
}
$player = ScoreHudManager::getInstance()->getPlayer($event->getMember());
if ($player === null) {
return;
}
ScoreHudManager::getInstance()->updatePlayerFactionTag($player, $event->getName());
}

public function onPowerChange(PowerChangeEvent $event): void
{
if ($event->isCancelled()) return;
$member = $event->getMember();
$faction = $member->getFaction();
if ($faction === null) return;
ScoreHudManager::getInstance()->updatePlayerFactionPowerTag(ScoreHudManager::getInstance()->getPlayer($member), $faction->getPower() + ($event->getPower() - $member->getPower()));
if ($faction === null) {
return;
}
$player = ScoreHudManager::getInstance()->getPlayer($member);
if ($player === null) {
return;
}
ScoreHudManager::getInstance()->updatePlayerFactionPowerTag($player, $faction->getPower() + ($event->getPower() - $member->getPower()));
}

public function onFactionRoleChange(FactionRoleChangeEvent $event): void
{
if ($event->isCancelled()) return;
ScoreHudManager::getInstance()->updatePlayerFactionRankTag(ScoreHudManager::getInstance()->getPlayer($event->getMember()), $event->getNewRole());
if ($event->isCancelled()) {
return;
}
$player = ScoreHudManager::getInstance()->getPlayer($event->getMember());
if ($player === null) {
return;
}
ScoreHudManager::getInstance()->updatePlayerFactionRankTag($player, $event->getNewRole());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function getInstance(): ScoreHudManager
return self::$instance;
}

public function getPlayer(FactionsPlayer $member): Player
public function getPlayer(FactionsPlayer $member): ?Player
{
return $this->plugin->getServer()->getPlayerByUUID($member->getUuid());
}
Expand Down

0 comments on commit f64214d

Please sign in to comment.