davidoc26/mojang-api

Simple Mojang-API class

v2.2.1 2022-11-20 08:14 UTC

This package is auto-updated.

Last update: 2024-11-20 12:33:25 UTC


README

Simple and easy class to use

Latest Stable Version Total Downloads License PHP Version Require

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