Minecraft

This class was developed to provide a set of functions to integrate Minecraft within your projects. Under no circumstances are you permitted to use this for malicious purposes.

Please note that the API surrounding Minecraft has seen dramatic changes since this libraries creation and as a result more than likely doesn't work in places.

Because Minecraft seems to have been aquired, i have decided to archive this code as it no longer seems worth updating knowing that Minecraft will become less open than it once was.

Example Usage

<?php  
    include('class.minecraft.php');
    if ($minecraft->signin('username', 'password') == true) {
        foreach($minecraft->account as $field => $value) {
            echo($field.'->'.$value.'<br>');
        }
    } else {
        echo('Error!');
    }
?>

Login

$minecraft->signin('username', 'password', 'version');

This function is used to login to your Minecraft account, taking 3 parameters: username, password and the version of the minecraft
launcher which currently defaults to 12. This returns that users account details if the user was successfully authenticated and false
otherwise. The account array that is set upon successful login contains the following...

  • current_version: The current version of the games resources.
  • correct_username: A correctly formatted username.
  • session_token: The current session used to login to the Minecraft client.
  • premium_account: If the account specified is of premium status.
  • player_skin: The url to the users custom skin, if applicable.
  • request_timestamp: the timestamp for the request which is formatted as DDMMYYYYHHMMSS in local server time.
$minecraft->account();

This array can be called using the function above once the user has logged in to their account otherwise null will be returned
when calling this function.


Is Premium

$minecraft->isPremium('username');

This function determines if the user specified has a premium account or not. It takes a single parameter of username and
returns true if a premium account was detected and false otherwise.


Get Skin

$minecraft->getSkin('username');

This function firstly checks the user specified has a premium account, then returns a url to the skin file for that user if
a custom skin was found. It takes a single parameter which is the username of the user you which to get the skin file of.


Keep Alive

$minecraft->keepAlive('username', 'session');

This function is used to keep the users current session alive, this command needs sending to the Minecraft servers every 600
ticks (60 seconds) otherwise the user is signed out. It takes 2 parameters, the username and session returned from signing
in to your account, this can be obtained with the following code...

$minecraft->account['session_token'];

The function returns null as the Minecraft server doesnt appear to throw back any exceptions or acknowledgement of the request.


Render Skin

$minecraft->renderSkin($username, $render_type, $size);

This function renders the specified player's skin. It takes 3 parameters, the first being the username of the player whos skin you wish to render,
the render_type which can either be head OR body and the size you would like the rendered image to be. Please note when rendering
the full body, the image width is half the size of the image height. You can include this function directly inside a img tag by using the following
example...

<img src="<?php echo($minecraft->render_skin('nblackburn', 'head', 100)) ?>" width="100" height="100">  

Download