Class Documentation: BedrockStatus
The BedrockStatus
class is a Java utility for fetching and retrieving the status of a Minecraft Bedrock Edition server using the mcstatus.io API. It provides methods to access various server details such as online status, player count, version, MOTD, and more.
Class Overview
Package
package io.github.undeffineddev.mcstatusio.bedrock;
Class Declaration
public class BedrockStatus
Constructors
BedrockStatus(String address)
BedrockStatus(String address)
Fetches the status of a Bedrock server with a default timeout of 5 seconds.
Parameters:
address
(String): The server address (e.g.,"example.com"
or"192.168.1.1:19132"
).
Throws:
IllegalArgumentException
: If the server address is null or empty.RuntimeException
: If an error occurs during the API request.
BedrockStatus(String address, double timeout)
BedrockStatus(String address, double timeout)
Fetches the status of a Bedrock server with a custom timeout.
Parameters:
address
(String): The server address.timeout
(double, optional): The timeout in seconds for the API request. Defaults to5.0
if not provided.
Throws:
IllegalArgumentException
: If the server address is null or empty.RuntimeException
: If an error occurs during the API request.
Methods
isOnline()
isOnline()
Checks if the server is online.
Returns:
boolean
:true
if the server is online,false
otherwise.
getHost()
getHost()
Gets the server's host address.
Returns:
String
: The server's host address.
getPort()
getPort()
Gets the server's port.
Returns:
int
: The server's port.
getIpAddress()
getIpAddress()
Gets the server's IP address.
Returns:
String
: The server's IP address, ornull
if not available.
isEulaBlocked()
isEulaBlocked()
Checks if the server is blocked due to EULA violations.
Returns:
boolean
:true
if the server is EULA blocked,false
otherwise.
getRetrievedAt()
getRetrievedAt()
Gets the timestamp when the data was retrieved.
Returns:
long
: The timestamp in milliseconds.
getExpiresAt()
getExpiresAt()
Gets the timestamp when the data expires.
Returns:
long
: The timestamp in milliseconds.
getVersionName()
getVersionName()
Gets the version name of the server.
Returns:
String
: The version name, ornull
if the server is offline.
getVersionProtocol()
getVersionProtocol()
Gets the protocol version of the server.
Returns:
int
: The protocol version, or-1
if the server is offline.
getPlayersOnline()
getPlayersOnline()
Gets the number of players currently online.
Returns:
int
: The number of players online, or0
if the server is offline.
getMaxPlayers()
getMaxPlayers()
Gets the maximum number of players allowed on the server.
Returns:
int
: The maximum number of players, or0
if the server is offline.
getMotdRaw()
getMotdRaw()
Gets the raw MOTD (Message of the Day) of the server.
Returns:
String
: The raw MOTD, ornull
if the server is offline.
getMotdClean()
getMotdClean()
Gets the clean MOTD (Message of the Day) of the server.
Returns:
String
: The clean MOTD, ornull
if the server is offline.
getMotdHtml()
getMotdHtml()
Gets the HTML MOTD (Message of the Day) of the server.
Returns:
String
: The HTML MOTD, ornull
if the server is offline.
getGamemode()
getGamemode()
Gets the game mode of the server.
Returns:
String
: The game mode, ornull
if the server is offline.
getServerId()
getServerId()
Gets the server ID.
Returns:
String
: The server ID, ornull
if the server is offline.
getEdition()
getEdition()
Gets the edition of the server (e.g., "MCPE"
or "MCEE"
).
Returns:
String
: The server edition, ornull
if the server is offline.
Usage Example
import io.github.undeffineddev.mcstatusio.bedrock;
public class Main {
public static void main(String[] args) {
// Change this to the Bedrock server address you wish to query.
String serverAddress = "bedrock.example.com";
try {
// Create an instance of BedrockStatus with the default timeout (5.0 seconds)
BedrockStatus bedrockStatus = new BedrockStatus(serverAddress);
// Display whether the server is online
System.out.println("Server online: " + bedrockStatus.isOnline());
if (bedrockStatus.isOnline()) {
// Basic server information
System.out.println("Host: " + bedrockStatus.getHost());
System.out.println("Port: " + bedrockStatus.getPort());
System.out.println("IP Address: " + bedrockStatus.getIpAddress());
System.out.println("EULA Blocked: " + bedrockStatus.isEulaBlocked());
System.out.println("Data retrieved at: " + bedrockStatus.getRetrievedAt());
System.out.println("Data expires at: " + bedrockStatus.getExpiresAt());
// Version information
System.out.println("Version Name: " + bedrockStatus.getVersionName());
System.out.println("Version Protocol: " + bedrockStatus.getVersionProtocol());
// Players information
System.out.println("Players Online: " + bedrockStatus.getPlayersOnline());
System.out.println("Max Players: " + bedrockStatus.getMaxPlayers());
// MOTD (Message of the Day) information
System.out.println("MOTD (raw): " + bedrockStatus.getMotdRaw());
System.out.println("MOTD (clean): " + bedrockStatus.getMotdClean());
System.out.println("MOTD (HTML): " + bedrockStatus.getMotdHtml());
// Additional Bedrock-specific information
System.out.println("Gamemode: " + bedrockStatus.getGamemode());
System.out.println("Server ID: " + bedrockStatus.getServerId());
System.out.println("Edition: " + bedrockStatus.getEdition());
} else {
System.out.println("The server is not online.");
}
} catch (Exception e) {
System.out.println("An error occurred while retrieving the Bedrock server status: " + e.getMessage());
e.printStackTrace();
}
}
}
Notes
Ensure the server address is valid and reachable.
The API request may fail if the server is offline or the address is incorrect.
The
timeout
parameter in the constructor is optional and defaults to5.0
seconds if not provided.
Last updated