Package ch.andre601.fluxpoint4j.mc
Class MCRequestBuilder
- java.lang.Object
-
- ch.andre601.fluxpoint4j.mc.MCRequestBuilder
-
public class MCRequestBuilder extends java.lang.ObjectBuilder 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 portandif 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 GenericAPIResponseperformRequest()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 aCompletableFuturefor you to handle.MCRequestBuilderwithHost(@NotNull java.lang.String host)Sets the domain/IP that should be pinged by the API.MCRequestBuilderwithIcon(boolean withIcon)Sets whether the FluxpointAPI should also include the Server's icon in its response.MCRequestBuilderwithPort(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
GenericAPIResponsecan be onw of two instances:- Instance of
MCServerPingResponseon a successful request. - Instance of
FailedAPIResponseon a failed request.
instanceofcalls 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
IllegalArgumentExceptionmay be thrown in the following cases:- Returns:
- A
GenericAPIResponseafter 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 aCompletableFuturefor you to handle.The returned
GenericAPIResponsecan be one of two instances:- Instance of
MCServerPingResponseon a successful request. - Instance of
FailedAPIResponseon a failed request.
instanceofcalls 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
IllegalArgumentExceptionmay be thrown in the following cases:- Returns:
- A
GenericAPIResponseafter a request has been made.
- Instance of
-
-