package net.frozenorb.apiv3.models; import lombok.Getter; import net.frozenorb.apiv3.APIv3; import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Id; import java.util.*; @Entity(value = "servers", noClassnameStored = true) public final class Server { @Getter @Id private String id; @Getter private String bungeeId; @Getter private String displayName; @Getter private String secret; @Getter private String group; @Getter private String ip; @Getter private Date lastUpdate; @Getter private double lastTps; @Getter private Set players; public static Server byId(String id) { return APIv3.getDatastore().createQuery(Server.class).field("id").equalIgnoreCase(id).get(); } public static List values() { return APIv3.getDatastore().createQuery(Server.class).asList(); } public Server() {} // For Morphia public Server(String id, String bungeeId, String displayName, String secret, ServerGroup group, String ip) { this.id = id; this.bungeeId = bungeeId; this.displayName = displayName; this.secret = secret; this.group = group.getId(); this.ip = ip; this.lastUpdate = new Date(); this.lastTps = 0; this.players = new HashSet<>(); } public ServerGroup resolveGroup() { return ServerGroup.byId(group); } }