Package ch.andre601.fluxpoint4j.mc
Class MCRequestBuilder
- java.lang.Object
-
- ch.andre601.fluxpoint4j.mc.MCRequestBuilder
-
public class MCRequestBuilder extends java.lang.Object
Builder class to set up a new request to the Fluxpoint API for the MC Server API.This class allows you to
set a host
,set a port
andif icon should be included
.
-
-
Constructor Summary
Constructors Constructor Description MCRequestBuilder(java.lang.String token, ch.andre601.fluxpoint4j.request.RequestHandler handler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GenericAPIResponse
performRequest()
Performs a request towards the Fluxpoint API to check a MC server and receive possible information from it.java.util.concurrent.CompletableFuture<GenericAPIResponse>
queueRequest()
Performs a request towards the Fluxpoint API to check a MC server and receive possible information from it and wraps it into aCompletableFuture
for you to handle.MCRequestBuilder
withHost(@NotNull java.lang.String host)
Sets the domain/IP that should be pinged by the API.MCRequestBuilder
withIcon(boolean withIcon)
Sets whether the FluxpointAPI should also include the Server's icon in its response.MCRequestBuilder
withPort(int port)
Sets the port that should be pinged.
-
-
-
Method Detail
-
withHost
public MCRequestBuilder withHost(@NotNull @NotNull java.lang.String host)
Sets the domain/IP that should be pinged by the API. Cannot be null or empty.- Parameters:
host
- The domain/IP to ping.- Returns:
- This builder after the host has been set. Useful for chaining.
-
withPort
public MCRequestBuilder withPort(int port)
Sets the port that should be pinged. Default is 25565 and the provided number cannot be negative.- Parameters:
port
- The port to ping.- Returns:
- This builder after the port has been set. Useful for chaining.
-
withIcon
public MCRequestBuilder withIcon(boolean withIcon)
Sets whether the FluxpointAPI should also include the Server's icon in its response.
The returned icon is accessible throughMCServerPing's getIcon()
method and is a Base64-encoded String of the icon.- Parameters:
withIcon
- Whether the server icon should be included or not.- Returns:
- This builder after the boolean has been set. Useful for chaining.
-
performRequest
public GenericAPIResponse performRequest()
Performs a request towards the Fluxpoint API to check a MC server and receive possible information from it.The returned
GenericAPIResponse
can be onw of two instances:- Instance of
MCServerPingResponse
on a successful request. - Instance of
FailedAPIResponse
on a failed request.
instanceof
calls where necessary:GenericAPIResponse response = api.getMCRequestBuilder().withHost("example.com").performRequest(); // Direct cast in if-block only usable in newer Java versions if(response instanceof FailedAPIResponse failedResponse){ System.out.println("Request not successful!"); System.out.println("Received Code: " + failedResponse.getCode()); System.out.println("Received Message: " + failedResponse.getMessage()); return; } // The request wasn't a failed one, so cast should be safe here. MCServerPingResponse mcResponse = (MCServerPingResponse)response;
An
IllegalArgumentException
may be thrown in the following cases:- Returns:
- A
GenericAPIResponse
after a request has been made.
- Instance of
-
queueRequest
public java.util.concurrent.CompletableFuture<GenericAPIResponse> queueRequest()
Performs a request towards the Fluxpoint API to check a MC server and receive possible information from it and wraps it into aCompletableFuture
for you to handle.The returned
GenericAPIResponse
can be one of two instances:- Instance of
MCServerPingResponse
on a successful request. - Instance of
FailedAPIResponse
on a failed request.
instanceof
calls where necessary:CompletableFuture<GenericAPIResponse> future = api.getMCRequestBuilder().withHost("example.com").queueRequest(); future.whenComplete((response, throwable) -> { if(throwable != null){ System.out.println("Encountered Exception: " + throwable.getMessage()); return; } // Direct cast in if-block only usable in newer Java versions if(response instanceof FailedAPIResponse failedResponse){ System.out.println("Request not successful!"); System.out.println("Received Code: " + failedResponse.getCode()); System.out.println("Received Message: " + failedResponse.getMessage()); return; } // The request wasn't a failed one, so cast should be safe here. MCServerPingResponse mcResponse = (MCServerPingResponse)response; }
An
IllegalArgumentException
may be thrown in the following cases:- Returns:
- A
GenericAPIResponse
after a request has been made.
- Instance of
-
-