fixed null issue

This commit is contained in:
Steffen Schröder 2014-10-24 19:54:10 +02:00
parent 79a5a451c2
commit 50547437f7

View File

@ -49,7 +49,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
*/ */
/** @var ManiaControl $maniaControl * */ /** @var ManiaControl $maniaControl * */
private $maniaControl = null; private $maniaControl = null;
private $recordCount = 0; private $recordCount = 0;
/** /**
* @see \ManiaControl\Plugins\Plugin::prepare() * @see \ManiaControl\Plugins\Plugin::prepare()
@ -121,6 +121,23 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
$this->resetRanks(); $this->resetRanks();
} }
/**
* Create necessary database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RANK . "` (
`PlayerIndex` int(11) NOT NULL,
`Rank` int(11) NOT NULL,
`Avg` float NOT NULL,
KEY `PlayerIndex` (`PlayerIndex`),
UNIQUE `Rank` (`Rank`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ServerRanking';";
$mysqli->query($query);
if ($mysqli->error) {
throw new \Exception($mysqli->error);
}
}
/** /**
* Get the RankingsTypeArray * Get the RankingsTypeArray
@ -141,24 +158,6 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
} }
} }
/**
* Create necessary database tables
*/
private function initTables() {
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_RANK . "` (
`PlayerIndex` int(11) NOT NULL,
`Rank` int(11) NOT NULL,
`Avg` float NOT NULL,
KEY `PlayerIndex` (`PlayerIndex`),
UNIQUE `Rank` (`Rank`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ServerRanking';";
$mysqli->query($query);
if ($mysqli->error) {
throw new \Exception($mysqli->error);
}
}
/** /**
* Resets and rebuilds the Ranking * Resets and rebuilds the Ranking
*/ */
@ -368,12 +367,18 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
return false; return false;
} }
$nextPlayer = null;
if ($rankObject->rank > 1) { if ($rankObject->rank > 1) {
$nextRank = $this->getNextRank($player); $nextRank = $this->getNextRank($player);
$nextPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($nextRank->playerIndex); if ($nextRank) {
$message = '$0f3The next better ranked player is $fff' . $nextPlayer->nickname; $nextPlayer = $this->maniaControl->getPlayerManager()->getPlayerByIndex($nextRank->playerIndex);
}
}
if ($nextPlayer) {
$message = '$0f3The next better ranked player is $fff' . $nextPlayer->getEscapedNickname() . '!';
} else { } else {
$message = '$0f3No better ranked player :-)'; $message = '$0f3No better ranked player.';
} }
$this->maniaControl->getChat()->sendChat($message, $player); $this->maniaControl->getChat()->sendChat($message, $player);
@ -530,7 +535,7 @@ class ServerRankingPlugin implements Plugin, CallbackListener, CommandListener {
} }
$playerObject = $this->maniaControl->getPlayerManager()->getPlayerByIndex($rankedPlayer->PlayerIndex); $playerObject = $this->maniaControl->getPlayerManager()->getPlayerByIndex($rankedPlayer->PlayerIndex);
$array = array($rankedPlayer->Rank => $posX + 5, $playerObject->nickname => $posX + 18, (string)round($rankedPlayer->Avg, 2) => $posX + 70); $array = array($rankedPlayer->Rank => $posX + 5, $playerObject->nickname => $posX + 18, (string) round($rankedPlayer->Avg, 2) => $posX + 70);
$this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array); $this->maniaControl->getManialinkManager()->labelLine($playerFrame, $array);
$posY -= 4; $posY -= 4;