diff options
author | bowser0000 <bowser0000@gmail.com> | 2020-07-23 17:13:07 -0400 |
---|---|---|
committer | bowser0000 <bowser0000@gmail.com> | 2020-07-23 17:13:07 -0400 |
commit | 286f10b9dfd86ebb336ffc18b76935d32c943158 (patch) | |
tree | 34945d81aca521cc505a19e5a789102a064fb331 | |
parent | 70fd715a1fdb2bf01d130d27be0be89189072a26 (diff) | |
download | SkyblockMod-286f10b9dfd86ebb336ffc18b76935d32c943158.tar.gz SkyblockMod-286f10b9dfd86ebb336ffc18b76935d32c943158.tar.bz2 SkyblockMod-286f10b9dfd86ebb336ffc18b76935d32c943158.zip |
Sort pets by xp
-rw-r--r-- | me/Danker/commands/PetsCommand.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/me/Danker/commands/PetsCommand.java b/me/Danker/commands/PetsCommand.java index c9c1af7..1ffdd77 100644 --- a/me/Danker/commands/PetsCommand.java +++ b/me/Danker/commands/PetsCommand.java @@ -1,6 +1,7 @@ package me.Danker.commands; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import com.google.gson.JsonArray; @@ -116,14 +117,27 @@ public class PetsCommand extends CommandBase { } System.out.println("Looping through pets..."); + // Push each pet into list + List<JsonElement> sortedPets = new ArrayList<JsonElement>(); + for (JsonElement petElement : petsArray) { + sortedPets.add(petElement); + } + // Sort pets by exp + Collections.sort(sortedPets, (pet1, pet2) -> { + double petXp1 = pet1.getAsJsonObject().get("exp").getAsDouble(); + double petXp2 = pet2.getAsJsonObject().get("exp").getAsDouble(); + return -Double.compare(petXp1, petXp2); + }); + + // Sort pets into rarities List<JsonObject> commonPets = new ArrayList<JsonObject>(); List<JsonObject> uncommonPets = new ArrayList<JsonObject>(); List<JsonObject> rarePets = new ArrayList<JsonObject>(); List<JsonObject> epicPets = new ArrayList<JsonObject>(); List<JsonObject> legendaryPets = new ArrayList<JsonObject>(); - for (JsonElement petElement : petsArray) { + for (JsonElement petElement : sortedPets) { JsonObject pet = petElement.getAsJsonObject(); String rarity = pet.get("tier").getAsString(); |