Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/nuriofernandez/minecraft-server-pinger
- Owner: nuriofernandez
- License: mit
- Created: 2020-04-21T05:45:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-28T08:37:38.000Z (over 3 years ago)
- Last Synced: 2024-01-03T14:36:02.398Z (10 months ago)
- Topics: bukkit-server, bungeecord, handshake, minecraft, minecraft-api, minecraft-server-ping, minecraft-server-pinger, minecraft-servers, pinger, spigot-server
- Language: Java
- Size: 34.2 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
```