From 0ca8793a582cd796a3bdbaeab9f5eca1b43fa524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Thu, 15 May 2014 18:10:01 +0200 Subject: [PATCH] fixed div by zero --- application/plugins/MCTeam/CustomVotesPlugin.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/application/plugins/MCTeam/CustomVotesPlugin.php b/application/plugins/MCTeam/CustomVotesPlugin.php index aad39396..bc804d29 100644 --- a/application/plugins/MCTeam/CustomVotesPlugin.php +++ b/application/plugins/MCTeam/CustomVotesPlugin.php @@ -607,13 +607,20 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP 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(); $this->showVoteWidget($timeUntilExpire, $votePercentage); $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 if ($timeUntilExpire <= 0 || (($playersVoteRatio >= $this->currentVote->neededPlayerRatio) && (($votePercentage >= $this->currentVote->neededRatio) || ($votePercentage <= 1 - $this->currentVote->neededRatio)))) {