Searching a good Minecraft API for PHP

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

FleecyTeddy

Member
Jan 26, 2017
4
0
0
Hello :emoji_slight_smile:
I'm currently searching a new API for my PHP website. I've used mcapi.ca before, but they took down essential stuff for my site. (My website uses the MCAPI to get usernames by uuids)
I know I could use the Mojang API to get the usernamea by uuids, but they have something like a spam protection that doesn't want me to get the names.

So... Is there any other MCAPI that could convert UUIDs to usernames?
 
Here you go :emoji_slight_smile:

PHP:
function uuid_to_username($uuid) {
    $uuid = minify_uuid($uuid);
    if (is_string($uuid)) {
        $json = file_get_contents('https://api.mojang.com/user/profiles/' . $uuid . '/names');
        if (!empty($json)) {
            $data = json_decode($json, true);
            if (!empty($data) and is_array($data)) {
                $last = array_pop($data);
                if (is_array($last) and isset($last['name'])) {
                    return $last['name'];
                }
            }
        }
    }
    return false;
}
function minify_uuid($uuid) {
    if (is_string($uuid)) {
        $minified = str_replace('-', '', $uuid);
        if (strlen($minified) === 32) {
            return $minified;
        }
    }
    return false;
}

ps: @BaeFell can we get syntax highlighting for php? <3
 
Last edited by a moderator:
Here you go :emoji_slight_smile:

PHP:
function uuid_to_username($uuid) {
    $uuid = minify_uuid($uuid);
    if (is_string($uuid)) {
        $json = file_get_contents('https://api.mojang.com/user/profiles/' . $uuid . '/names');
        if (!empty($json)) {
            $data = json_decode($json, true);
            if (!empty($data) and is_array($data)) {
                $last = array_pop($data);
                if (is_array($last) and isset($last['name'])) {
                    return $last['name'];
                }
            }
        }
    }
    return false;
}
function minify_uuid($uuid) {
    if (is_string($uuid)) {
        $minified = str_replace('-', '', $uuid);
        if (strlen($minified) === 32) {
            return $minified;
        }
    }
    return false;
}

ps: @BaeFell can we get syntax highlighting for php? <3
xenForo already has it. Just do [CODE=Your language here]CODE[/CODE]