HomeJavaModsServerPingLib
ServerPingLib
I can't speak English. I'm using translation software. If you don't understand what I want to say, I'm sorry.

A brief introduction to the development of this API Library:


In the process of writing this plug-in, I intended to make it a API library, but in the end I made it work on BungeeCord, Spigot, and Bukkit servers (which may not be practical, but I did).

What does this API library do?

This API library can fake a network protocol and read the MOTD information of the MineCraft server with the specified IP address without passing through the MineCraft client.

List of functions of this API library:

API Classes and Methods:

studio.trc.minecraft.serverpinglib.API.MCServerSocket: Connection with server.
Spoiler: Methods
public String getIP()
public int getPort()
public boolean isOnline()
public boolean isSRVDomainName()
public MCServerStatus getStatus()
public MCServerStatus getStatus(ProtocolVersion version)
public Socket getSocket()
public void close()
public static MCServerSocket getInstance(String ip, int port, int timeout)
public static MCServerSocket getInstance(String ip, int port)

studio.trc.minecraft.serverpinglib.API.MCServerStatus: Get information about this server
Spoiler: Methods
public int getMaxPlayers()
public int getOnlinePlayers()
public int getServerProtocolNumber()
public int getProtocolNumber()
public long getPing()
public String getVersion()
public String getProtocolVersion()
public String getStringJson()
public MCServerModInfo getModInfo()
public MCServerMotd getMotd()
public MCServerSample getSample()
public MCServerIcon getIcon()
public boolean isMCServer()
public boolean supportVersion()
public static MCServerStatus getStatus(MCServerSocket mcsocket) throws SocketException
public static MCServerStatus getStatus(MCServerSocket mcsocket, ProtocolVersion version) throws SocketException


studio.trc.minecraft.serverpinglib.API.MCServerSample: Get the Server Samples
Spoiler: Methods
public List<SampleText> getSampleList()
public boolean hasSample()
Inner Class:
SampleText:
public String getID()
public String getName()
public String get(SampleEnum object)
public String getColorID()
public String getColorName()
public String getColor(SampleEnum object)


studio.trc.minecraft.serverpinglib.API.MCServerModInfo: Get the Server Mods
Spoiler: Methods
public boolean hasModInfo()
public boolean hasMod()
public String getModType()
public List<MCMod> getModList()
Inner Class:
MCMod:
public String getVersion()
public String getModId()

studio.trc.minecraft.serverpinglib.API.MCServerMotd: Get the Server MOTD information
Spoiler: Methods
public String getMotdText()
public String getColorMotdText()
public String getLine1MotdText()
public String getLine2MotdText()
public String getLine1ColorMotd()
public String getLine2ColorMotd()

studio.trc.minecraft.serverpinglib.API.MCServerIcon: Get the Server Icon
Spoiler: Methods
public void saveImageFile(File file)
public void saveImageFile(String path)
public boolean hasServerIcon()
public String getBase64Image()
public byte[] getImageBytes()


Spoiler: Sample code
Code (Text):

    public static void main(String[] args) {
        MCServerSocket socket = MCServerSocket.getInstance("mc.hypixel.net", 25565);
        if (socket == null) {
            System.out.println("Can't connect to server!");
            return;
        }
        MCServerStatus status = socket.getStatus(ProtocolVersion.v1_8_X);
        if (!status.isMCServer()) {
            System.out.println("This is not a MineCraft server.");
            return;
        }
        System.out.println("Server IP: " + socket.getIP() + ":" + socket.getPort());
        System.out.println("SRV domain name resolution: " + socket.isSRVDomainName());
        System.out.println("Server Version: " + status.getVersion());
        System.out.println("Your protocol number: " + status.getProtocolNumber());
        System.out.println("Target server protocol number: " + status.getServerProtocolNumber());
        System.out.println("Protocol Version: " + status.getProtocolVersion());
        System.out.println("Support this version: " + status.supportVersion());
        System.out.println("Max Online Players: " + status.getMaxPlayers());
        System.out.println("Now Online Players: " + status.getOnlinePlayers());
        if (status.getSample().hasSample()) {
            System.out.println("Sample: ");
            for (SampleText st : status.getSample().getSampleList()) {
                System.out.println(st.getName());
            }
        }
        System.out.println("MOTD: ");
        System.out.println(status.getMotd().getLine1MotdText());
        System.out.println(status.getMotd().getLine2MotdText());
        if (status.getIcon().hasServerIcon()) {
            status.getIcon().saveImageFile("D:/Test/Hypixel.png");
            System.out.println("Saved server Icon to D:/Test/Hypixel.png");
        }
        if (status.getModInfo().hasModInfo()) {
            if (status.getModInfo().hasMod()) {
                System.out.println("Mods");
                for (MCMod mods : status.getModInfo().getModList()) {
                    System.out.println(mods.getModId() + ", v" + mods.getVersion());
                }
            }
        }
    }
 

In the above code, mc.hypixel.net is the IP address of the famous server Hypixel. You can replace it with the IP address of other servers and get their information.
PS: It is recommended not to use the method of
MCServerSocket. getInstance(String ip, int port) in the main thread. If the target server connection takes too long, it may cause the main thread to be unresponsive for a long time or even cause other unnecessary consequences.

Spoiler: Output results
Server IP: mc.hypixel.net:25565
SRV domain name resolution: false
Server Version: Requires MC 1.8-1.14
Your protocol number: 47
Target server protocol number: 47
Protocol Version: 1.8.X
Support this version: true
Max Online Players: 76000
Now Online Players: 73223
MOTD:
Hypixel Network [1.8-1.14]
SKYBLOCK - SUMMER SALE UP TO 85% OFF
Saved server Icon to D:/Test/Hypixel.png

Save icons: (example):
example.png
Other classes:
ProtocolNumber: Number of Control Protocol
ProtocolVersion: Version Enumeration
ProtocolPacket: Protocol Packets for Reading Information
Encoding: Setting the encoding of the return stream

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

ServerPingLib is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 1,769 times (via Spigot). Download it and open it directly in the game.

Explore more