Advertisement
kyroskoh

Twitch CustomAPI - Minecraft Server Status

May 7th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.37 KB | None | 0 0
  1. <?php
  2. /*  Quick Minecraft Server status API.
  3.  *  Currently supported languages include:
  4.  *  en = English - default
  5.  *  nl = Dutch
  6.  *  zh = Chinese
  7.  *  de = German
  8.  *  ja = Japanese
  9.  *  ru = Russian
  10.  *  es = Spanish
  11.  * Blame Google if translations are off. */
  12.  
  13. // Set variables of GET data.
  14. $Broadcaster = $_GET["Broadcaster"];
  15. $Language = $_GET["Language"];
  16. $MinecraftServer = $_GET["Server"];
  17. // Check if a server is specified, if not, use default.
  18. if(empty($_GET["Server"]) || $_GET["Server"] == null)
  19. {
  20.     // Just some random server I grabbed off a website.
  21.     $MinecraftServer = "play.teegeecraft.net";
  22. }
  23. // For URL simplicity, just specify broadcaster, and use built in defaults for that broadcaster.
  24. if($Broadcaster == "BananaFlavourHD")
  25. {
  26.     $Language = "nl";
  27.     if (empty($_GET["Server"]))
  28.     {
  29.         // Default server to use if nothing specified.
  30.         $MinecraftServer = "193.111.140.158:28281";
  31.     }
  32. }
  33. // Pull and decode JSON data for the specified server.
  34. // $MinecraftServerJson = json_decode(@file_get_contents("https://mcapi.ca/query/$MinecraftServer/info"), true);
  35. // Was advised to use cURL to retrieve JSON.
  36. $ch = curl_init("https://mcapi.ca/query/" . $MinecraftServer . "/info");
  37. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  38. $result = curl_exec($ch);
  39. curl_close($ch);
  40. $MinecraftServerJson = json_decode($result, true);
  41.  
  42.  
  43. // Display Minecraft Server JSON data in the correct language.
  44. if($Language == "nl") // Dutch
  45. {
  46.     if($MinecraftServerJson["status"] == null)
  47.     {
  48.         echo ' Server "' . $MinecraftServer . '" is momenteel offline!';
  49.         die();
  50.     }
  51.     else
  52.     {
  53.     echo $MinecraftServer . ' heeft ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' spelers, met een ping van ' . $MinecraftServerJson['ping'] . 'ms.';
  54.     die();
  55.     }
  56. }
  57. if($Language == "zh") // Chinese
  58. {
  59.     if($MinecraftServerJson["status"] == null)
  60.     {
  61.         echo ' 服务器 "' . $MinecraftServer . '" 当前离线!';
  62.         die();
  63.     }
  64.     else
  65.     {
  66.         echo $MinecraftServer . ' 具有 ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' 玩家用的ping ' . $MinecraftServerJson['ping'] . 'ms.';
  67.         die();
  68.     }
  69. }
  70. if($Language == "de") // German
  71. {
  72.     if($MinecraftServerJson["status"] == null)
  73.     {
  74.         echo ' Server "' . $MinecraftServer . '" ist zur Zeit offline!';
  75.         die();
  76.     }
  77.     else
  78.     {
  79.         echo $MinecraftServer . ' hat ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' Spieler, mit einem Ping von ' . $MinecraftServerJson['ping'] . 'ms.';
  80.         die();
  81.     }
  82. }
  83. if($Language == "ja") // Japanese
  84. {
  85.     if($MinecraftServerJson["status"] == null)
  86.     {
  87.         echo ' サーバ "' . $MinecraftServer . '" 現在オフラインです!';
  88.         die();
  89.     }
  90.     else
  91.     {
  92.         echo $MinecraftServer . ' 持っています ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' のpingを持つ選手、 ' . $MinecraftServerJson['ping'] . 'ms.';
  93.         die();
  94.     }
  95. }
  96. if($Language == "ru") // Russian
  97. {
  98.     if($MinecraftServerJson["status"] == null)
  99.     {
  100.         echo ' сервер "' . $MinecraftServer . '" в настоящее время оффлайн!!';
  101.         die();
  102.     }
  103.     else
  104.     {
  105.         echo $MinecraftServer . ' имеет ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' игроки, с пинга ' . $MinecraftServerJson['ping'] . 'ms.';
  106.         die();
  107.     }
  108. }
  109. if($Language == "es") // Spanish
  110. {
  111.     if($MinecraftServerJson["status"] == null)
  112.     {
  113.         echo ' Servidor "' . $MinecraftServer . '" se encuentra actualmente fuera de línea!';
  114.         die();
  115.     }
  116.     else
  117.     {
  118.         echo $MinecraftServer . ' tiene ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' jugadores, con un ping de ' . $MinecraftServerJson['ping'] . 'ms.';
  119.         die();
  120.     }
  121. }
  122. else // English - Default
  123. {
  124.     if($MinecraftServerJson["status"] == null)
  125.     {
  126.         echo ' Server "' . $MinecraftServer . '" is currently offline!';
  127.         die();
  128.     }
  129.     else
  130.     {
  131.         echo $MinecraftServer . ' has ' . $MinecraftServerJson['players']['online'] . '/' . $MinecraftServerJson['players']['max'] . ' players, with a ping of ' . $MinecraftServerJson['ping'] . 'ms.';
  132.         die();
  133.     }
  134. }
  135.  
  136. ?>
  137.  
  138. Example:
  139. MinecraftServerStatus.php?Server=play.minesuperior.com
  140. or
  141. MinecraftServerStatus.php?Server=play.minesuperior.com&Language=ru
  142. or
  143. MinecraftServerStatus.php?Broadcaster=TwitchName&Server=MinecraftServer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement