102 lines
3.3 KiB
PHP
102 lines
3.3 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class MinecraftModel extends CI_Model {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function getUUID($username) {
|
|
$json = json_decode(@file_get_contents('https://api.mojang.com/users/profiles/minecraft/' . $username));
|
|
|
|
if(empty($json)) {
|
|
return ["Nicht vorhanden", $username, true];
|
|
} else {
|
|
$uuid = $json->id;
|
|
$name = $json->name;
|
|
return [$uuid, $name, false];
|
|
}
|
|
}
|
|
public function getIcon($user) {
|
|
return "https://crafatar.com/avatars/" . $user . "?overlay&size=64&default=MHF_Alex";
|
|
}
|
|
public function getRender($user) {
|
|
return "https://crafatar.com/renders/body/" . $user . "?overlay&scale=7&default=MHF_Alex";
|
|
}
|
|
public function serverIcon($server) {
|
|
return "https://craftapi.com/api/server/favicon/" . $server;
|
|
}
|
|
public function getServerName($server) {
|
|
$json = json_decode(@file_get_contents('https://craftapi.com/api/server/info/' . $server));
|
|
|
|
if(!empty($json->error) || empty($json)) {
|
|
return lang('servers_error_ip');
|
|
} else {
|
|
return $json->server;
|
|
}
|
|
}
|
|
public function getPlayers($server) {
|
|
$json = json_decode(@file_get_contents('https://craftapi.com/api/server/info/' . $server));
|
|
|
|
if (!empty($json->error)) {
|
|
return lang('servers_error');
|
|
} else {
|
|
$online = $json->players->online;
|
|
$max = $json->players->max;
|
|
$ping = floatval($json->latency) * 1000;
|
|
$version = $json->version->name;
|
|
|
|
if($online < $max) {
|
|
$color = "#00AA00";
|
|
} else {
|
|
$color = "#FFAA00";
|
|
}
|
|
|
|
return [$online, $max, $color, $ping, $version];
|
|
}
|
|
}
|
|
public function getMOTD($server) {
|
|
$json = json_decode(@file_get_contents('https://craftapi.com/api/server/info/' . $server));
|
|
|
|
if(!empty($json->error) || empty($json)) {
|
|
return lang('servers_error');
|
|
} else {
|
|
return $json->motd;
|
|
}
|
|
}
|
|
public function getHistory($uuid) {
|
|
$json = json_decode(@file_get_contents('https://craftapi.com/api/user/namehistory/' . $uuid));
|
|
|
|
$return = '';
|
|
if(!empty($json)) {
|
|
foreach($json as $element) {
|
|
$name = $element->name;
|
|
|
|
if(!empty($element->changedToAt)) {
|
|
$milliseconds = floatval($element->changedToAt);
|
|
$date = date("d.m.Y \u\m H:i:s", $milliseconds/1000);
|
|
$changedtoat = $date . " Uhr";
|
|
} else {
|
|
$changedtoat = "<i>" . lang('player_original_name') . "</i>";
|
|
}
|
|
|
|
$return .= "<tr><td>" . $name . "</td><td>" . $changedtoat . "</td></tr>";
|
|
}
|
|
return $return;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function formatUUID($uuid) {
|
|
$return = $uuid;
|
|
$return = substr_replace($return, '-' . $uuid[8], 8, -23);
|
|
$return = substr_replace($return, '-' . $uuid[12], 13, -19);
|
|
$return = substr_replace($return, '-' . $uuid[16], 18, -15);
|
|
$return = substr_replace($return, '-' . $uuid[20], 23, -11);
|
|
|
|
return $return;
|
|
}
|
|
}
|