fix linter + add check if null

This commit is contained in:
Beu
2025-07-25 11:12:02 +02:00
parent 345ce361e2
commit d6f7a6f842

View File

@@ -736,58 +736,63 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin); $this->maniaControl->getPlayerManager()->getPlayerActions()->revokeAuthLevel($adminLogin, $targetLogin);
break; break;
case self::ACTION_FORCE_SPEC_VOTE: case self::ACTION_FORCE_SPEC_VOTE:
/** @var $votesPlugin CustomVotesPlugin */ /** @var ?CustomVotesPlugin $votesPlugin */
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); $votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
if ($votesPlugin !== null) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); $startMessage = $admin->getEscapedNickname() . '$s started a vote to force $<' . $target->nickname . '$> into spectator!';
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$startMessage = $admin->getEscapedNickname() . '$s started a vote to force $<' . $target->nickname . '$> into spectator!'; $votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage);
$votesPlugin->defineVote('forcespec', 'Force ' . $target->getEscapedNickname() . ' Spec', true, $startMessage); $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
$message = $this->maniaControl->getChat()->formatMessage(
'Vote successful -> %s forced to Spectator!',
$target
);
$this->maniaControl->getChat()->sendSuccess($message);
$votesPlugin->undefineVote('forcespec');
try {
$this->maniaControl->getClient()->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
} catch (PlayerStateException $e) {
} catch (UnknownPlayerException $e) {
}
});
}
$votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) {
$message = $this->maniaControl->getChat()->formatMessage(
'Vote successful -> %s forced to Spectator!',
$target
);
$this->maniaControl->getChat()->sendSuccess($message);
$votesPlugin->undefineVote('forcespec');
try {
$this->maniaControl->getClient()->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->getClient()->spectatorReleasePlayerSlot($target->login);
} catch (PlayerStateException $e) {
} catch (UnknownPlayerException $e) {
}
});
break; break;
case self::ACTION_KICK_PLAYER_VOTE: case self::ACTION_KICK_PLAYER_VOTE:
/** @var $votesPlugin CustomVotesPlugin */ /** @var ?CustomVotesPlugin $votesPlugin */
$votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); $votesPlugin = $this->maniaControl->getPluginManager()->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN);
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); if ($votesPlugin !== null) {
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
$startMessage = $admin->getEscapedNickname() . '$s started a vote to kick $<' . $target->nickname . '$>!'; $startMessage = $admin->getEscapedNickname() . '$s started a vote to kick $<' . $target->nickname . '$>!';
$votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage); $votesPlugin->defineVote('kick', 'Kick ' . $target->getEscapedNickname(), true, $startMessage);
$votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) { $votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) {
$message = $this->maniaControl->getChat()->formatMessage( $message = $this->maniaControl->getChat()->formatMessage(
'Vote successful -> %s got kicked!', 'Vote successful -> %s got kicked!',
$target $target
); );
$this->maniaControl->getChat()->sendSuccess($message); $this->maniaControl->getChat()->sendSuccess($message);
$votesPlugin->undefineVote('kick'); $votesPlugin->undefineVote('kick');
$message = '$39FYou got kicked due to a Public Vote!'; $message = '$39FYou got kicked due to a Public Vote!';
try { try {
$this->maniaControl->getClient()->kick($target->login, $message); $this->maniaControl->getClient()->kick($target->login, $message);
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
} }
}); });
}
break; break;
} }
} else if (count($actionArray) == 2) { } else if (count($actionArray) == 2) {