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

52 lines
1.6 KiB
Java
Raw Normal View History

2016-04-08 13:12:31 +02:00
package net.frozenorb.apiv3.models;
2016-02-06 02:58:49 +01:00
import lombok.Getter;
2016-04-30 20:03:34 +02:00
import lombok.Setter;
2016-03-21 23:28:17 +01:00
import net.frozenorb.apiv3.APIv3;
2016-05-01 06:34:02 +02:00
import net.frozenorb.apiv3.serialization.ExcludeFromReplies;
2016-03-21 23:28:17 +01:00
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
2016-05-03 01:34:30 +02:00
import org.mongodb.morphia.annotations.Indexed;
2016-02-06 02:58:49 +01:00
2016-04-27 02:46:34 +02: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-04-08 13:12:31 +02:00
@Getter @Id private String id;
2016-02-08 00:03:42 +01:00
@Getter private String bungeeId;
@Getter private String displayName;
2016-05-01 06:34:02 +02:00
@Getter @ExcludeFromReplies String apiKey;
2016-05-11 00:37:07 +02:00
@Getter @Indexed private String serverGroup;
2016-05-10 18:30:21 +02:00
@Getter private String serverIp;
2016-05-11 00:37:07 +02:00
@Getter @Setter private Date lastUpdatedAt;
2016-04-30 20:03:34 +02:00
@Getter @Setter private double lastTps;
2016-05-01 06:34:02 +02:00
@Getter @Setter @ExcludeFromReplies 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) {
2016-05-01 06:34:02 +02:00
return APIv3.getDatastore().createQuery(Server.class).field("_id").equal(id).get();
2016-02-08 00:03:42 +01:00
}
2016-04-27 02:46:34 +02:00
public static List<Server> values() {
return APIv3.getDatastore().createQuery(Server.class).asList();
}
2016-03-21 23:28:17 +01:00
public Server() {} // For Morphia
2016-05-11 00:37:07 +02:00
public Server(String id, String bungeeId, String displayName, String apiKey, ServerGroup serverGroup, String serverIp) {
2016-03-21 23:28:17 +01:00
this.id = id;
this.bungeeId = bungeeId;
this.displayName = displayName;
2016-05-01 02:08:58 +02:00
this.apiKey = apiKey;
2016-05-11 00:37:07 +02:00
this.serverGroup = serverGroup.getId();
2016-05-10 18:30:21 +02:00
this.serverIp = serverIp;
2016-05-11 00:37:07 +02:00
this.lastUpdatedAt = new Date();
2016-03-21 23:28:17 +01:00
this.lastTps = 0;
this.players = new HashSet<>();
2016-02-08 00:03:42 +01:00
}
2016-05-01 02:20:12 +02:00
public void delete() {
APIv3.getDatastore().delete(this);
}
2016-02-06 02:58:49 +01:00
}