Package dev.redcoke.mcserverping
Class MCServerPing
- java.lang.Object
-
- dev.redcoke.mcserverping.MCServerPing
-
public final class MCServerPing extends Object
API for pinging and obtaining info about a Minecraft server.
-
-
Constructor Summary
Constructors Constructor Description MCServerPing()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull ServerPingResponsegetPing(String address)Pings a Minecraft Server to obtain server info.static @NotNull ServerPingResponsegetPing(String address, int port)Pings a Minecraft Server to obtain server info.static @NotNull ServerPingResponsegetPingWithTimeout(String address, int timeout)Pings a Minecraft server to obtain info with the custom timeout parameter.static ServerPingResponsegetPingWithTimeout(String address, int port, int timeout)Pings a Minecraft Server to obtain server info with a custom timeout parameter.static voidio(boolean b, String m)Throws IOException when condition is false.static intreadVarInt(DataInputStream in)Reads a VarInt from a DataInputStream.static voidwriteVarInt(DataOutputStream out, int inputParamInt)
-
-
-
Method Detail
-
getPingWithTimeout
@Contract("null, _ -> fail") @NotNull public static @NotNull ServerPingResponse getPingWithTimeout(String address, int timeout) throws IOException, TimeoutExceptionPings a Minecraft server to obtain info with the custom timeout parameter.- Parameters:
address- The address to pingtimeout- The timeout for the socket- Returns:
- The ping response.
- Throws:
IOException- For any i/o exception during the data exchange.TimeoutException- If the socket connection times out.
-
getPing
@Contract("null -> fail") @NotNull public static @NotNull ServerPingResponse getPing(String address) throws IOException, TimeoutExceptionPings a Minecraft Server to obtain server info.- Parameters:
address- server address- Returns:
- MCServerPingResponse
- Throws:
IOException- failed to resolve hostnameTimeoutException
-
getPing
@Contract("null, _ -> fail") @NotNull public static @NotNull ServerPingResponse getPing(String address, int port) throws IOException, TimeoutExceptionPings a Minecraft Server to obtain server info.- Parameters:
address- server addressport- server port- Returns:
- MCServerPingResponse server info
- Throws:
IOException- failed to resolve hostnameTimeoutException- when the server does not respond within 3 seconds- See Also:
ServerPingResponse
-
getPingWithTimeout
public static ServerPingResponse getPingWithTimeout(String address, int port, int timeout) throws IOException, TimeoutException
Pings a Minecraft Server to obtain server info with a custom timeout parameter.- Parameters:
address- server addressport- server porttimeout- The timeout for the socket- Returns:
- MCServerPingResponse server info
- Throws:
IOException- failed to resolve hostnameTimeoutException- when the server does not respond within 3 seconds- See Also:
ServerPingResponse
-
io
public static void io(boolean b, String m) throws IOExceptionThrows IOException when condition is false.- Parameters:
b- Conditionm- Exception cause- Throws:
IOException- Exception
-
readVarInt
public static int readVarInt(DataInputStream in) throws IOException, TimeoutException
Reads a VarInt from a DataInputStream.- Parameters:
in- DataInputStream- Returns:
- int
- Throws:
IOException- Failed to read VarInt or invalid VarIntTimeoutException- Timed out
-
writeVarInt
public static void writeVarInt(DataOutputStream out, int inputParamInt) throws IOException
- Throws:
IOException
-
-