Giter Club home page Giter Club logo

minecraft's Introduction

Minecraft Class

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.

Example Usage

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

Login

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

This function is used to login to your Minecraft account, taking 3 parameters: username (or email since Mojang account migration), password and the version of the minecraft launcher (optional) which is currently 12 by defaults. This returns true if the user was successfully authenticated and false otherwise. An array is also set upon successful login which 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.

If the authentication fail, you can use the getLastError() method to see why.


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 (optional if already used successfully the signin method) and returns true if a premium account was detected and false otherwise.


Get Skin Url

$minecraft->getSkinUrl('username');

This function firstly checks the user specified has a premium account, then returns an 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 (optional if already used successfully the signin method).


Keep Alive

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

This function is used to keep the user's current session alive, this command needs to be sent 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 into the account (optionals if already used successfully the signin method), this can be obtained with the code above...


Account

$minecraft->account['session_token'];

This variable is false if you didn't sign in correctly.


Render Skin

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

This function renders the specified player's skin. It takes 3 parameters, the first being the username of the player who's 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="data:image/png;base64,<?= base64_encode($minecraft->renderSkin('head', 64, 'nblackburn')) ?>">

If you want to call a php script which generate rendered skin, you can also use it like that :

<?php

require 'class.minecraft.php';

header('Content-Type: image/png');
$mc = new Minecraft();
// parameters can be passed by GET e.g.
echo $mc->renderSkin('head', 64, 'nblackburn');

So in your html file, you can just like it like an ordinary image.

<img src="path/to/your/script.php">

Get Username

$minecraft->getUsername();

This function return the username of the last successfully signed in user.

If no user has been successfully signed in, this function will throw an exception.

Get Last Error

$minecraft->getLastError();

This function can be called after an unsuccessfull call of signin to know why it failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.