Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nuriofernandez/minecraft-server-pinger

Minecraft server pinger obtains information such as the MOTD of minecraft servers.
https://github.com/nuriofernandez/minecraft-server-pinger

bukkit-server bungeecord handshake minecraft minecraft-api minecraft-server-ping minecraft-server-pinger minecraft-servers pinger spigot-server

Last synced: 2 days ago
JSON representation

Minecraft server pinger obtains information such as the MOTD of minecraft servers.

Awesome Lists containing this project

README

        

# Minecraft Server Pinger
Minecraft server pinger library obtains information such as the MOTD of minecraft servers.

# Maven dependency

```xml

nurio-repo
https://nurio.me/repo/mvn/

```

```xml

me.nurio.minecraft
pinger
0.0.3
compile

```

# How to use the server pinger

The `MinecraftServerPinger` class it's very easy to use, it will manage everything for you, SRV domain resolve, offline check, getting server's data, connection timeout management...

Here is an example for you:

```java
MinecraftServerStatus server = MinecraftServerPinger.ping("serveradress.com:25544");
// In case the server is not online:
if(server.isOffline()) {
System.out.println("Minecraft server 'serveradress.com' is not online!");

// You can get the server connection exception like that:
OfflineMinecraftServerStatus offlineServer = (OfflineMinecraftServerStatus) server;
offlineServer.getException().printStackTrace();
return;
}

// These methods will throw an exceptions in case the server is not online.
String motd = server.getMotd();
long latency = server.getPing();
Version version = server.getVersion();
Players players = server.getPlayers();
String base64Favicon = server.getFavicon();
```

# Additional utilities

## Advanced server query mode

If you want to have a little more control of this process you can use the `MinecraftServerConnection` class.
You will need to provide a `InetSocketAddress` and optionally a connection timeout time in milliseconds.

Here is an example:

```java
InetSocketAddress socketAddress = new InetSocketAddress("serveradress.com", 25565);

MinecraftServerConnection connection = new MinecraftServerConnection(socketAddress);
connection.setTimeout(5000); // Optional timeout (default was 1000ms)
MinecraftServerStatus server = connection.fetchData();

// Here you can continue as the first example. (isOffline(), getMotd()...)
```

## SRVResolver resolver

Some minecraft servers uses SRV domain records to manage server's port.
With the SRVResolver utility class, you can obtian the server real domain and port.

```java
InetSocketAddress address = SRVResolver.getSocketAddress(serverAddress);
String serverAddress = address.getHostName();
int serverPort = address.getPort();
```