diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index 7d501f2..710f5cd 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -14,10 +14,7 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import net.frozenorb.apiv3.actors.ActorType; import net.frozenorb.apiv3.filters.*; -import net.frozenorb.apiv3.models.Grant; -import net.frozenorb.apiv3.models.IPLogEntry; -import net.frozenorb.apiv3.models.Punishment; -import net.frozenorb.apiv3.models.User; +import net.frozenorb.apiv3.models.*; import net.frozenorb.apiv3.routes.GETDump; import net.frozenorb.apiv3.routes.GETWhoAmI; import net.frozenorb.apiv3.routes.NotFound; @@ -48,6 +45,7 @@ import net.frozenorb.apiv3.serialization.ObjectIdTypeAdapter; import net.frozenorb.apiv3.unsorted.BugsnagSLF4JLogger; import net.frozenorb.apiv3.unsorted.LoggingExceptionHandler; import net.frozenorb.apiv3.utils.IPUtils; +import net.frozenorb.apiv3.utils.PermissionUtils; import net.frozenorb.apiv3.utils.UUIDUtils; import org.bson.Document; import org.bson.types.ObjectId; diff --git a/src/main/java/net/frozenorb/apiv3/models/Rank.java b/src/main/java/net/frozenorb/apiv3/models/Rank.java index 08a6de2..dd036d4 100644 --- a/src/main/java/net/frozenorb/apiv3/models/Rank.java +++ b/src/main/java/net/frozenorb/apiv3/models/Rank.java @@ -7,15 +7,14 @@ import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Id; import org.mongodb.morphia.annotations.Indexed; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.TimeUnit; @Entity(value = "ranks", noClassnameStored = true) public final class Rank { private static Map rankCache = null; + private static List sortedRankCache = null; private static long rankCacheUpdated = 0; @Getter @Id private String id; @@ -32,7 +31,7 @@ public final class Rank { public static List values() { updateCacheIfNeeded(); - return ImmutableList.copyOf(rankCache.values()); + return ImmutableList.copyOf(sortedRankCache); } public Rank() {} // For Morphia @@ -53,12 +52,15 @@ public final class Rank { private static void updateCacheIfNeeded() { if (rankCache == null || (System.currentTimeMillis() - rankCacheUpdated) > TimeUnit.MINUTES.toMillis(1)) { Map working = new HashMap<>(); + List workingSorted = new ArrayList<>(); for (Rank rank : APIv3.getDatastore().createQuery(Rank.class).order("weight").asList()) { working.put(rank.getId(), rank); + workingSorted.add(rank); } rankCache = working; + sortedRankCache = workingSorted; rankCacheUpdated = System.currentTimeMillis(); } } diff --git a/src/main/java/net/frozenorb/apiv3/models/Server.java b/src/main/java/net/frozenorb/apiv3/models/Server.java index 131836c..bfecf8e 100644 --- a/src/main/java/net/frozenorb/apiv3/models/Server.java +++ b/src/main/java/net/frozenorb/apiv3/models/Server.java @@ -14,7 +14,6 @@ import java.util.*; 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 serverGroup; @@ -33,9 +32,8 @@ public final class Server { public Server() {} // For Morphia - public Server(String id, String bungeeId, String displayName, String apiKey, ServerGroup serverGroup, String serverIp) { + public Server(String id, String displayName, String apiKey, ServerGroup serverGroup, String serverIp) { this.id = id; - this.bungeeId = bungeeId; this.displayName = displayName; this.apiKey = apiKey; this.serverGroup = serverGroup.getId(); diff --git a/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServer.java b/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServer.java index c77e90c..8a41865 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServer.java +++ b/src/main/java/net/frozenorb/apiv3/routes/servers/POSTServer.java @@ -13,7 +13,6 @@ public final class POSTServer implements Route { public Object handle(Request req, Response res) { String id = req.queryParams("id"); - String bungeeId = req.queryParams("bungeeId"); String displayName = req.queryParams("displayName"); String apiKey = req.queryParams("apiKey"); ServerGroup group = ServerGroup.byId(req.queryParams("group")); @@ -27,7 +26,7 @@ public final class POSTServer implements Route { return ErrorUtils.invalidInput("IP address \"" + ip + "\" is not valid."); } - Server server = new Server(id, bungeeId, displayName, apiKey, group, ip); + Server server = new Server(id, displayName, apiKey, group, ip); APIv3.getDatastore().save(server); return server; } diff --git a/src/main/java/net/frozenorb/apiv3/utils/ErrorUtils.java b/src/main/java/net/frozenorb/apiv3/utils/ErrorUtils.java index dcfb3bb..e0b4c83 100644 --- a/src/main/java/net/frozenorb/apiv3/utils/ErrorUtils.java +++ b/src/main/java/net/frozenorb/apiv3/utils/ErrorUtils.java @@ -15,7 +15,7 @@ public class ErrorUtils { public static Map notFound(String itemType, String id) { return error("Not found: " + itemType + " with id " + id + " cannot be found."); } - + public static Map invalidInput(String message) { return error("Invalid input: " + message); }