aboutsummaryrefslogtreecommitdiff
path: root/me/Danker/commands/SlayerCommand.java
diff options
context:
space:
mode:
authorbowser0000 <bowser0000@gmail.com>2020-07-19 17:58:35 -0400
committerbowser0000 <bowser0000@gmail.com>2020-07-19 17:58:35 -0400
commit1b6cdee6ed6503b9b3dad740f9efa1e60d87600b (patch)
treeec4b4c0b4d8f306022546eede2d319be62c76e70 /me/Danker/commands/SlayerCommand.java
parentd1f260be47ea166e77b2e25cd07d6b08ec3e767d (diff)
downloadSkyblockMod-1b6cdee6ed6503b9b3dad740f9efa1e60d87600b.tar.gz
SkyblockMod-1b6cdee6ed6503b9b3dad740f9efa1e60d87600b.tar.bz2
SkyblockMod-1b6cdee6ed6503b9b3dad740f9efa1e60d87600b.zip
Move requests into API handler for future API commands
Diffstat (limited to 'me/Danker/commands/SlayerCommand.java')
-rw-r--r--me/Danker/commands/SlayerCommand.java44
1 files changed, 7 insertions, 37 deletions
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;
}