2016-02-12 02:40:06 +01:00
|
|
|
package net.frozenorb.apiv3.model;
|
2016-02-06 02:58:49 +01:00
|
|
|
|
|
|
|
import lombok.Getter;
|
2016-02-08 00:03:42 +01:00
|
|
|
import lombok.ToString;
|
2016-02-12 01:10:46 +01:00
|
|
|
import net.frozenorb.apiv3.APIv3;
|
2016-02-08 02:54:27 +01:00
|
|
|
import net.frozenorb.apiv3.LiteFullJson;
|
2016-02-12 02:40:06 +01:00
|
|
|
import net.frozenorb.apiv3.accessor.Servers;
|
2016-02-12 01:10:46 +01:00
|
|
|
import org.bson.Document;
|
2016-02-06 02:58:49 +01:00
|
|
|
|
2016-02-08 00:03:42 +01:00
|
|
|
import java.time.Instant;
|
2016-02-12 01:10:46 +01:00
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
2016-02-06 02:58:49 +01:00
|
|
|
|
2016-02-12 02:40:06 +01:00
|
|
|
@ToString
|
2016-02-08 02:54:27 +01:00
|
|
|
public final class Server implements LiteFullJson {
|
2016-02-08 00:03:42 +01:00
|
|
|
|
2016-02-06 02:58:49 +01:00
|
|
|
@Getter private String id;
|
2016-02-08 00:03:42 +01:00
|
|
|
@Getter private String bungeeId;
|
|
|
|
@Getter private String displayName;
|
|
|
|
@Getter private String secret;
|
|
|
|
@Getter private String group;
|
|
|
|
@Getter private String internalIp;
|
|
|
|
@Getter private Instant lastUpdate;
|
|
|
|
@Getter private double lastTps;
|
|
|
|
@Getter private List<UUID> players;
|
|
|
|
|
2016-02-12 02:40:06 +01:00
|
|
|
public Server(Document json) {
|
2016-02-08 00:03:42 +01:00
|
|
|
this.id = json.getString("_id");
|
|
|
|
this.bungeeId = json.getString("bungeeId");
|
|
|
|
this.displayName = json.getString("displayName");
|
|
|
|
this.secret = json.getString("secret");
|
|
|
|
this.group = json.getString("group");
|
|
|
|
this.internalIp = json.getString("internalIp");
|
2016-02-12 02:40:06 +01:00
|
|
|
this.lastUpdate = (Instant) json.get("lastUpdate");
|
|
|
|
this.lastTps = ((Number) json.get("lastTps")).doubleValue();
|
2016-02-08 00:03:42 +01:00
|
|
|
this.players = new ArrayList<>();
|
|
|
|
|
2016-02-12 02:40:06 +01:00
|
|
|
for (Object uuidString : (Collection) json.get("players")) {
|
2016-02-08 00:03:42 +01:00
|
|
|
players.add(UUID.fromString((String) uuidString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:10:46 +01:00
|
|
|
public void update() {
|
2016-02-12 02:40:06 +01:00
|
|
|
APIv3.getMongo().getCollection(Servers.COLLECTION_NAME).updateOne(new Document("_id", id), new Document("$set", new Document("lastUpdate", new Date())), (result, error) -> {});
|
2016-02-12 01:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Document toLiteJson() {
|
|
|
|
Document json = new Document();
|
2016-02-08 00:03:42 +01:00
|
|
|
|
2016-02-12 02:40:06 +01:00
|
|
|
json.put("id", id);
|
2016-02-08 00:03:42 +01:00
|
|
|
json.put("bungeeId", bungeeId);
|
|
|
|
json.put("displayName", displayName);
|
|
|
|
json.put("group", group);
|
|
|
|
json.put("internalIp", internalIp);
|
|
|
|
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:10:46 +01:00
|
|
|
public Document toFullJson() {
|
|
|
|
Document json = toLiteJson();
|
2016-02-08 00:03:42 +01:00
|
|
|
|
2016-02-12 01:10:46 +01:00
|
|
|
json.put("lastUpdate", lastUpdate.toString());
|
2016-02-08 00:03:42 +01:00
|
|
|
json.put("lastTps", lastTps);
|
2016-02-12 01:10:46 +01:00
|
|
|
json.put("players", players.stream().map(UUID::toString).collect(Collectors.toList()));
|
2016-02-06 02:58:49 +01:00
|
|
|
|
2016-02-08 00:03:42 +01:00
|
|
|
return json;
|
2016-02-06 02:58:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|