Sueta

PHP Mojang API

1.5

A easy-to-use PHP class for accessing official Mojang's API

·Plugin

.

Description
A easy-to-use PHP class for accessing official Mojang's API.
This include UUID to username conversion, get Mojang status, or fetch user's skin/head.

Installation
First you need to download the resource, and require mojang-api.class.php . Other files are not needed in your project.

So it's simple as this:

// Require API  
 require   'mojang-api.class.php'   ;

Usage
A lot of sample code and example case are in example.php file, also be sure to check mojang-api.interface.php file to see all methods available.

// Require API  
 require   'mojang-api.class.php'   ;  

 // Get UUID from username  
 $uuid   =  MojangAPI  ::   getUuid   (   'MTC'   )   ;  
 echo   'UUID: <b>'   .   $uuid   .   '</b><br>'   ;  

 // Get his name history  
 $history   =  MojangAPI  ::   getNameHistory   (   $uuid   )   ;  
 echo   'First username: <b>'   .    reset    (   $history   )   [   'name'   ]   .   '</b><br>'   ;  

 // Print player's head  
 $img   =   '<img src="'   .  MojangAPI  ::   embedImage   (  MojangAPI  ::   getPlayerHead   (   $uuid   )   )   .   '" alt="Head of MTC">'   ;  
 echo   'Skin:<br>'   .   $img   .   '<br>'   ;  

 // Query a server  
 $query   =  MojangAPI  ::   query   (   'play.onecraft.fr'   ,   25565   )   ;  
 if   (   $query   )   echo   'There is '   .   $query   [   'players'   ]   .   ' players online out of '   .   $query   [   'maxplayers'   ]   .   '<br>'   ;  
 else   echo   'Server is offline.<br>'   ;

This code will result in:

Github
Code source is fully available on Github here: https://github.com/MineTheCube/MojangAPI
Don't hesitate to report issues or send pull request if needed !
.

Similar projects

Plugin →