Giter Club home page Giter Club logo

minecraft-server-pinger's Introduction

Minecraft Server Pinger

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

Maven dependency

<repository>
    <id>nurio-repo</id>
    <url>https://nurio.me/repo/mvn/</url>
</repository>
<dependency>
    <groupId>me.nurio.minecraft</groupId>
    <artifactId>pinger</artifactId>
    <version>0.0.3</version>
    <scope>compile</scope>
</dependency>

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:

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:

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.

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

minecraft-server-pinger's People

Contributors

dependabot[bot] avatar katakurinna avatar nuriofernandez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

minecraft-server-pinger's Issues

help, i'm new to java and I don't know what this means...

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at me.nurio.minecraft.pinger.MinecraftServerPinger.ping(MinecraftServerPinger.java:24)
at Sticky.main(Sticky.java:19)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.