Tool collection - Redstonecrafter0/RedstoneAPI GitHub Wiki

MojangAPI

This collection provides a subset of the Mojang API.

UUID by Name

Get a UUID by the playername

UUID uuid = MojangAPI.getUniqueIdByName("Notch");

Namehistory

Returns a List of all names and timestamps the player had before. NameHistory#getChangedToAt() returns null if it's the current name.

List<NameHistory> nameHistory = MojangAPI.getNameHistory(uuid);
for (NameHistory i : nameHistory) {
    System.out.println(i.getName() + " " + i.getChangedToAt());
}

MojangProfile

Get some data about a player.

MojangProfile profile = MojangAPI.getProfile(uuid);

Get UUID

Get the uuid

UUID uuid = profile.getUniqueId();

Get playername

Get the playername

String playerName = profile.getName();

Get the timestamp

Get the timestamp

long timestamp = profile.getTimestamp();

Get Skin

Get the players skin

BufferedImage

BufferedImage skin = profile.getSkin();

Base64 String

String b64Skin = profile.getSkinB64();

Get Cape

This is NOT for getting Optifine capes but for official Mojang Capes.

BufferedImage

BufferedImage cape = profile.getCape();

Base64 String

String b64Cape = profile.getCapeB64();

Convert UUIDs

getUniqueIdByString

Get a UUID with inserted '-' where necessary

UUID uuid = MojangAPI.getUniqueIdByString("00000000000000000000000000000000");

uniqueIdToString

Convert a UUID to a String without the '-'

String uuidString = MojangAPI.uniqueIdToString(uuid);

ServerListPing

Ping a Minecraft server to get some data.

ServerListPing slp = ServerListPing.ping("localhost");

ServerListPing slp = ServerListPing.ping("localhost", port); // for custom port

Favicon

Get the favicon.

RenderedImage

RenderedImage favicon = slp.getFavicon();

Base64 String

String faviconB64 = slp.getFaviconB64();

Players

Max players

long maxPlayers = slp.getMaxPlayers();

Online players

long online = slp.getOnlinePlayers();

MOTD

Colorless

Get the MOTD without color codes and formatting codes.

String motd = slp.getMotd();

Colored

Get the MOTD with color codes forced to the format with '§'

String motdColored = slp.getMotdColored();

Version

Get the version name.

String version = slp.getVersion();

Protocol

Get the protocol version number.

int protocol = slp.getProtocol();

Ping

Get the latency.

long ping = slp.getLatency();

MinecraftColors

A enum that contains all colors available in Minecraft.

Getting

Of course there is the standart java way of enums but there are more possablities.

By name

MinecraftColors color = MinecraftColors.getColorByName("dark_red");

By key

MinecraftColors color = MinecraftColors.getColorByKey("4");

Values

Key

The key that the '4' for example in '§4Thats dark red'.

String key = MinecraftColors.DARK_RED.getKey();

Name

That is the color name used in json messages.

String name = MinecraftColors.DARK_RED.getName();

MinecraftTools

This is a litte toolbox that contains some features that may be useful.

isSlimeChunk

Check if a chunk is a slime chunk by the seed and CHUNK COORDINATES. If you have the block cooridnates just divide them by 32 und cut off the decimals.

boolean slimeChunk = MinecraftTools.isSlimeChunk(2908347, 5, 12);

// from block coordinates
boolean slimeChunk = MinecraftTools.isSlimeChunk(2908347, Math.floor(532 / 32), Math.floor(1234 / 32));

textToSeed

Get the long seed by a seed in text format.

long seed = MinecraftTools.textToSeed("lol");

IntUtils

A utils class for numbers (not only integers).

random

Get a random number between two numbers

int number = IntUtils.random(10, 50);

round

Ever wanted to round a number to a specific length?

double rounded = IntUtils.round(1234.56789, 2);

normalize

Get a double array of a double array with only values from 0 to 1.

double[] normalized = IntUtils.normalize(1, 23, 1, 214, 412, 412, 41, 513, 51);

StringUtils

sameChar

Get a String of the same char as long as you want

String str = StringUtils.sameChar('+', 20);

isValid

Check if a String is valid by providing the text to check and a whitelist. There is a default whitelist

