From 1b6cdee6ed6503b9b3dad740f9efa1e60d87600b Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Sun, 19 Jul 2020 17:58:35 -0400 Subject: Move requests into API handler for future API commands --- me/Danker/commands/SlayerCommand.java | 44 ++++++----------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) (limited to 'me/Danker/commands/SlayerCommand.java') diff --git a/me/Danker/commands/SlayerCommand.java b/me/Danker/commands/SlayerCommand.java index ec23606..9fae3ef 100644 --- a/me/Danker/commands/SlayerCommand.java +++ b/me/Danker/commands/SlayerCommand.java @@ -55,51 +55,21 @@ public class SlayerCommand extends CommandBase { player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Checking slayer of " + username)); } else { username = arg1[0]; - String uuidURL = "https://api.mojang.com/users/profiles/minecraft/" + username; player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "Checking slayer of " + username)); - - JsonObject uuidResponse = ah.getResponse(uuidURL, player); - uuid = uuidResponse.get("id").getAsString(); + uuid = ah.getUUID(username); } - // Get profiles - System.out.println("Fetching profiles..."); - String profilesURL = "https://api.hypixel.net/skyblock/profiles?uuid=" + uuid + "&key=" + key; - - JsonObject profilesResponse = ah.getResponse(profilesURL, player); - if (!profilesResponse.get("success").getAsBoolean()) { - String reason = profilesResponse.get("cause").getAsString(); - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Failed with reason: " + reason)); - return; - } - if (profilesResponse.get("profiles").isJsonNull()) { - player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This player doesn't appear to have played SkyBlock.")); + // Find stats of latest profile + String latestProfile = ah.getLatestProfileID(uuid, key); + if (latestProfile == null) { return; } - // Loop through profiles to find latest - System.out.println("Looping through profiles..."); - String latestProfile = ""; - int latestSave = 0; - JsonArray profilesArray = profilesResponse.get("profiles").getAsJsonArray(); - - for (JsonElement profile : profilesArray) { - JsonObject profileJSON = profile.getAsJsonObject(); - int profileLastSave = profileJSON.get("members").getAsJsonObject().get(uuid).getAsJsonObject().get("last_save").getAsInt(); - - if (profileLastSave > latestSave) { - latestProfile = profileJSON.get("profile_id").getAsString(); - latestSave = profileLastSave; - } - } - - // Find stats of latest profile - System.out.println("Fetching profile..."); String profileURL = "https://api.hypixel.net/skyblock/profile?profile=" + latestProfile + "&key=" + key; - - JsonObject profileResponse = ah.getResponse(profileURL, player); + System.out.println("Fetching profile..."); + JsonObject profileResponse = ah.getResponse(profileURL); if (!profileResponse.get("success").getAsBoolean()) { - String reason = profilesResponse.get("cause").getAsString(); + String reason = profileResponse.get("cause").getAsString(); player.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Failed with reason: " + reason)); return; } -- cgit