To know if a player has voted, simply use the URL below, replacing:
Your server's ID is at the end of your vote link URL. (Ex: https://www.playmc.lk/server-theserver.1)
https://www.playmc.lk/api/checkVote/{serverId}/{ip,Username}In this example, we retrieve the returned result in the $resultat variable. To read the result (in JSON), we convert it into an array. Then you just need to test if the "success" value is true!
If the player has voted, you can 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 successfully";
// Optional: Remaining time to 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 retrieve the list of top voters and their votes, simply use the URL below, replacing:
Your server's ID is at the end of your vote link URL. (Ex: https://www.playmc.lk/server-theserver.1)
https://www.playmc.lk/api/topVotes/{serverId}/{limit}In this example, we retrieve the returned result in the $resultat variable. To read the result (in JSON), we convert it into an array. Then you just need to list the 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>";
}