1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Searching a good Minecraft API for PHP

Discussion in 'General' started by FleecyTeddy, Feb 18, 2017.

  1. FleecyTeddy

    FleecyTeddy Member

    Joined:
    Jan 26, 2017
    Messages:
    4
    Likes Received:
    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?
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,049
    Likes Received:
    145
    Here you go :emoji_slight_smile:

    Code (PHP):
    1. function uuid_to_username($uuid) {
    2.     $uuid = minify_uuid($uuid);
    3.     if (is_string($uuid)) {
    4.         $json = file_get_contents('https://api.mojang.com/user/profiles/' . $uuid . '/names');
    5.         if (!empty($json)) {
    6.             $data = json_decode($json, true);
    7.             if (!empty($data) and is_array($data)) {
    8.                 $last = array_pop($data);
    9.                 if (is_array($last) and isset($last['name'])) {
    10.                     return $last['name'];
    11.                 }
    12.             }
    13.         }
    14.     }
    15.     return false;
    16. }
    17. function minify_uuid($uuid) {
    18.     if (is_string($uuid)) {
    19.         $minified = str_replace('-', '', $uuid);
    20.         if (strlen($minified) === 32) {
    21.             return $minified;
    22.         }
    23.     }
    24.     return false;
    25. }
    ps: @BaeFell can we get syntax highlighting for php? <3
     
    #2 ShaneBee, Feb 18, 2017
    Last edited by a moderator: Feb 18, 2017
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,049
    Likes Received:
    145
    xenForo already has it. Just do [CODE=Your language here]CODE[/CODE]
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,049
    Likes Received:
    145
    Ah, it wasn't in the dropdown. Thanks for that!
     
Loading...