⚒️
MCStatusIO
  • Overview
  • Class Documentation: JavaStatus
  • Class Documentation: BedrockStatus
  • Class Documentation: Icon
  • License
Powered by GitBook
On this page
  • Class Overview
  • Methods
  • Usage Example
  • Notes

Class Documentation: Icon

PreviousClass Documentation: BedrockStatus

Last updated 4 months ago

The Icon class is a Java utility for retrieving the server icon of a Minecraft Java Edition server using the . It provides methods to fetch the server icon as a BufferedImage or as a URL.


Class Overview

Package

package io.github.undeffineddev.mcstatusio.java.icon;

Class Declaration

public class Icon

Methods

getServerIcon(String address)

Retrieves the server icon as a BufferedImage with a default timeout of 5 seconds.

Parameters:

  • address (String): The server address (e.g., "example.com" or "192.168.1.1:25565").

Returns:

  • BufferedImage: The server icon as a BufferedImage, or null if an error occurs.


getServerIcon(String address, double timeout)

Retrieves the server icon as a BufferedImage with a specified timeout.

Parameters:

  • address (String): The server address.

  • timeout (double, optional): The timeout in seconds for the API request. Defaults to 5.0 if not provided.

Returns:

  • BufferedImage: The server icon as a BufferedImage, or null if an error occurs.


getServerIconAsLink(String address)

Retrieves the URL of the server icon with a default timeout of 5 seconds.

Parameters:

  • address (String): The server address.

Returns:

  • String: The URL of the server icon.


getServerIconAsLink(String address, double timeout)

Retrieves the URL of the server icon with a specified timeout.

Parameters:

  • address (String): The server address.

  • timeout (double, optional): The timeout in seconds for the API request. Defaults to 5.0 if not provided.

Returns:

  • String: The URL of the server icon.


Usage Example

Example 1: Fetching the Server Icon as a BufferedImage

import io.github.undeffineddev.mcstatusio.java.icon.Icon;
import java.awt.image.BufferedImage;

public class Main {
    public static void main(String[] args) {
        // Fetch the server icon as a BufferedImage
        BufferedImage icon = Icon.getServerIcon("example.com:25565");

        if (icon != null) {
            System.out.println("Server icon successfully retrieved!");
            // You can now use the BufferedImage (e.g., display it in a GUI).
        } else {
            System.err.println("Failed to retrieve the server icon.");
        }
    }
}

Example 2: Fetching the Server Icon URL

import io.github.undeffineddev.mcstatusio.java.icon.Icon;

public class Main {
    public static void main(String[] args) {
        // Fetch the server icon URL
        String iconUrl = Icon.getServerIconAsLink("example.com:25565");

        System.out.println("Server icon URL: " + iconUrl);
        // You can use this URL to download or display the icon.
    }
}

Example 3: Using a Custom Timeout

import io.github.undeffineddev.mcstatusio.java.icon.Icon;
import java.awt.image.BufferedImage;

public class Main {
    public static void main(String[] args) {
        // Fetch the server icon with a custom timeout (10 seconds)
        BufferedImage icon = Icon.getServerIcon("example.com:25565", 10.0);

        if (icon != null) {
            System.out.println("Server icon successfully retrieved!");
        } else {
            System.err.println("Failed to retrieve the server icon.");
        }
    }
}

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 methods is optional and defaults to 5.0 seconds if not provided.

mcstatus.io API