Class MCRequestBuilder

    • 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 a CompletableFuture 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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MCRequestBuilder

        public MCRequestBuilder​(java.lang.String token,
                                ch.andre601.fluxpoint4j.request.RequestHandler handler)
    • 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 through MCServerPing'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:

        Please make sure to check for the right instance using 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:

        • Host is null or empty.
        • Port is not a positive number.
        Returns:
        A GenericAPIResponse after a request has been made.
      • 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 a CompletableFuture for you to handle.

        The returned GenericAPIResponse can be one of two instances:

        Please make sure to check for the right instance using 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:

        • Host is null or empty.
        • Port is not a positive number.
        Returns:
        A GenericAPIResponse after a request has been made.