README
MinecraftAPI
This package is a wrapper for the official Minecraft API
- Minecraft
Minecraft
This is an Offical API Offical Docs
Usage
const {MinecraftAPI} = require("@mattplays/minecraft-api")
const API = new MinecraftAPI();
Functions
GetAPIStatus
Returns status of various Mojang services. Possible values are green (no issues), yellow (some issues), red (service unavailable).
Output
The GetAPIStatus function returns a Promise<ServerStatusResponse>
type
Usage
const API = new MinecraftAPI();
API.GetAPIStatus().then((data) => {
// Your Code Here :D
}).catch((err) => {
// Handle error Here D:
});;
Authenticate
Authenticates a user using their password.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
username | string |
Yes | The user's username |
password | string |
Yes | The user's password |
##### Output | |||
The Authenticate function returns a Promise<AuthenticationResponse> type |
|||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.Authenticate("Notch", "MINECRAFTROCKS").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
});; | |||
``` | |||
#### Refresh | |||
Refreshes a valid accessToken. It can be used to keep a user logged in between gaming sessions and is preferred over storing the user's password in a file see lastlogin. | |||
##### Inputs |
Note that an accessToken may be unusable for authentication with a Minecraft server, but still be good enough for /refresh. This mainly happens when one has used another client (e.g. played Minecraft on another PC with the same account). It seems only the most recently obtained accessToken for a given account can reliably be used for authentication (the next-to-last token also seems to remain valid, but don't rely on it).
/validate may be called with or without a clientToken. If a clientToken is provided, it should match the one used to obtain the accessToken. The Minecraft Launcher does send a clientToken to /validate.
Inputs
Parameter | Type | Required | Description |
---|---|---|---|
accessToken | string |
Yes | The user's accessToken |
clientToken | string |
No | The clientToken that was used to obtain accessToken in the first place |
##### Output | |||
The Validate functions returns an empty payload (Promise<any> ) |
|||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.Validate("DUMMY_ACCESS-TOKEN").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### Signout | |||
Invalidates accessTokens using an account's username and password. | |||
##### Inputs | |||
Parameter | Type | Required | Description |
------------- | ------------- | ------------- | ------------- |
username | string |
Yes | The user's username |
password | string |
Yes | The user's password |
##### Output | |||
The Signout function returns an empty payload if successful (Promise<any> ) |
|||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.Signout("Notch", "Minecraft-ROCKS").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### Invalidate | |||
Invalidates accessTokens using a client/access token pair. | |||
##### Inputs | |||
Parameter | Type | Required | Description |
------------- | ------------- | ------------- | ------------- |
accessToken | string |
Yes | The user's accessToken |
clientToken | string |
Yes | The clientToken that was used to obtain accessToken in the first place |
##### Output | |||
The Invalidate function returns an empty payload if successful (Promise<any> ) |
|||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.Invalidate("DUMMMY_ACCESS-TOKEN", "DUMMY_CLIENT-TOKEN").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### UsernameToUUID | |||
This will return the UUID of the username. | |||
##### Input | |||
Parameter | Type | Required | Description |
------------- | ------------- | ------------- | ------------- |
username | string |
Yes | The user's username |
##### Output | |||
The UsernameToUUID function returns a Promise<UUIDResponse> type |
|||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.UsernameToUUID("Notch").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### UsernamesToUUIDs | |||
This will return player UUIDs and some extras. | |||
##### Input | |||
Parameter | Type | Required | Description |
------------- | ------------- | ------------- | ------------- |
usernames | string[] |
Yes | List of Usernames |
##### Output | |||
The UsernameToUUID function returns a Promise<UUIDResponse> type |
|||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.UsernamesToUUIDs(["Notch", "jeb_"]).then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### UUIDToNameHistory | |||
Returns all the usernames this user has used in the past and the one they are using currently. The UUID must be given either without, or correctly formatted hyphens. | |||
##### Input | |||
Parameter | Type | Required | Description |
------------- | ------------- | ------------- | ------------- |
uuid | string |
Yes | The user's UUID |
##### Output | |||
The UUIDToNameHistory function returns | |||
```javascript | |||
Promise<{name: string, changedToAt: number}[]> | |||
``` | |||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.UUIDToNameHistory("069a79f444e94726a5befca90e38aaf5").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### UUIDToSkin | |||
This will return the player's username plus any additional information about them (e.g. skins). Example This has no ratelimit. | |||
##### Inputs | |||
Parameter | Type | Required | Description |
------------- | ------------- | ------------- | ------------- |
uuid | string |
Yes | The user's UUID |
##### Output | |||
The UUIDToSkin function returns | |||
```javascript | |||
Promise<{id: string, name: string, properties: {name: string, value: string, signature: string}[], legacy: boolean}> | |||
``` | |||
##### Usage | |||
```javascript | |||
const API = new MinecraftAPI(); | |||
API.UUIDToSkin("4566e69fc90748ee8d71d7ba5aa00d20").then((data) => { | |||
// Your Code Here :D | |||
}).catch((err) => { | |||
// Handle error Here D: | |||
}); | |||
``` | |||
#### GetBlockedServers | |||
Returns a list of SHA1 hashes used to check server addresses against when the client tries to connect. |
Clients check the lowercase name, using the ISO-8859-1 charset, against this list. They will also attempt to check subdomains, replacing each level with a *. Specifically, it splits based off of the . in the domain, goes through each section removing one at a time. For instance, for mc.example.com, it would try mc.example.com, *.example.com, and *.com. With IP addresses (verified by having 4 split sections, with each section being a valid integer between 0 and 255, inclusive) substitution starts from the end, so for 192.168.0.1, it would try 192.168.0.1, 192.168.0.*, 192.168.*, and 192.*.
This check is done by the bootstrap class in netty. The default netty class is overridden by one in the com.mojang:netty dependency loaded by the launcher. This allows it to affect any version that used netty (1.7+)
Output
The GetBlockedServers function returns a Promise<string[]>
type
Usage
const API = new MinecraftAPI();
API.GetBlockedServers().then((data) => {
// Your Code Here :D
}).catch((err) => {
// Handle error Here D:
});
GetStatistics
Get statistics on the sales of Minecraft.