boolean valid = StringUtils.isValid("Is this valid or ⓝⓞⓣ?", StringUtils.DEFAULT_WHITELISTED_CHARS);

stringFromError

Get the stacktrace of an exception as a String.

try {
  throw new NullPointerException();
} catch (Throwable e) {
  String error = StringUtils.stringFromError(e);
}

parseArgs

Parse args with joining arguments when between quotation marks ans backslash escaping.

String[] args = StringUtils.parseArgs("whatever \"you are\\\" using\" here);

Version

A wrapper for version Strings like 'v1.0', 'pre-1', 'v1', 'pre-1.0', '1' or 'v1.0'.

Version version = new Version("v1.0");

Version version = new Version(new int[]{1, 0});

boolean prefixWithV = true;
boolean preRelease = false;
Version version = new Version(new int[]{1, 0}, prefixWithV, preRelease);

getMajor

Get the major version number

int major = version.getMajor();

getMinor

Get the minor version number

int minor = version.getMinor();

getPatch

Get the patch version number

int patch = version.getPatch();

getBuild

Get the build version number

int build = version.getBuild();

Get a version number on position

Using 0 will equal getMajor, 1 will equal getMinor, 2 will equal getPatch and 3 will equal getBuild.

int number = version.getOnPos(4);

Get depth

Get the max depth the version has.

int depth = version.getDepth();

isOlderThan

Does what it says

boolean isOlder = version.isOlderThan(version1);

isNewerThan

Does also what it says

boolean isNewer = version.isNewerThan(version1);

equals

Returns true if the version is the same.

boolean sameVersion = version.equals(version1);

isPrerelease

Returns true if it was set to true in the contructor manually or by prefixing with 'pre-'.

boolean preRelease = version.isPreRelease();

HttpRequest

Simple wrapper for HTTP requests.

HttpHeader

Used for the HttpRequest

HttpHeader header = new HttpHeader("key", "value");

Requests

GET

Perform a 'GET' request. It works similar for HEAD and DELETE.

HttpRequest response = HttpRequest.get("localhost");

// include headers
HttpRequest response = HttpRequest.get("localhost", new HttpHeader("key", "value"), new HttpHeader("key", "value"), ... );

POST

Perform a 'POST' request. It works similar for PUT and PATCH.

HttpRequest response = HttpRequest.post("localhost", "lol".getBytes(StandardCharsets.UTF_8));

// include headers
HttpRequest response = HttpRequest.post("localhost", "lol".getBytes(StandardCharsets.UTF_8), new HttpHeader("key", "value"), new HttpHeader("key", "value"), ... );

Response

A HttpRequest object

getContent

Get the reponse content as byte array.

byte[] content = response.getContent();

getContentAsString

Get the reponse content as String assuming the format is utf-8.

String content = response.getContentAsString();

getJsonArray

Parse the response content automatically as JSONArray.

JSONArray arr = response.getJsonArray();

getJsonObject

Parse the response content automatically as JSONObject.

JSONObject obj = response.getJsonObject();

getResponseCode

Get the HTTP response code. 200 = OK, 404 = NOT FOUND, ...

int code = response.getResponseCode();

getMimeType

Get the MIME type of the response content.

String mime = response.getMimeType();

Terminal

The terminal uses the console input for performing commands because it behaves similar to the CommandManager of the DiscordBot i reference it here.

EventManager

The EventManager is just a codebase you can use for an event system in your program. For a class to have events it must extend EventHandler. Each event is annotated with @EventListener or @EventListener(priority = 0) as the default priority. En event can be made by extending the Event abstract class. If it should be cancable implement CancellableEvent. To register an EventHandler use registerEventListener on the EventManager. To fire an Event use fireEvent on the EventManager.

Proxy

There are SOCKS4 and SOCKS5 without authentication predefined. It behaves like a normal Socket object but is proxied through SOCKS. Notice that the traffic is NOT encrypted due to the protocol and has to be done manually. Create an instance with the parameters of the proxy server host and proxy server port. Connect to where you want to proxy to by using the host and port of it in the connect method. You can get the InputStream and OutputStream to send and receive data.

HashLib

It is basicly a collection of static methods and is selfexplaing on usage.