Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Quick Minecraft Server status API.
- * Currently supported languages include:
- * en = English - default
- * nl = Dutch
- * zh = Chinese
- * de = German
- * ja = Japanese
- * ru = Russian
- * es = Spanish
- * Blame Google if translations are off. */
- // Set variables of GET data.
- $Broadcaster = $_GET["Broadcaster"];
- $Language = $_GET["Language"];
- $MinecraftServer = $_GET["Server"];
- // Check if a server is specified, if not, use default.
- if(empty($_GET["Server"]) || $_GET["Server"] == null)
- {
- // Just some random server I grabbed off a website.
- $MinecraftServer = "play.teegeecraft.net";
- }
- // For URL simplicity, just specify broadcaster, and use built in defaults for that broadcaster.
- if($Broadcaster == "BananaFlavourHD")
- {
- $Language = "nl";
- if (empty($_GET["Server"]))
- {
- // Default server to use if nothing specified.
- $MinecraftServer = "193.111.140.158:28281";
- }
- }
- // Pull and decode JSON data for the specified server.
- // $MinecraftServerJson = json_decode(@file_get_contents("https://mcapi.ca/query/$MinecraftServer/info"), true);
- // Was advised to use cURL to retrieve JSON.
- $ch = curl_init("https://mcapi.ca/query/" . $MinecraftServer . "/info");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($ch);
- curl_close($ch);
- $MinecraftServerJson = json_decode($result, true);
- // Display Minecraft Server JSON data in the correct language.
- if($Language == "nl") // Dutch
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' Server "' . $MinecraftServer . '" is momenteel offline!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' heeft ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' spelers, met een ping van ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- if($Language == "zh") // Chinese
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' 服务器 "' . $MinecraftServer . '" 当前离线!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' 具有 ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' 玩家用的ping ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- if($Language == "de") // German
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' Server "' . $MinecraftServer . '" ist zur Zeit offline!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' hat ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' Spieler, mit einem Ping von ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- if($Language == "ja") // Japanese
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' サーバ "' . $MinecraftServer . '" 現在オフラインです!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' 持っています ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' のpingを持つ選手、 ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- if($Language == "ru") // Russian
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' сервер "' . $MinecraftServer . '" в настоящее время оффлайн!!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' имеет ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' игроки, с пинга ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- if($Language == "es") // Spanish
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' Servidor "' . $MinecraftServer . '" se encuentra actualmente fuera de línea!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' tiene ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' jugadores, con un ping de ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- else // English - Default
- {
- if($MinecraftServerJson["status"] == null)
- {
- echo ' Server "' . $MinecraftServer . '" is currently offline!';
- die();
- }
- else
- {
- echo $MinecraftServer . ' has ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' players, with a ping of ' . $MinecraftServerJson['ping'] . 'ms.';
- die();
- }
- }
- ?>
- Example:
- MinecraftServerStatus.php?Server=play.minesuperior.com
- or
- MinecraftServerStatus.php?Server=play.minesuperior.com&Language=ru
- or
- MinecraftServerStatus.php?Broadcaster=TwitchName&Server=MinecraftServer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement