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 bungeeId; @Getter private String displayName; @Getter @ExcludeFromReplies String apiKey; @Getter @Indexed private String group; @Getter private String serverIp; @Getter @Setter private Date lastUpdate; @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 bungeeId, String displayName, String apiKey, ServerGroup group, String serverIp) { this.id = id; this.bungeeId = bungeeId; this.displayName = displayName; this.apiKey = apiKey; this.group = group.getId(); this.serverIp = serverIp; this.lastUpdate = new Date(); this.lastTps = 0; this.players = new HashSet<>(); } public void delete() { APIv3.getDatastore().delete(this); } }