fixed div by zero

This commit is contained in:
Steffen Schröder 2014-05-15 18:10:01 +02:00
parent 8d28ccfc2b
commit 0ca8793a58

View File

@ -607,13 +607,20 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
return; return;
} }
$votePercentage = $this->currentVote->positiveVotes / $this->currentVote->getVoteCount(); $voteCount = $this->currentVote->getVoteCount();
$votePercentage = 0;
if ($voteCount > 0) {
$votePercentage = $this->currentVote->positiveVotes / floatval($voteCount);
}
$timeUntilExpire = $this->currentVote->expireTime - time(); $timeUntilExpire = $this->currentVote->expireTime - time();
$this->showVoteWidget($timeUntilExpire, $votePercentage); $this->showVoteWidget($timeUntilExpire, $votePercentage);
$playerCount = $this->maniaControl->playerManager->getPlayerCount(); $playerCount = $this->maniaControl->playerManager->getPlayerCount();
$playersVoteRatio = (100 / $playerCount * $this->currentVote->getVoteCount()) / 100; $playersVoteRatio = 0;
if ($playerCount > 0 && $voteCount > 0) {
$playersVoteRatio = floatval($voteCount) / floatval($playerCount);
}
//Check if vote is over //Check if vote is over
if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) { if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {