Minecraft API
![Software License][ico-license], (*1)
This is a simple package providing you with all the tools to quickstart
development on that Minecraft site you've been craving. Retrieve UUIDs based
on usernames or the other way around with a simple and human-readable API., (*2)
Install
Via composer:, (*3)
$ composer require sven/minecraft-php
If you're using the Laravel framework, you can add the MinecraftServiceProvider
to your
providers
array:, (*4)
// config/app.php
'providers' => [
...
Sven\Minecraft\MinecraftServiceProvider::class,
...
];
You may also add the Minecraft
facade to the aliases
array to use the facade:, (*5)
// config/app.php
'aliases' => [
...
'Minecraft' => Sven\Minecraft\Facades\Minecraft::class,
...
];
Usage
$minecraft = new Sven\Minecraft\Minecraft;
// Build up the user object from a given username.
$minecraft->fromName($username);
// Supply an optional UNIX timestamp to get the user object of the player who
// owned that username at the time.
$minecraft->fromName($username, time() - (365 * 24 * 60 * 60));
// Build up the user object from a given UUID.
$minecraft->fromUuid($uuid);
If you specified the alias in config/app.php
, you can use the facade:, (*6)
Minecraft::fromName($username);
Minecraft::fromUuid($uuid);
This always returns you the same object (Sven\Minecraft\Minecraft
). You may use
the get()
and only($property)
methods on it to retrieve the data:, (*7)
$minecraft = new Minecraft;
$user = $minecraft->fromName('jeb_');
$user->get()->name; // jeb_
$user->get()->uuid; // 853c80ef3c3749fdaa49938b674adae6
$user->only('name'); // jeb_
$user->only('uuid'); // 853c80ef3c3749fdaa49938b674adae6
If you want more flexibility, the ->get()
method returns a JSON object of
data for your user:, (*8)
$user->get(); // {"name": "jeb_", "uuid": "853c80ef3c3749fdaa49938b674adae6"}
Rate limiting
Mojang has some rate limiting in place so you are expected to cache the
results. You may send 1 request per minute to the same resource, and
you may request as many unique resources as you'd like. Keep in mind
Mojang might change this at any time., (*9)
Credits
This is simply a wrapper around Mojang's API, beautifully
(yet unofficially) documented at http://wiki.vg/Mojang_API., (*10)
License
sven/minecraft-php
is licensed under the MIT License (MIT). Please see the
license file for more information., (*11)