62 lines
1.6 KiB
Java
62 lines
1.6 KiB
Java
package xyz.etztech.serverapi.web.api;
|
|
|
|
import com.expediagroup.graphql.annotations.GraphQLDescription;
|
|
import com.expediagroup.graphql.annotations.GraphQLName;
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import org.bukkit.Server;
|
|
|
|
@GraphQLName("Ping")
|
|
@GraphQLDescription("Ping GraphQL")
|
|
public class PingAPI {
|
|
private final String type;
|
|
private final String version;
|
|
private final String motd;
|
|
@JsonProperty("current_players")
|
|
private final int currentPlayers;
|
|
@JsonProperty("max_players")
|
|
private final int maxPlayers;
|
|
|
|
public PingAPI(String type, String version, String motd, int currentPlayers, int maxPlayers) {
|
|
this.type = type;
|
|
this.version = version;
|
|
this.motd = motd;
|
|
this.currentPlayers = currentPlayers;
|
|
this.maxPlayers = maxPlayers;
|
|
}
|
|
|
|
@GraphQLName("type")
|
|
public String getType() {
|
|
return type;
|
|
}
|
|
|
|
@GraphQLName("version")
|
|
public String getVersion() {
|
|
return version;
|
|
}
|
|
|
|
@GraphQLName("motd")
|
|
public String getMotd() {
|
|
return motd;
|
|
}
|
|
|
|
@GraphQLName("current_players")
|
|
public Integer getCurrentPlayers() {
|
|
return currentPlayers;
|
|
}
|
|
|
|
@GraphQLName("max_players")
|
|
public Integer getMaxPlayers() {
|
|
return maxPlayers;
|
|
}
|
|
|
|
public static PingAPI fromMinecraft(Server server) {
|
|
return new PingAPI(
|
|
server.getName(),
|
|
server.getBukkitVersion().split("-")[0], // 1.x.x-R0.1-SNAPSHOT
|
|
server.getMotd(),
|
|
server.getOnlinePlayers().size(),
|
|
server.getMaxPlayers()
|
|
);
|
|
}
|
|
}
|