davidoc26 / mojang-api
Simple Mojang-API class
v2.2.1
2022-11-20 08:14 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-gd: *
- ext-json: *
- guzzlehttp/guzzle: ^7.3
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^6.0
- vimeo/psalm: ^4.9
README
Simple and easy class to use
Installation
composer require davidoc26/mojang-api
Usage
Get status of Mojang services
use Davidoc26\MojangAPI\MojangAPI; $mojangAPI = new MojangAPI(); $services = $mojangAPI->apiStatus(); foreach ($services as $service) { echo $service->getName(); // the name of service echo $service->getStatus(); // can be green/yellow/red }
Get UUID by username
$uuid = $mojangAPI->getUuid('Test'); // d8d5a9237b2043d8883b1150148d6955
Get username names history
$uuid = $mojangAPI->getUuid('Test'); $users = $mojangAPI->getNameHistory($uuid); foreach ($users as $user) { echo $user->getName(); echo date('d M | Y', $user->getChangedToAt()); // Be careful! getChangedToAt() can return null }
Render user head
$url = $mojangAPI->getSkinUrl($uuid); $head = $mojangAPI->renderHead($url, 300); // the second argument is the size of head echo "<img src='$head' alt='head'>";
Authentication
$user = $mojangAPI->authenticate('email','password'); $user->getName(); $user->getUuid(); $user->getAccessToken(); $user->nameAvailability($newName); // You can also render the head of the current player. $user->renderHead($size);
Check name availability
$isAvailable = $mojangAPI->nameAvailability($username, $token); // bool