add ServerInfo DTO
This commit is contained in:
49
src/main/java/mc/protocol/dto/ServerInfo.java
Normal file
49
src/main/java/mc/protocol/dto/ServerInfo.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package mc.protocol.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonRawValue;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Data
|
||||
public class ServerInfo {
|
||||
|
||||
private Version version;
|
||||
|
||||
@JsonProperty("players")
|
||||
private PlayersInfo playersInfo;
|
||||
|
||||
//TODO необходимо реализовать объект типа Chat (см. https://wiki.vg/index.php?title=Chat&oldid=8329)
|
||||
private JsonNode description;
|
||||
|
||||
@JsonProperty("favicon")
|
||||
private String faviconBase64;
|
||||
|
||||
@Data
|
||||
public static class Version {
|
||||
private String name;
|
||||
private int protocol;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PlayersInfo {
|
||||
|
||||
private int max;
|
||||
|
||||
private int online;
|
||||
|
||||
@JsonProperty("sample")
|
||||
private List<SamplePlayer> samplePlayers;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SamplePlayer {
|
||||
private UUID id;
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package mc.protocol.status.server;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import mc.protocol.Packet;
|
||||
import mc.protocol.dto.ServerInfo;
|
||||
import mc.protocol.io.NetInputStream;
|
||||
import mc.protocol.io.NetOutputStream;
|
||||
|
||||
@@ -49,15 +52,41 @@ public class StatusServerResponse implements Packet {
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
private String info;
|
||||
private String serverInfo;
|
||||
|
||||
private ServerInfo serverInfoDto;
|
||||
|
||||
public ServerInfo getServerInfoDto() {
|
||||
if (serverInfoDto == null) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
serverInfoDto = mapper.readValue(serverInfo, ServerInfo.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return new ServerInfo();
|
||||
}
|
||||
}
|
||||
|
||||
return serverInfoDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSelf(NetInputStream netInputStream) {
|
||||
info = netInputStream.readString();
|
||||
serverInfo = netInputStream.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetOutputStream netOutputStream) {
|
||||
netOutputStream.writeString(info);
|
||||
if (serverInfo == null) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
serverInfo = mapper.writeValueAsString(serverInfoDto);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
serverInfo = "{}";
|
||||
}
|
||||
}
|
||||
|
||||
netOutputStream.writeString(serverInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user