To check if a player has voted, you just need to use the URL below by replacing:
Your server ID is found at the end of your voting link URL. (Ex: http://playmc.lk/server-playmc.1)
https://www.playmc.lk/api/checkVote/{idServeur}/{ip,Username}In this example, we retrieve the result in the variable $resultat. To read the result (in JSON), we convert it into an array. Then we simply test if the value of "success" is true!
If the player has voted, you can also retrieve the value: prochainVote (timestamp), as in the example below, to display the remaining time before they can vote again.
$resultat = file_get_contents("https://www.playmc.lk/api/checkVote/1/Notch");
$jsonDecoded = json_decode($resultat, true);
if ($jsonDecoded['success'] === true) {
echo "The player has voted";
// Optional: Remaining time before they can vote.
$dateProchainVote = new DateTime();
$dateProchainVote->setTimestamp($jsonDecoded['prochainVote']);
$ecart = $dateProchainVote->diff(new DateTime());
echo '<p>The player can vote in: ';
echo $ecart->h.' hour(s) ';
echo $ecart->i.' minute(s) ';
echo $ecart->s.' second(s) ';
echo '</p>';
}else{
echo "The player has not voted";
}
To get the list of top voters and their votes, you just need to use the URL below by replacing:
Your server ID is found at the end of your voting link URL. (Ex: http://listeserveurs.test/server-leserveur.1)
https://www.playmc.lk/api/topVotes/{idServeur}/{limit}In this example, we retrieve the result in the variable $resultat. To read the result (in JSON), we convert it into an array. Then we just return the whole list (players) and their votes!
$resultat = file_get_contents("https://www.playmc.lk/api/topVotes/1/30");
$jsonDecoded = json_decode($resultat, true);
foreach($jsonDecoded["classement"] as $joueur){
echo '<p>' . $joueur["pseudo"] . " - " . $joueur["votes"] . " votes </p>";
}