APIv3/src/main/java/net/frozenorb/apiv3/model/Server.java

48 lines
1.3 KiB
Java
Raw Normal View History

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-03-21 23:28:17 +01:00
import net.frozenorb.apiv3.APIv3;
2016-02-12 01:10:46 +01:00
import org.bson.Document;
2016-03-21 23:28:17 +01:00
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
2016-02-06 02:58:49 +01:00
2016-03-21 23:28:17 +01:00
import java.lang.annotation.Documented;
2016-02-08 00:03:42 +01:00
import java.time.Instant;
2016-03-21 23:28:17 +01:00
import java.util.*;
2016-02-06 02:58:49 +01:00
2016-03-21 23:28:17 +01:00
@Entity(value = "servers", noClassnameStored = true)
public final class Server {
2016-02-08 00:03:42 +01:00
2016-03-21 23:28:17 +01:00
@Id 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;
2016-02-23 13:14:42 +01:00
@Getter private String ip;
2016-03-21 23:28:17 +01:00
@Getter private Date lastUpdate;
2016-02-08 00:03:42 +01:00
@Getter private double lastTps;
2016-03-21 23:28:17 +01:00
@Getter private Set<UUID> players;
2016-02-08 00:03:42 +01:00
2016-03-21 23:28:17 +01:00
public static Server byId(String id) {
return APIv3.getDatastore().createQuery(Server.class).field("id").equal(id).get();
2016-02-08 00:03:42 +01:00
}
2016-03-21 23:28:17 +01:00
public Server() {} // For Morphia
public Server(String id, String bungeeId, String displayName, String secret, String group, String ip) {
this.id = id;
this.bungeeId = bungeeId;
this.displayName = displayName;
this.secret = secret;
this.group = group;
this.ip = ip;
this.lastUpdate = new Date();
this.lastTps = 0;
this.players = new HashSet<>();
2016-02-08 00:03:42 +01:00
}
2016-03-21 23:28:17 +01:00
public ServerGroup resolveGroup() {
return ServerGroup.byId(group);
2016-02-06 02:58:49 +01:00
}
}