package net.frozenorb.apiv3.models; import lombok.Getter; import lombok.Setter; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.serialization.ExcludeFromReplies; import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Id; import org.mongodb.morphia.annotations.Indexed; import java.util.*; @Entity(value = "servers", noClassnameStored = true) public final class Server { @Getter @Id private String id; @Getter private String displayName; @Getter @ExcludeFromReplies String apiKey; @Getter @Indexed private String serverGroup; @Getter private String serverIp; @Getter @Setter private Date lastUpdatedAt; @Getter @Setter private double lastTps; @Getter @Setter @ExcludeFromReplies private Set players; public static Server byId(String id) { return APIv3.getDatastore().createQuery(Server.class).field("_id").equal(id).get(); } public static List values() { return APIv3.getDatastore().createQuery(Server.class).asList(); } public Server() {} // For Morphia public Server(String id, String displayName, String apiKey, ServerGroup serverGroup, String serverIp) { this.id = id; this.displayName = displayName; this.apiKey = apiKey; this.serverGroup = serverGroup.getId(); this.serverIp = serverIp; this.lastUpdatedAt = new Date(); this.lastTps = 0; this.players = new HashSet<>(); } public void delete() { APIv3.getDatastore().delete(this); } }