net.lenni0451.mcping.responses.IPingResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of MCPing Show documentation
Show all versions of MCPing Show documentation
A simple library to ping minecraft servers
The newest version!
package net.lenni0451.mcping.responses;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
/**
* Marker interface for all possible ping responses.
* Some methods exist for common values, but not all responses have all values.
*/
public interface IPingResponse {
/**
* Get the address of the server.
*
* Implemented: {@link MCPingResponse}, {@link ClassicPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}, {@link SocketPingResponse}
* Default: {@code "Unknown"}
*
* @return The address
*/
@Nonnull
default String getAddress() {
return "Unknown";
}
/**
* Get the port of the server.
*
* Implemented: {@link MCPingResponse}, {@link ClassicPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}, {@link SocketPingResponse}
* Default: {@code -1}
*
* @return The port
*/
default int getPort() {
return -1;
}
/**
* Get the MOTD of the server.
* The MOTD can be a text component but is not guaranteed to be one.
*
* Implemented: {@link MCPingResponse}, {@link ClassicPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}
* Default: {@code "Unknown"}
*
* @return The MOTD
*/
@Nonnull
default String getMotd() {
return "Unknown";
}
/**
* Get the favicon of the server.
* The favicon is a base64 encoded png image. The server can send any string here, so it is not guaranteed to be a valid image.
*
* Implemented: {@link MCPingResponse}
* Default: {@code null}
*
* @return The favicon
*/
@Nullable
default String getFavicon() {
return null;
}
/**
* Get the ping to the server in milliseconds.
*
* Implemented: {@link MCPingResponse}, {@link ClassicPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}, {@link SocketPingResponse}
* Default: {@code -1}
*
* @return The ping
*/
default long getPing() {
return -1;
}
/**
* Get the amount of players currently online on the server.
*
* Implemented: {@link MCPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}
* Default: {@code -1}
*
* @return The amount of players
*/
default int getOnlinePlayers() {
return -1;
}
/**
* Get the maximum amount of players that can be online on the server.
*
* Implemented: {@link MCPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}
* Default: {@code -1}
*
* @return The maximum amount of players
*/
default int getMaxPlayers() {
return -1;
}
/**
* Get the version name of the server.
*
* Implemented: {@link MCPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}
* Default: {@code "Unknown"}
*
* @return The version name
*/
@Nonnull
default String getVersionName() {
return "Unknown";
}
/**
* Get the protocol id of the server.
*
* Implemented: {@link MCPingResponse}, {@link ClassicPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}
* Default: {@code -1}
*
* @return The protocol id
*/
default int getProtocolId() {
return -1;
}
/**
* Get a sample of players on the server.
* The server can send any list of strings here, so it is not guaranteed to be valid player names.
* Some implementations may return some general information about the server here (e.g. {@link BedrockPingResponse}).
* The list can be unmodifiable.
*
* Implemented: {@link MCPingResponse}, {@link BedrockPingResponse}, {@link QueryPingResponse}
*
* @return The sample players
*/
@Nonnull
default List getSample() {
return Collections.emptyList();
}
}