diff --git a/pom.xml b/pom.xml index f247203..0b1891b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,9 @@ jar JavaDestinyAPI - A Java wrapper for bungie.net platform api, allowing users to get data about the video games Destiny and Destiny 2 + A Java wrapper for bungie.net platform API, allowing users to get data about the video games Destiny and Destiny 2 https://github.com/dec4234/JavaDestinyAPI @@ -51,7 +50,7 @@ com.google.code.gson gson - 2.8.6 + 2.8.9 org.jetbrains @@ -62,7 +61,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.11.0 diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java new file mode 100644 index 0000000..d438167 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * Base class for all exceptions generated when an issue occurs in the request pipeline to Bungie. + * This most common reason for this error would be when the API is offline, and all objects are misparsed. + */ +public abstract class APIException extends Exception { + + public APIException() { + + } + + public APIException(String errorMessage) { + super(errorMessage); + } + + public APIException(Exception e) { + super(e); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java index 54b900f..2b4312c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.exceptions; @@ -11,7 +10,7 @@ /** * Indicates that the request returned error code 5 (The API has been disabled by Bungie) */ -public class APIOfflineException extends Exception { +public class APIOfflineException extends APIException { public APIOfflineException(String returnMessage) { super("The Bungie API returned this message: " + returnMessage); diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java new file mode 100644 index 0000000..d7b74fc --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * Self explanatory. The access token needs to be regenerated using the refresh token. + */ +public class AccessTokenExpiredException extends APIException{ +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java deleted file mode 100644 index 1bc06b9..0000000 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. - * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI - */ - -package net.dec4234.javadestinyapi.exceptions; - -/** - * Thrown whenever a 401 error is detected in the HTTP response - * This error indicates that the OAuth access token used by the request was not accepted by the server - */ -public class AccessTokenInvalidException extends Exception { - - public AccessTokenInvalidException() { - } - - public AccessTokenInvalidException(String message) { - super(message); - } -} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java new file mode 100644 index 0000000..2857f56 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +public class ConnectionException extends APIException { + + public ConnectionException(Exception exception) { + super(exception); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java new file mode 100644 index 0000000..e9d5735 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * When a token is missing or wrong, or some other pre-condition was not met that was needed to execute a request. + * This is a generic error, check the associated error message for more information. + */ +public class InvalidConditionException extends APIException { + + public InvalidConditionException(String message) { + super(message); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java new file mode 100644 index 0000000..0973f62 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +import com.google.gson.JsonSyntaxException; + +/** + * Malformed or non-json content found where JSON was expected. Usually at an API endpoint. + */ +public class JsonParsingError extends APIException { + + public JsonParsingError(String message) { + super(message); + } + + public JsonParsingError(JsonSyntaxException exception) { + super(exception); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java new file mode 100644 index 0000000..1680709 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * You either have insufficient permission to attempt this OAuth action, or you forgot to authorize yourself. + * Alternatively, the access and/or refresh token has expired + * See {@link net.dec4234.javadestinyapi.utils.framework.OAuthFlow} + */ +public class OAuthUnauthorizedException extends APIException { + + public OAuthUnauthorizedException(String message) { + super(message); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java new file mode 100644 index 0000000..a9af245 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * The name is self-expanatory. The refresh token normally used to generate a new access token has expired since it + * hasn't been refreshed in the past 90 days or it has been 1 year since the last oauth. + * See {@link net.dec4234.javadestinyapi.utils.framework.OAuthFlow} to generate a new one. + */ +public class RefreshTokenExpiredException extends APIException { + +} diff --git a/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java b/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java index 3db4218..acc590f 100644 --- a/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java +++ b/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.jdaSrc; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java b/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java index a0677d5..972eec8 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material; @@ -11,9 +10,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.clan.Clan; import net.dec4234.javadestinyapi.material.user.BungieUser; -import net.dec4234.javadestinyapi.material.user.DestinyPlatform; import net.dec4234.javadestinyapi.material.user.UserCredential; import net.dec4234.javadestinyapi.material.user.UserCredentialType; import net.dec4234.javadestinyapi.responses.user.SanitizedUsernamesResponse; @@ -132,7 +131,7 @@ public static BungieUser getUser(String id) { return new BungieUser(id); } - public static SanitizedUsernamesResponse getSanitizedUsernames(String id) { + public static SanitizedUsernamesResponse getSanitizedUsernames(String id) throws APIException { return new SanitizedUsernamesResponse(httpUtils.urlRequestGET(HttpUtils.URL_BASE + "/User/GetSanitizedPlatformDisplayNames/" + id + "/").getAsJsonObject("Response")); } @@ -140,7 +139,7 @@ public static SanitizedUsernamesResponse getSanitizedUsernames(String id) { * Get a BungieUser from a Steam ID * NOT the same IDs used by Bungie to identify individual users */ - public static BungieUser getMemberFromSteamID(String steamID) { + public static BungieUser getMemberFromSteamID(String steamID) throws APIException { return getMemberFromPlatformID("SteamId", steamID); } @@ -148,7 +147,7 @@ public static BungieUser getMemberFromSteamID(String steamID) { * Used to get a BungieUser from a specified platform ID * Currently only works with Steam IDs (see getMemberFromSteamID()) */ - private static BungieUser getMemberFromPlatformID(String platformName, String platformID) { + private static BungieUser getMemberFromPlatformID(String platformName, String platformID) throws APIException { JsonObject jsonObject = getHttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/GetMembershipFromHardLinkedCredential/" + platformName + "/" + platformID + "/").getAsJsonObject("Response"); return new BungieUser(jsonObject.get("membershipId").getAsString()); @@ -162,7 +161,7 @@ private static BungieUser getMemberFromPlatformID(String platformName, String pl *

* Requires OAuth */ - public static UserCredential[] getUserCredentials(BungieUser bungieUser) { + public static UserCredential[] getUserCredentials(BungieUser bungieUser) throws APIException { List list = new LinkedList<>(); for (JsonElement je : getHttpUtils().urlRequestGETOauth("https://www.bungie.net/Platform/User/GetCredentialTypesForTargetAccount/" + bungieUser.getID() + "/").getAsJsonArray("Response")) { @@ -185,7 +184,7 @@ public static UserCredential[] getUserCredentials(BungieUser bungieUser) { /** * Get a "UserCredential" from a BungieUser */ - public static UserCredential getUserCredential(UserCredentialType type, BungieUser bungieUser) { + public static UserCredential getUserCredential(UserCredentialType type, BungieUser bungieUser) throws APIException { for (UserCredential userCredential : getUserCredentials(bungieUser)) { if (userCredential.getUserCredentialType() == type) { return userCredential; @@ -207,7 +206,7 @@ public static UserCredential getUserCredential(UserCredentialType type, BungieUs * @param nameAndDiscrim A full name and discriminator such as "dec4234#9904" * @return A user with the matching name and discriminator, null otherwise */ - public static BungieUser getUserWithName(String nameAndDiscrim) { + public static BungieUser getUserWithName(String nameAndDiscrim) throws APIException { try { String[] split = nameAndDiscrim.split("#"); JsonObject jsonObject = new JsonObject(); @@ -229,7 +228,7 @@ public static BungieUser getUserWithName(String nameAndDiscrim) { * BungieUser. While searching "Gladd" or "Datto" should return * multiple. */ - public static List searchUsers(String name) { + public static List searchUsers(String name) throws APIException { List users = new ArrayList<>(); JsonObject body = new JsonObject(); @@ -274,7 +273,7 @@ public static List searchUsers(String name) { * @param jsonArray * @return */ - private static BungieUser processListOfProfiles(JsonArray jsonArray) { + private static BungieUser processListOfProfiles(JsonArray jsonArray) throws APIException { for (JsonElement jsonElement : jsonArray) { JsonObject profile = jsonElement.getAsJsonObject(); @@ -325,7 +324,7 @@ private static BungieUser processListOfProfiles(JsonArray jsonArray) { * Use searchUsers() instead */ @Deprecated - public static List searchGlobalDisplayNames(String prefix) { + public static List searchGlobalDisplayNames(String prefix) throws APIException { prefix = StringUtils.httpEncode(prefix); List bungieUsers = new ArrayList<>(); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java index f492b0f..1cd6b90 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.clan; @@ -11,17 +10,19 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; -import net.dec4234.javadestinyapi.stats.activities.ActivityMode; import net.dec4234.javadestinyapi.material.user.BungieUser; -import net.dec4234.javadestinyapi.material.user.DestinyPlatform; +import net.dec4234.javadestinyapi.stats.activities.ActivityMode; import net.dec4234.javadestinyapi.utils.HttpUtils; import net.dec4234.javadestinyapi.utils.StringUtils; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; public class Clan extends ContentFramework { @@ -37,7 +38,7 @@ public class Clan extends ContentFramework { private int memberCount = -1; private List admins, members; - private net.dec4234.javadestinyapi.material.clan.ClanManagement clanManagement; + private ClanManagement clanManagement; private JsonObject jj; public Clan(long clanId) { @@ -62,46 +63,46 @@ public Clan(long clanId, String clanName) { this.clanName = clanName; } - public String getClanID() { + public String getClanID() throws APIException { if (clanId == -1) { clanId = getDetail().get("groupId").getAsLong(); } return clanId + ""; } - public String getClanName() { + public String getClanName() throws APIException { if (clanName == null) { clanName = getJO().getAsJsonObject("detail").get("name").getAsString(); } return clanName; } - public String getClanDescription() { + public String getClanDescription() throws APIException { if (clanDescription == null) { clanDescription = getDetail().get("about").getAsString(); } return clanDescription; } - public Date getCreationDate() { + public Date getCreationDate() throws APIException { if (creationDate == null) { creationDate = StringUtils.valueOfZTime(getDetail().get("creationDate").getAsString()); } return creationDate; } - public int getMemberCount() { + public int getMemberCount() throws APIException { if (memberCount == -1) { memberCount = getDetail().get("memberCount").getAsInt(); } return memberCount; } - public boolean isPublic() { + public boolean isPublic() throws APIException { return getDetail().get("isPublic").getAsBoolean(); } - public String getMotto() { + public String getMotto() throws APIException { if (motto == null) { motto = getDetail().get("motto").getAsString(); } @@ -111,14 +112,14 @@ public String getMotto() { /** * Get if this clan allows chat. I think this refers to the Bungie.net clan chat page */ - public boolean isAllowChat() { + public boolean isAllowChat() throws APIException { return getDetail().get("allowChat").getAsBoolean(); } /** * Get the founder of the clan */ - public BungieUser getFounder() { + public BungieUser getFounder() throws APIException { return new BungieUser(getJO().getAsJsonObject("founder").getAsJsonObject("destinyUserInfo").get("membershipId").getAsString()); } @@ -127,7 +128,7 @@ public BungieUser getFounder() { * The founder is always the first in this list? * Followed by the admins in the order they were promoted */ - public List getAdmins() { + public List getAdmins() throws APIException { if (admins != null) { return admins; } @@ -148,7 +149,7 @@ public List getAdmins() { * * Thanks to the ClanMember system, requires very little calls and should be pretty fast. */ - public double getAverageInactivityAmongMembers() { + public double getAverageInactivityAmongMembers() throws APIException { ArrayList averages = new ArrayList<>(); int a = 0; for (ClanMember clanMember : this.getMembers()) { @@ -163,7 +164,7 @@ public double getAverageInactivityAmongMembers() { /** * Get the most inactive members of a clan, using the getMembers() endpoint and the ClanMember class */ - public List getMostInactiveMembers(int numberOfResults, String... exclude) { + public List getMostInactiveMembers(int numberOfResults, String... exclude) throws APIException { List list = getMembers(); List excluded = Arrays.asList(exclude); List toReturn = new LinkedList<>(); @@ -190,7 +191,7 @@ public List getMostInactiveMembers(int numberOfResults, String... ex * * TO-DO: Maybe switch this to the search part of the /Members/ endpoint? */ - public List searchMembers(String name) { + public List searchMembers(String name) throws APIException { List list = new LinkedList<>(); for (BungieUser bungieUser : getMembers()) { @@ -208,7 +209,7 @@ public List searchMembers(String name) { * * @return A list of all online members of the clan */ - public List getOnlineMembers() { + public List getOnlineMembers() throws APIException { List toReturn = new ArrayList<>(); for(ClanMember clanMember : getMembers()) { @@ -225,7 +226,7 @@ public List getOnlineMembers() { * * @return The userIds belonging to the members of this clan */ - public List getMembersIDs() { + public List getMembersIDs() throws APIException { List toReturn = new ArrayList<>(); for (BungieUser bungieUser : getMembers()) { @@ -239,7 +240,7 @@ public List getMembersIDs() { * Get the members of this clan * @return A List of ClanMember */ - public List getMembers() { + public List getMembers() throws APIException { List clanMembers = new ArrayList<>(); JsonObject response = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + getClanID() + "/Members/").get("Response").getAsJsonObject(); @@ -256,7 +257,7 @@ public List getMembers() { * @param amount The amount of members to return * @return A sorted list of the oldest members of this clan */ - public List getOldestMembers(int amount) { + public List getOldestMembers(int amount) throws APIException { List members = getMembers(); List sorted = new LinkedList<>(); @@ -285,14 +286,14 @@ public List getOldestMembers(int amount) { /** * Returns if this BungieUser is a member of the clan */ - public boolean isMember(BungieUser bungieUser) { + public boolean isMember(BungieUser bungieUser) throws APIException { return isMember(bungieUser.getID()); } /** * Checks if the member with the provided id is a member of the clan */ - public boolean isMember(String bungieID) { + public boolean isMember(String bungieID) throws APIException { for (BungieUser bungieUser : getMembers()) { if (bungieUser.getID().equals(bungieID)) { return true; @@ -306,7 +307,7 @@ public boolean isMember(String bungieID) { * Retrieve a JsonObject depicting the top stats of the clan * Unfortunately does not say who has those top stats */ - public JsonObject getClanStats(ActivityMode... filter) { + public JsonObject getClanStats(ActivityMode... filter) throws APIException { String queryString = "/?modes="; for (ActivityMode activityMode : filter) { queryString = queryString.concat(activityMode.getBungieValue() + ","); @@ -321,7 +322,7 @@ public JsonObject getClanStats(ActivityMode... filter) { * * @return The Date this user joined the clan or null if that user was not found */ - public Date getJoinDate(BungieUser member) { + public Date getJoinDate(BungieUser member) throws APIException { if (jj == null) { jj = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + getClanID() + "/Members/").get("Response").getAsJsonObject(); } @@ -346,7 +347,7 @@ public ClanManagement getClanManagement() { return clanManagement; } - private JsonObject getDetail() { + private JsonObject getDetail() throws APIException { return getJO().getAsJsonObject("detail"); } } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java index 4378c14..d42f390 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.clan; public enum ClanChatSecuritySetting { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java index 1518307..57ec675 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.clan; @@ -11,6 +10,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.utils.HttpUtils; @@ -38,57 +38,57 @@ public ClanManagement(Clan clan) { /** * Kicks this user from the clan */ - public void kickPlayer(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Kick/", ""); + public void kickPlayer(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Kick/"); } /** * Bans the user from the clan */ - public void banUser(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Ban/", ""); + public void banUser(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Ban/"); } /** * Unbans this user from the clan, as long as they are banned, of course */ - public void unbanUser(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Unban/", ""); + public void unbanUser(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Unban/"); } /** * Invites the specified user to join the clan */ - public void inviteUser(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInvite/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + public void inviteUser(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInvite/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** * Cancels the invite for this user to join the clan */ - public void cancelInvite(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInviteCancel/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + public void cancelInvite(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInviteCancel/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** * Approves this user's request to join the clan if and only if they have requested to join */ - public void approvePendingMember(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Approve/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + public void approvePendingMember(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Approve/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** * Approves all requests to join the clan */ - public void approveAllPendingMembers() { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/ApproveAll/", ""); + public void approveAllPendingMembers() throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/ApproveAll/"); } /** * Denies all pending requests to join the clan :) */ - public void denyAllPendingMembers() { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/DenyAll/?components=200", ""); + public void denyAllPendingMembers() throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/DenyAll/?components=200"); } /** @@ -96,8 +96,8 @@ public void denyAllPendingMembers() { * * @param bungieUser The user who will be the new founder (leader) of the clan */ - public void abdicateFoundership(BungieUser bungieUser) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/AbdicateFoundership/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + public void abdicateFoundership(BungieUser bungieUser) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/AbdicateFoundership/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** @@ -106,12 +106,12 @@ public void abdicateFoundership(BungieUser bungieUser) { * @param chatName The name of the chat * @param clanChatSecuritySetting The security setting of the chat */ - public void addOptionalConversation(String chatName, ClanChatSecuritySetting clanChatSecuritySetting) { + public void addOptionalConversation(String chatName, ClanChatSecuritySetting clanChatSecuritySetting) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("chatName", chatName); jsonObject.addProperty("chatSecurity", clanChatSecuritySetting.getSetting()); - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/Add/", jsonObject.toString()); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/Add/", jsonObject); } /** @@ -122,13 +122,13 @@ public void addOptionalConversation(String chatName, ClanChatSecuritySetting cla * @param chatName The name of the chat * @param clanChatSecuritySetting The security setting of the chat */ - public void editOptionalConversation(String conversationID, boolean chatEnabled, String chatName, ClanChatSecuritySetting clanChatSecuritySetting) { + public void editOptionalConversation(String conversationID, boolean chatEnabled, String chatName, ClanChatSecuritySetting clanChatSecuritySetting) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("chatName", chatName); jsonObject.addProperty("chatSecurity", clanChatSecuritySetting.getSetting()); jsonObject.addProperty("chatEnabled", chatEnabled); - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/" + conversationID + "/Edit/", jsonObject.toString()); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/" + conversationID + "/Edit/", jsonObject); } /** @@ -136,7 +136,7 @@ public void editOptionalConversation(String conversationID, boolean chatEnabled, * * @return The list of banned users */ - public List getBannedMembers() { + public List getBannedMembers() throws APIException { if (bannedMembers != null) { return bannedMembers; } List temp = new ArrayList<>(); @@ -151,7 +151,7 @@ public List getBannedMembers() { /** * Returns a list of pending members to the clan, Never cached: always makes a new request */ - public List getPendingMembers() { + public List getPendingMembers() throws APIException { List temp = new ArrayList<>(); JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Pending/?components=200").get("Response").getAsJsonObject().get("results").getAsJsonArray(); @@ -169,10 +169,10 @@ public List getPendingMembers() { * * @return The list of invited users */ - public List getInvitedMembers() { + public List getInvitedMembers() throws APIException { List temp = new ArrayList<>(); - JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Invited/?components=200").getAsJsonObject("Response").getAsJsonArray("results"); + JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/InvitedIndividuals/?components=200").getAsJsonObject("Response").getAsJsonArray("results"); for(JsonElement je : ja) { temp.add(new BungieUser(je.getAsJsonObject().getAsJsonObject("destinyUserInfo").get("membershipId").getAsString())); @@ -184,7 +184,7 @@ public List getInvitedMembers() { /** * Check if a BungieUser is a pending applicant without the performance overhead of creating multiple BungieUsers */ - public boolean isPendingMember(BungieUser bungieUser) { + public boolean isPendingMember(BungieUser bungieUser) throws APIException { JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Pending/?components=200").get("Response").getAsJsonObject().get("results").getAsJsonArray(); for(JsonElement jsonElement : ja) { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java index b7cea7f..2e08785 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.clan; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java index b4786f4..5641af9 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java @@ -1,13 +1,13 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.inventory.items.DestinyItem; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; @@ -16,14 +16,14 @@ public class CollectionsManager extends ContentFramework { private BungieUser bungieUser; - public CollectionsManager(BungieUser bungieUser) { + public CollectionsManager(BungieUser bungieUser) throws APIException { super("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Profile/" + bungieUser.getID() + "/?components=800", source -> { return source.getAsJsonObject("Response"); }); this.bungieUser = bungieUser; } - public boolean hasCollectedItem(String collectibleHash) { + public boolean hasCollectedItem(String collectibleHash) throws APIException { try { return getJO().getAsJsonObject("profileCollectibles").getAsJsonObject("data").getAsJsonObject("collectibles").getAsJsonObject(collectibleHash).get("state").getAsInt() == 0; } catch (NullPointerException e) { @@ -31,7 +31,7 @@ public boolean hasCollectedItem(String collectibleHash) { } } - public boolean hasCollectedItem(DestinyItem destinyItem) { + public boolean hasCollectedItem(DestinyItem destinyItem) throws APIException { try { return getJO().getAsJsonObject("profileCollectibles").getAsJsonObject("data").getAsJsonObject("collectibles").getAsJsonObject(destinyItem.getCollectibleHash()).get("state").getAsInt() == 0; } catch (NullPointerException e) { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java index 9d48fcd..dfbd8ea 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java @@ -1,13 +1,13 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; @@ -25,7 +25,7 @@ public InventoryManager(BungieUser bungieUser) { this.bungieUser = bungieUser; } - public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) { + public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) throws APIException { return bungieUser.getCharacterOfType(destinyClass); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java index f405a1f..d2463db 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.items; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java index 5aa7688..03912ab 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java @@ -1,19 +1,20 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.DestinyManifest; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; import net.dec4234.javadestinyapi.utils.HttpUtils; +import net.dec4234.javadestinyapi.utils.StringUtils; import net.dec4234.javadestinyapi.utils.framework.ContentInterface; import java.util.ArrayList; @@ -46,7 +47,7 @@ public DestinyItem(String hashID, String name, String icon, boolean hasIcon) { this.hasIcon = hasIcon; } - public String getHashID() { + public String getHashID() throws APIException { if(hashID == null) { checkJO(); hashID = jo.get("hash").getAsString(); @@ -54,14 +55,14 @@ public String getHashID() { return hashID; } - public int getHashIDasInt() { + public int getHashIDasInt() throws APIException { return Integer.parseInt(getHashID()); } /** * Gets the name of the item */ - public String getName() { + public String getName() throws APIException { if(name == null) { checkDP(); name = dp.get("name").getAsString(); @@ -72,7 +73,7 @@ public String getName() { /** * Plug this after https://www.bungie.net/ in a browser */ - public String getIcon() { + public String getIcon() throws APIException { if(icon == null) { checkDP(); icon = dp.get("icon").getAsString(); @@ -83,7 +84,7 @@ public String getIcon() { /** * Gets the lore descriptions associated with this item */ - public String getDescription() { + public String getDescription() throws APIException { if(description == null) { checkDP(); description = dp.get("description").getAsString(); @@ -91,13 +92,13 @@ public String getDescription() { return description; } - public boolean hasIcon() { + public boolean hasIcon() throws APIException { checkDP(); hasIcon = dp.get("hasIcon").getAsBoolean(); return hasIcon; } - public String getCollectibleHash() { + public String getCollectibleHash() throws APIException { checkJO(); if(jo.has("collectibleHash")) { collectibleHash = jo.get("collectibleHash").getAsString(); @@ -106,7 +107,7 @@ public String getCollectibleHash() { return collectibleHash; } - public String getScreenshot() { + public String getScreenshot() throws APIException { checkJO(); if(jo.has("screenshot") && screenshot == null) { screenshot = jo.get("screenshot").getAsString(); @@ -115,14 +116,14 @@ public String getScreenshot() { return screenshot; } - public ItemTier getItemTier() { + public ItemTier getItemTier() throws APIException { if(itemTier == null) { itemTier = assessItemTier(); } return itemTier; } - private ItemTier assessItemTier() { + private ItemTier assessItemTier() throws APIException { checkJO(); switch(jo.getAsJsonObject("inventory").get("tierTypeName").getAsString()) { case "Common": @@ -140,14 +141,14 @@ private ItemTier assessItemTier() { } @Override - public void checkJO() { + public void checkJO() throws APIException { if(jo == null) { jo = new DestinyManifest().manifestGET(ManifestEntityTypes.INVENTORYITEM, hashID); // jo = hu.manifestGET(ManifestEntityTypes.INVENTORYITEM, hashID).getAsJsonObject("Response"); } } - public void checkDP() { + public void checkDP() throws APIException { if(dp == null) { checkJO(); dp = jo.getAsJsonObject("displayProperties"); @@ -165,10 +166,10 @@ public enum ItemTier { /** * Return a list of all items that contain or match the name provided */ - public static List searchForItems(String itemName) { + public static List searchForItems(String itemName) throws APIException { HttpUtils httpUtils = DestinyAPI.getHttpUtils(); List destinyItemList = new ArrayList<>(); - itemName = itemName.replace(" ", "%20"); + itemName = StringUtils.httpEncode(itemName); for(JsonElement jsonElement : httpUtils.urlRequestGET("https://www.bungie.net/Platform/Destiny2/Armory/Search/DestinyInventoryItemDefinition/" + itemName + "/").getAsJsonObject("Response").getAsJsonObject("results").getAsJsonArray("results")) { JsonObject jsonObject = jsonElement.getAsJsonObject(); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java index 2063785..966d421 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory.items; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java index 5b797cb..36e9f2c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java @@ -1,17 +1,16 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; -import net.dec4234.javadestinyapi.material.inventory.items.DestinyItem; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; import net.dec4234.javadestinyapi.utils.HttpUtils; @@ -31,7 +30,7 @@ public class InventoryItem extends DestinyItem { private int quantity, bindStatus, location, transferStatus, state, dismantlePermission; private boolean lockable = false, isWrapper; - public InventoryItem(String instanceId, DestinyCharacter characterOwner) { + public InventoryItem(String instanceId, DestinyCharacter characterOwner) throws APIException { this(httpUtils.urlRequestGET(HttpUtils.URL_BASE + "/Destiny2/" + characterOwner.getMembershipType() + "/Profile/" + characterOwner.getMembershipID() + "/Item/" + instanceId + "/?components=305").getAsJsonObject("Response").getAsJsonObject("item").getAsJsonObject("data")); this.characterOwner = characterOwner; @@ -99,7 +98,7 @@ private InventoryItem(JsonObject jsonObject) { * * @return Returns a list of ItemPlugs */ - public List getItemPlugs() { + public List getItemPlugs() throws APIException { JsonObject jsonObject = httpUtils.urlRequestGET(HttpUtils.URL_BASE + "/Destiny2/" + characterOwner.getMembershipType() + "/Profile/" + characterOwner.getMembershipID() + "/Item/" + instanceId + "/?components=305"); List itemPlugs = new ArrayList<>(); jsonObject = jsonObject.getAsJsonObject("Response").getAsJsonObject("sockets").getAsJsonObject("data"); @@ -117,7 +116,7 @@ public List getItemPlugs() { * * @return Returns true if the move was succesful */ - public boolean moveTo(DestinyCharacter destinyCharacter) { + public boolean moveTo(DestinyCharacter destinyCharacter) throws APIException { if(!isInVault()) { moveToVault(); } @@ -138,7 +137,7 @@ public boolean moveTo(DestinyCharacter destinyCharacter) { * * @return True if the move was reported as succesful */ - public boolean moveToVault() { + public boolean moveToVault() throws APIException { JsonObject jsonObject = httpUtils.urlRequestPOSTOauth(HttpUtils.URL_BASE + "/Destiny2/Actions/Items/TransferItem/", prepareJsonObject(getCharacterOwner(), true, isItemEquippable())); boolean wasSuccesful = wasTransferSuccesful(jsonObject); @@ -159,7 +158,7 @@ public boolean moveToVault() { * * @return Returns whether or not the action was succesful */ - public boolean equip() { + public boolean equip() throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("itemId", getInstanceIDAsLong()); jsonObject.addProperty("characterId", getCharacterOwner().getCharacterIDAsLong()); @@ -195,7 +194,7 @@ public boolean isItemEquippable() { * Lock or unlock an item * @param state The state of the lock the item should be set to */ - public void setLockState(boolean state) { + public void setLockState(boolean state) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("state", state); jsonObject.addProperty("itemId", getInstanceId()); @@ -203,7 +202,7 @@ public void setLockState(boolean state) { jsonObject.addProperty("membershipType", getCharacterOwner().getMembershipType()); - httpUtils.urlRequestPOSTOauth(HttpUtils.URL_BASE + "/Destiny2/Actions/Items/SetLockState/", jsonObject.toString()); + httpUtils.urlRequestPOSTOauth(HttpUtils.URL_BASE + "/Destiny2/Actions/Items/SetLockState/", jsonObject); } /** @@ -285,7 +284,7 @@ public boolean isWrapper() { /** * Prepares a POST body for item transferring */ - private JsonObject prepareJsonObject(DestinyCharacter destinyCharacter, boolean moveToVault, boolean isEquippable) { + private JsonObject prepareJsonObject(DestinyCharacter destinyCharacter, boolean moveToVault, boolean isEquippable) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("itemReferenceHash", getHashIDasInt()); jsonObject.addProperty("stackSize", isEquippable ? 1 : getQuantity()); // If the item is equippable, set stack size as 1 diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java index 43bf65a..97b7152 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java @@ -1,6 +1,14 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.manifest.DestinyManifest; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -11,7 +19,7 @@ public class ItemPerk { private int perkVisibility; private boolean isActive, visible; - public ItemPerk(String perkHash) { + public ItemPerk(String perkHash) throws APIException { this(new DestinyManifest().manifestGET(ManifestEntityTypes.INVENTORYITEM, perkHash)); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java index 42258fa..b2b38ce 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java @@ -1,6 +1,14 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.manifest.DestinyManifest; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; import org.jetbrains.annotations.NotNull; @@ -31,11 +39,11 @@ public class ItemPlug { private boolean onActionRecreateSelf, isDummyPlug, applyStatsToSocketOwnerItem; private int plugStyle, plugAvailibility, alternatePlugStyle; - public ItemPlug(@NotNull String hash) { + public ItemPlug(@NotNull String hash) throws APIException { this(new DestinyManifest().manifestGET(ManifestEntityTypes.INVENTORYITEM, hash)); } - public ItemPlug(@NotNull String hash, boolean isEnabled, boolean isVisible) { + public ItemPlug(@NotNull String hash, boolean isEnabled, boolean isVisible) throws APIException { this(hash); this.isEnabled = isEnabled; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java index 759ca3b..fd89ed2 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.loadouts; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java b/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java index b9a1edc..aecee3b 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java @@ -1,14 +1,14 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.manifest; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; @@ -36,7 +36,7 @@ public DestinyManifest() { * * It'll download the entire definition library the first time and it'll cache it */ - public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String hash) { + public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String hash) throws APIException { JsonObject jsonObject = getDefinitionLibrary(manifestEntityTypes); if(jsonObject.has(hash)) { @@ -50,36 +50,36 @@ public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String ha * Get the current version of the manifest * Useful for checking for updates */ - public String getVersion() { + public String getVersion() throws APIException { return getJO().get("version").getAsString(); } - public String getMobileAssetContentPath() { + public String getMobileAssetContentPath() throws APIException { return getJO().get("mobileAssetContentPath").getAsString(); } - public String getMobileWorldContentPath(Language language) { + public String getMobileWorldContentPath(Language language) throws APIException { return getJO().getAsJsonObject("mobileWorldContentPaths").get(language.getCode()).getAsString(); } - public String getJsonWorldContentPath(Language language) { + public String getJsonWorldContentPath(Language language) throws APIException { return getJO().getAsJsonObject("jsonWorldContentPaths").get(language.getCode()).getAsString(); } - public JsonObject getWorldContent(Language language) { + public JsonObject getWorldContent(Language language) throws APIException { return DestinyAPI.getHttpUtils().urlRequestGET("https://www.bungie.net" + getJsonWorldContentPath(language)); } /** * Get the entirety of the specified definition library */ - public JsonObject getDefinitionLibrary(ManifestEntityTypes manifestEntityTypes) { + public JsonObject getDefinitionLibrary(ManifestEntityTypes manifestEntityTypes) throws APIException { Language language = Language.ENGLISH; return getDefinitionLibrary(language, manifestEntityTypes); } - public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes manifestEntityTypes) { + public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes manifestEntityTypes) throws APIException { if(!worldComponents.containsKey(manifestEntityTypes.getBungieEntityValue())) { worldComponents.put(manifestEntityTypes.getBungieEntityValue(), DestinyAPI.getHttpUtils().urlRequestGET("https://www.bungie.net" + getJO().getAsJsonObject("jsonWorldComponentContentPaths").getAsJsonObject(language.getCode()).get(manifestEntityTypes.getBungieEntityValue()).getAsString())); } @@ -87,7 +87,7 @@ public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes ma return worldComponents.get(manifestEntityTypes.getBungieEntityValue()); } - public String getMobileClanBannerDatabasePath() { + public String getMobileClanBannerDatabasePath() throws APIException { return getJO().get("mobileClanBannerDatabasePath").getAsString(); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java b/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java index 09f2ec3..4da0d30 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.manifest; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java index ca5911a..c2e929c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.social; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java index 77e9fda..b382ec1 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java @@ -1,7 +1,15 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.social; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import java.util.ArrayList; @@ -11,7 +19,7 @@ public class SocialFriendsList { - public List getFriendsList() { + public List getFriendsList() throws APIException { List list = new ArrayList<>(); JsonObject jo = DestinyAPI.getHttpUtils().urlRequestGETOauth(URL_BASE + "/Social/Friends/"); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java index 789511f..d5280db 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; @@ -11,6 +10,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.clan.Clan; import net.dec4234.javadestinyapi.material.inventory.CollectionsManager; @@ -43,6 +43,7 @@ public class BungieUser extends ContentFramework { private List destinyCharacters = null; private int playTime = -1, crossSaveOverride = -1, membershipType = -1; private boolean isPublic, isCrossSavePrimary, isOverridden = false; + @Deprecated private int intendedPlatform = -2; private InventoryManager inventoryManager; private CollectionsManager collectionsManager; @@ -127,7 +128,7 @@ public BungieUser(String bungieMembershipID, String displayName, String globalDi * Determines if the user has any profiles on their account * Useful to see if a user's account has any data on it */ - public boolean isValidUser() { + public boolean isValidUser() throws APIException { try { return getJO().getAsJsonArray("profiles").size() != 0; } catch (NullPointerException nullPointerException) { @@ -142,7 +143,7 @@ public boolean isValidUser() { * Deprecated in favor of getGlobalDisplayName() */ @Deprecated - public String getDisplayName() { + public String getDisplayName() throws APIException { getJE(); if (displayName == null) { displayName = getJE().get("displayName").getAsString(); @@ -156,7 +157,7 @@ public String getDisplayName() { * Please note, an empty string will be returned if a user has not logged in since the * start of Season of The Lost */ - public String getGlobalDisplayName() { + public String getGlobalDisplayName() throws APIException { if (globalDisplayName == null) { // LinkedProfiles is not populated with bungieGlobalDisplayName as of 8/29/2021: github issue #1511 @@ -171,7 +172,7 @@ public String getGlobalDisplayName() { * Returns the combined displayname and user discriminator as used in friend requests and user searches * E.g. dec4234#9904 */ - public String getSupplementalDisplayName() { + public String getSupplementalDisplayName() throws APIException { if (supplementalDisplayName == null) { supplementalDisplayName = getJO().getAsJsonObject("bnetMembership").get("supplementalDisplayName").getAsString(); } @@ -183,7 +184,7 @@ public String getSupplementalDisplayName() { * Get the discriminator of a user's name * E.g. "9904" of dec4234#9904 */ - public String getDiscriminator() { + public String getDiscriminator() throws APIException { if (discriminator == null) { discriminator = getSupplementalDisplayName().split("#")[1]; } @@ -194,7 +195,7 @@ public String getDiscriminator() { /** * Gets the last day this user was seen online */ - public Date getLastPlayed() { + public Date getLastPlayed() throws APIException { if (lastPlayed == null) { lastPlayed = StringUtils.valueOfZTime(getJE().get("dateLastPlayed").getAsString()); } @@ -205,27 +206,27 @@ public Date getLastPlayed() { /** * Gets a double representing the number of days since the user last played */ - public double getDaysSinceLastPlayed() { + public double getDaysSinceLastPlayed() throws APIException { DecimalFormat df = new DecimalFormat("0.##"); return Double.parseDouble(df.format((new Date().getTime() - getLastPlayed().getTime()) / 1000.0 / 60.0 / 60.0 / 24.0)); } - public boolean isOverridden() { + public boolean isOverridden() throws APIException { return !isOverridden ? isOverridden = getJE().get("isOverridden").getAsBoolean() : isOverridden; } - public boolean isCrossSavePrimary() { + public boolean isCrossSavePrimary() throws APIException { return !isCrossSavePrimary ? isCrossSavePrimary = getJE().get("isCrossSavePrimary").getAsBoolean() : isCrossSavePrimary; } - public int getCrossSaveOverride() { + public int getCrossSaveOverride() throws APIException { return crossSaveOverride == -1 ? crossSaveOverride = getJE().get("crossSaveOverride").getAsInt() : crossSaveOverride; } /** * Get the applicable membership types declared in the response */ - public ArrayList getApplicableMembershipTypes() { + public ArrayList getApplicableMembershipTypes() throws APIException { if (applicableMembershipTypes.isEmpty()) { for (JsonElement jj : getJE().get("applicableMembershipTypes").getAsJsonArray()) { applicableMembershipTypes.add(jj.getAsInt()); @@ -237,7 +238,7 @@ public ArrayList getApplicableMembershipTypes() { /** * Get all membership types declared under this account's profiles */ - public ArrayList getMembershipTypes() { + public ArrayList getMembershipTypes() throws APIException { ArrayList integers = new ArrayList<>(); for (JsonElement jsonElement : getJO().get("profiles").getAsJsonArray()) { @@ -247,14 +248,14 @@ public ArrayList getMembershipTypes() { return integers; } - public boolean isPublic() { + public boolean isPublic() throws APIException { return !isPublic ? isPublic = getJE().get("isPublic").getAsBoolean() : isPublic; } /** * Returns the membership type of the main profile */ - public int getMembershipType() { + public int getMembershipType() throws APIException { return membershipType == -1 ? membershipType = getJE().get("membershipType").getAsInt() : membershipType; } @@ -263,7 +264,7 @@ public int getMembershipType() { * * @return The list of characters associated with this account, or null if none are found */ - public List getCharacters() { + public List getCharacters() throws APIException { if (destinyCharacters != null) { return destinyCharacters; } destinyCharacters = new ArrayList<>(); JsonObject jsonObject = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + getID() + "/?components=Profiles,Characters").getAsJsonObject("Response"); @@ -290,7 +291,7 @@ public List getCharacters() { * @param destinyClass * @return The character if there is one, and is not a duplicate */ - public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) { + public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) throws APIException { DestinyCharacter toReturn = null; for (DestinyCharacter destinyCharacter : this.getCharacters()) { @@ -311,7 +312,7 @@ public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destiny * * @return The time played of this user, in minutes */ - public int getTimePlayed() { + public int getTimePlayed() throws APIException { if (playTime != -1) { return playTime; } for (DestinyCharacter c : getCharacters()) { playTime += Integer.parseInt(c.getMinutesPlayedTotal()); @@ -322,7 +323,7 @@ public int getTimePlayed() { /** * Gets the clan that this user is a member of */ - public Clan getClan() { + public Clan getClan() throws APIException { if (clan != null) { return clan; } JsonObject jo2 = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/User/" + getMembershipType() + "/" + getID() + "/0/1/?components=200").getAsJsonObject("Response"); @@ -335,7 +336,7 @@ public Clan getClan() { * If the user is currently in a clan * @return Returns true if the user is a member of a clan */ - public boolean isAMemberOfAClan() { + public boolean isAMemberOfAClan() throws APIException { return getClan() != null; } @@ -352,7 +353,7 @@ public void allowClanInvites(boolean allowInvites) { * Determines if the user is online * @return Returns true if the user is online */ - public boolean isOnline() { + public boolean isOnline() throws APIException { for(DestinyCharacter destinyCharacter : getCharacters()) { if(destinyCharacter.getLastPlayed().getTime() + ((long) destinyCharacter.getMinutesPlayedThisSession() * 60 * 1000) + (10 * 1000) > System.currentTimeMillis()) { return true; @@ -368,7 +369,7 @@ public boolean isOnline() { * * @return Null if no information about the current activity is found */ - public ActivityInfo getCurrentActivityInfo() { + public ActivityInfo getCurrentActivityInfo() throws APIException { JsonObject data = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + getID() + "/?components=204").getAsJsonObject("Response").getAsJsonObject("characterActivities").getAsJsonObject("data"); for (DestinyCharacter character : getCharacters()) { @@ -386,8 +387,8 @@ public ActivityInfo getCurrentActivityInfo() { /** * Request to join the specified clan */ - public void requestToJoinClan(Clan clan) { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Apply/" + getMembershipType() + "/", ""); + public void requestToJoinClan(Clan clan) throws APIException { + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Apply/" + getMembershipType() + "/"); } /** @@ -395,7 +396,7 @@ public void requestToJoinClan(Clan clan) { * Uses the preferred platform profile if it has been declared or * it will select the first profile in the profiles array */ - public JsonObject getJE() { + public JsonObject getJE() throws APIException { if (je == null) { if (intendedPlatform != -2) { for (JsonElement jsonElement : getJO().getAsJsonArray("profiles")) { @@ -442,6 +443,7 @@ public JsonObject getJE() { return je; } + @Deprecated public void setIntendedPlatform(DestinyPlatform destinyPlatform) { intendedPlatform = destinyPlatform.getPlatformCode(); je = null; @@ -455,7 +457,7 @@ public InventoryManager getInventoryManager() { return inventoryManager; } - public CollectionsManager getCollectionsManager() { + public CollectionsManager getCollectionsManager() throws APIException { if (collectionsManager == null) { collectionsManager = new CollectionsManager(this); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java index 0d20c4b..ad06555 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; @@ -11,6 +10,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.inventory.items.DestinyItem; import net.dec4234.javadestinyapi.material.inventory.items.InventoryItem; @@ -43,7 +43,7 @@ public class DestinyCharacter extends ContentFramework { HttpUtils hu = DestinyAPI.getHttpUtils(); - public DestinyCharacter(BungieUser bungieUser, String characterID) { + public DestinyCharacter(BungieUser bungieUser, String characterID) throws APIException { super("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + characterID + "/?components=200", source -> source.getAsJsonObject("Response").getAsJsonObject("character").getAsJsonObject("data")); this.characterID = characterID; @@ -67,7 +67,7 @@ public String getMembershipID() { /** * Get the membershipType of the account that owns this character */ - public int getMembershipType() { + public int getMembershipType() throws APIException { return bungieUser.getMembershipType(); } @@ -89,7 +89,7 @@ public int getMembershipType() { /** * Get the Date that this character was last played */ - public Date getLastPlayed() { + public Date getLastPlayed() throws APIException { if (lastPlayed == null) { lastPlayed = StringUtils.valueOfZTime(getJO().get("dateLastPlayed").getAsString()); } @@ -100,7 +100,7 @@ public Date getLastPlayed() { * Get the total amount of time, in minutes, that this character has been played in this session * TO-DO: Define what a "session" is */ - public int getMinutesPlayedThisSession() { + public int getMinutesPlayedThisSession() throws APIException { if (minutesPlayedThisSession == -1) { minutesPlayedThisSession = getJO().get("minutesPlayedThisSession").getAsInt(); } @@ -110,7 +110,7 @@ public int getMinutesPlayedThisSession() { /** * Get the total amount of time, in minutes, that has been played on this character */ - public String getMinutesPlayedTotal() { + public String getMinutesPlayedTotal() throws APIException { if (minutesPlayedTotal == null) { minutesPlayedTotal = getJO().get("minutesPlayedTotal").getAsString(); } @@ -122,7 +122,7 @@ public String getMinutesPlayedTotal() { * * @return The light level of this character, as an integer */ - public int getLightLevel() { + public int getLightLevel() throws APIException { if (lightLevel == -1) { lightLevel = getJO().get("light").getAsInt(); } @@ -133,7 +133,7 @@ public int getLightLevel() { * Get the race of this character * Either Human, Exo or Awoken */ - public Race getRace() { + public Race getRace() throws APIException { if (race == null) { race = evaluateRace(getJO().get("raceHash").getAsString()); } @@ -145,7 +145,7 @@ public Race getRace() { * * @return Male or Female */ - public Gender getGender() { + public Gender getGender() throws APIException { if (gender == null) { gender = evaluateGender(getJO().get("genderHash").getAsString()); } @@ -156,7 +156,7 @@ public Gender getGender() { * Get the Class of this character * Either Warlock, Titan or Hunter */ - public DestinyClass getD2class() { + public DestinyClass getD2class() throws APIException { if (d2class == null) { d2class = evaluateClass(getJO().get("classHash").getAsString()); } @@ -169,7 +169,7 @@ public DestinyClass getD2class() { * * @return */ - public String getEmblemPath() { + public String getEmblemPath() throws APIException { if (emblemPath == null) { emblemPath = getJO().get("emblemPath").getAsString(); } @@ -180,7 +180,7 @@ public String getEmblemPath() { * Get the background of the currently equipped emblem * Add this path to the end of "https://bungie.net/" */ - public String getEmblemBackgroundPath() { + public String getEmblemBackgroundPath() throws APIException { if (emblemBackgroundPath == null) { emblemBackgroundPath = getJO().get("emblemBackgroundPath").getAsString(); } @@ -190,7 +190,7 @@ public String getEmblemBackgroundPath() { /** * Get the hash of the currently equipped emblem to be used in a manifest request */ - public String getEmblemHash() { + public String getEmblemHash() throws APIException { if (emblemHash == null) { emblemHash = getJO().get("emblemHash").getAsString(); } @@ -200,7 +200,7 @@ public String getEmblemHash() { /** * Get a list of the currently equipped items of this character */ - public List getEquippedItems() { + public List getEquippedItems() throws APIException { JsonArray jsonArray = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + getCharacterID() + "/?components=205").getAsJsonObject("Response").getAsJsonObject("equipment").getAsJsonObject("data").getAsJsonArray("items"); @@ -221,7 +221,7 @@ public InventoryItem getItemInSlot(InventoryItem.ItemLocation itemLocation) { } */ - public List getAllItemsInInventory() { + public List getAllItemsInInventory() throws APIException { JsonArray jsonArray = hu.urlRequestGETOauth("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + getCharacterID() + "/?components=201").getAsJsonObject("Response").getAsJsonObject("inventory").getAsJsonObject("data").getAsJsonArray("items"); @@ -249,7 +249,7 @@ public List getAllItemsInInventory() { return list; } - public List getLoadouts() { + public List getLoadouts() throws APIException { hu.urlRequestGETOauth(HttpUtils.URL_BASE + "/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + getCharacterID() + "/?components=206,201"); List loadouts = new ArrayList<>(); @@ -264,7 +264,7 @@ public List getLoadouts() { * Needs work because not all activities return the same JSON info * = */ - public List getAllActivities() { + public List getAllActivities() throws APIException { if (allActivities != null) { return allActivities; } allActivities = new ArrayList<>(); JsonObject jj = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Account/" + getMembershipID() + "/Character/" + getCharacterID() + "/Stats/AggregateActivityStats/"); @@ -275,7 +275,7 @@ public List getAllActivities() { } - private boolean hasPlayedInActivity(String pgcrId, List source) { + private boolean hasPlayedInActivity(String pgcrId, List source) throws APIException { for (Activity activity : source) { if (pgcrId.equals(activity.getInstanceId())) { return true; @@ -292,7 +292,7 @@ private boolean hasPlayedInActivity(String pgcrId, List source) { * * @return True or false depending on if the user played in it */ - public boolean hasPlayedInActivity(String pgcrId) { + public boolean hasPlayedInActivity(String pgcrId) throws APIException { List participantIds = new ArrayList<>(); new Activity(pgcrId).getParticipants().forEach(activityParticipant -> { @@ -302,7 +302,7 @@ public boolean hasPlayedInActivity(String pgcrId) { return participantIds.contains(getCharacterID()); } - private Gender evaluateGender(String genderHash) { + private Gender evaluateGender(String genderHash) throws APIException { JsonObject jj = hu.manifestGET(ManifestEntityTypes.GENDER, genderHash).getAsJsonObject("Response"); switch (jj.get("genderType").getAsString()) { case "0": @@ -313,7 +313,7 @@ private Gender evaluateGender(String genderHash) { return null; } - private DestinyClass evaluateClass(String classHash) { + private DestinyClass evaluateClass(String classHash) throws APIException { JsonObject jj = hu.manifestGET(ManifestEntityTypes.CLASS, classHash).getAsJsonObject("Response"); switch (jj.getAsJsonObject("displayProperties").get("name").getAsString()) { case "Warlock": @@ -326,7 +326,7 @@ private DestinyClass evaluateClass(String classHash) { return null; } - private Race evaluateRace(String raceHash) { + private Race evaluateRace(String raceHash) throws APIException { JsonObject jj = hu.manifestGET(ManifestEntityTypes.RACE, raceHash).getAsJsonObject("Response"); switch (jj.getAsJsonObject("displayProperties").get("name").getAsString()) { case "Exo": diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java index 149ce0f..2b732e3 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java index 6b78b22..bf24131 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.user; import com.google.gson.JsonElement; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java index 225c915..9c50f1e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java index f2d8cfa..513512a 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java b/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java index 6eb223b..23365d7 100644 --- a/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java +++ b/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.responses.user; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java index d35dd2c..646cccc 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java @@ -1,15 +1,15 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.HttpUtils; import net.dec4234.javadestinyapi.utils.StringUtils; @@ -68,7 +68,7 @@ public Activity(String activityId, String referenceId, String directoryActivityH * * @return */ - public Date getDatePlayed() { + public Date getDatePlayed() throws APIException { checkJO(); return time == null ? time = StringUtils.valueOfZTime(getJO().get("period").getAsString()) : time; } @@ -78,7 +78,7 @@ public Date getDatePlayed() { * * @return */ - public String getReferenceId() { + public String getReferenceId() throws APIException { checkJO(); return referenceId == null ? referenceId = getJO().getAsJsonObject("activityDetails").get("referenceId").getAsString() : referenceId; } @@ -86,7 +86,7 @@ public String getReferenceId() { /** * Get the director activity hash (the type of activity played?) */ - public String getDirectoryActivityHash() { + public String getDirectoryActivityHash() throws APIException { checkJO(); return directoryActivityHash == null ? directoryActivityHash = getJO().getAsJsonObject("activityDetails").get("directorActivityHash").getAsString() : directoryActivityHash; } @@ -95,7 +95,7 @@ public String getDirectoryActivityHash() { * Gets the instance id, which happens to be the same as the activityId :) * = */ - public String getInstanceId() { + public String getInstanceId() throws APIException { checkJO(); return activityId == null ? activityId = getJO().get("instanceId").getAsString() : activityId; } @@ -103,7 +103,7 @@ public String getInstanceId() { /** * Get the mode number of the Activity */ - private int getModeNumber() { + private int getModeNumber() throws APIException { checkJO(); return mode == -1 ? mode = getJO().getAsJsonObject("activityDetails").get("mode").getAsInt() : mode; } @@ -113,7 +113,7 @@ private int getModeNumber() { * Mode list on this page * https://bungie-net.github.io/multi/schema_Destiny-Definitions-DestinyActivityDefinition.html */ - public ActivityMode getMode() { + public ActivityMode getMode() throws APIException { checkJO(); for (ActivityMode am : ActivityMode.values()) { if (am.getBungieValue() == getModeNumber()) { @@ -128,7 +128,7 @@ public ActivityMode getMode() { * * @return */ - public List getParticipants() { + public List getParticipants() throws APIException { List temp = new ArrayList<>(); try { @@ -145,7 +145,7 @@ public List getParticipants() { /** * If you need to get data not inside of this class */ - public JsonObject getJsonObject() { + public JsonObject getJsonObject() throws APIException { checkJO(); return getJO(); } diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java index e966e9f..d10d167 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; @@ -11,6 +10,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.clan.Clan; import net.dec4234.javadestinyapi.material.clan.ClanMember; @@ -26,7 +26,7 @@ public class ActivityHistoryReview { private HttpUtils httpUtils = DestinyAPI.getHttpUtils(); - public LinkedHashMap getMostUnrecentAttempts(Clan clan, ActivityIdentifier activityIdentifier) { + public LinkedHashMap getMostUnrecentAttempts(Clan clan, ActivityIdentifier activityIdentifier) throws APIException { HashMap map = new HashMap<>(); HashMap doubleMap = new HashMap<>(); LinkedHashMap toReturn = new LinkedHashMap<>(); @@ -79,7 +79,7 @@ public int compare(Map.Entry o1, /** * Takes a very long time */ - public double getAverageCompletions(Clan clan, ActivityIdentifier activityIdentifier) { + public double getAverageCompletions(Clan clan, ActivityIdentifier activityIdentifier) throws APIException { List members = clan.getMembers(); double count = 0; @@ -90,7 +90,7 @@ public double getAverageCompletions(Clan clan, ActivityIdentifier activityIdenti return count / members.size(); } - public LinkedHashMap getTopClearers(Clan clan, ActivityIdentifier activityIdentifier) { + public LinkedHashMap getTopClearers(Clan clan, ActivityIdentifier activityIdentifier) throws APIException { HashMap map = new HashMap<>(); LinkedHashMap toReturn = new LinkedHashMap<>(); @@ -114,7 +114,7 @@ public int compare(Map.Entry o1, return toReturn; } - public int getCompletions(BungieUser bungieUser, ActivityIdentifier activityIdentifier) { + public int getCompletions(BungieUser bungieUser, ActivityIdentifier activityIdentifier) throws APIException { int count = 0; for (DestinyCharacter destinyCharacter : bungieUser.getCharacters()) { @@ -124,7 +124,7 @@ public int getCompletions(BungieUser bungieUser, ActivityIdentifier activityIden return count; } - public int getCompletions(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) { + public int getCompletions(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) throws APIException { int count = 0; for (JsonArray ja : getArrays(activityIdentifier, bungieUser, destinyCharacter)) { @@ -143,7 +143,7 @@ public int getCompletions(ActivityIdentifier activityIdentifier, BungieUser bung return count; } - public boolean hasPlayedInActivity(BungieUser bungieUser, String pgcrId) { + public boolean hasPlayedInActivity(BungieUser bungieUser, String pgcrId) throws APIException { Activity activity = new Activity(pgcrId); for (ActivityParticipant activityParticipant : activity.getParticipants()) { if (activityParticipant.getMembershipId().equals(bungieUser.getID())) { @@ -154,7 +154,7 @@ public boolean hasPlayedInActivity(BungieUser bungieUser, String pgcrId) { return false; } - public void getUndiscoveredActivityHashes(BungieUser bungieUser, ActivityIdentifier activityIdentifier) { + public void getUndiscoveredActivityHashes(BungieUser bungieUser, ActivityIdentifier activityIdentifier) throws APIException { for (DestinyCharacter destinyCharacter : bungieUser.getCharacters()) { for (int i = 0; i < 25; i++) { JsonObject jo = httpUtils.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getID() + "/Character/" + destinyCharacter.getCharacterID() + "/Stats/Activities/?page=" + i + "&count=250&mode=" + activityIdentifier.getMode().getBungieValue()); @@ -181,7 +181,7 @@ public void getUndiscoveredActivityHashes(BungieUser bungieUser, ActivityIdentif } } - private JsonArray[] getArrays(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) { + private JsonArray[] getArrays(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) throws APIException { List jsonArrays = new ArrayList<>(); for (int i = 0; i < Integer.MAX_VALUE; i++) { diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java index 5ebfe80..c8ea8e3 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java index 8e29b98..9319387 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java @@ -1,14 +1,14 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; @@ -19,7 +19,7 @@ public class ActivityInfo extends ContentFramework { private ActivityMode activityMode; private boolean hasIcon, isPlaylist, inheritFromFreeRoam, suppressOtherRewards, isMatchmade, requiresGuardianOath, isPvP; - public ActivityInfo(String hash) { + public ActivityInfo(String hash) throws APIException { super(ManifestEntityTypes.ACTIVITY, hash, source -> { return source.getAsJsonObject("Response"); }); @@ -72,11 +72,11 @@ public ActivityInfo(String hash) { this.requiresGuardianOath = getMatchmaking().get("requiresGuardianOath").getAsBoolean(); } - public JsonObject getDisplayProperties() { + public JsonObject getDisplayProperties() throws APIException { return getJO().getAsJsonObject("displayProperties"); } - public JsonObject getMatchmaking() { + public JsonObject getMatchmaking() throws APIException { return getJO().getAsJsonObject("matchmaking"); } diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java index 22eff29..26a6c84 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java index bcc0c33..1532f7c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java b/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java index e78b92b..973d42d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java @@ -1,14 +1,14 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.character; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; @@ -32,7 +32,7 @@ public class UserStats { /** * Gets stats for this user's entire account */ - public UserStats(BungieUser bungieUser) { + public UserStats(BungieUser bungieUser) throws APIException { this.bungieUser = bungieUser; jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getID() + "/Stats/").getAsJsonObject("Response").getAsJsonObject("mergedAllCharacters").getAsJsonObject("results"); allPve = jo.getAsJsonObject("allPvE").getAsJsonObject("allTime"); @@ -41,7 +41,7 @@ public UserStats(BungieUser bungieUser) { /** * Gets stats for this user's specific character */ - public UserStats(BungieUser bungieUser, DestinyCharacter destinyCharacter) { + public UserStats(BungieUser bungieUser, DestinyCharacter destinyCharacter) throws APIException { this.bungieUser = bungieUser; jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getID() + "/Character/" + destinyCharacter.getCharacterID() + "/Stats/").getAsJsonObject("Response"); allPve = jo.getAsJsonObject("allPvE").getAsJsonObject("allTime"); diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java index 2cab98b..30574cb 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java index d00ffb3..0c32e1e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java @@ -1,17 +1,22 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.exceptions.APIOfflineException; -import net.dec4234.javadestinyapi.exceptions.AccessTokenInvalidException; +import net.dec4234.javadestinyapi.exceptions.AccessTokenExpiredException; +import net.dec4234.javadestinyapi.exceptions.ConnectionException; +import net.dec4234.javadestinyapi.exceptions.JsonParsingError; +import net.dec4234.javadestinyapi.exceptions.OAuthUnauthorizedException; +import net.dec4234.javadestinyapi.exceptions.RefreshTokenExpiredException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -45,27 +50,36 @@ public void setApiKey(String apiKey) { /** * Send a GET url request to the url provided, returns a JsonObject of the response */ - public JsonObject urlRequestGET(String url) { - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { + public JsonObject urlRequestGET(String url) throws APIException { + return getJsonObject(getRequest(true, url, starter -> { starter.GET(); return starter; - }))); + })); } - public JsonObject urlRequestGETOauth(String url) { - setTokenViaRefresh(); - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { - starter.GET() - .setHeader("Authorization", "Bearer " + HttpUtils.bearerToken); - return starter; - }))); + public JsonObject urlRequestGETOauth(String url) throws APIException { + try { + return getJsonObject(getRequest(true, url, starter -> { + starter.GET() + .setHeader("Authorization", "Bearer " + HttpUtils.bearerToken); + return starter; + })); + } catch (AccessTokenExpiredException e) { + setTokenViaRefresh(); + + return getJsonObject(getRequest(true, url, starter -> { + starter.GET() + .setHeader("Authorization", "Bearer " + HttpUtils.bearerToken); + return starter; + })); + } } - public JsonObject urlRequestPOST(String url, JsonObject body) { + public JsonObject urlRequestPOST(String url, JsonObject body) throws APIException { return urlRequestPOST(url, body.toString()); } - public JsonObject urlRequestPOST(String url, String body) { + public JsonObject urlRequestPOST(String url, String body) throws APIException { if (body.isEmpty()) { body = "{\"message\": \"\",}"; } String finalBody = body; @@ -73,34 +87,15 @@ public JsonObject urlRequestPOST(String url, String body) { System.out.println("Body: " + finalBody); } - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { + return getJsonObject(getRequest(true, url, starter -> { starter.setHeader("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(finalBody)); - return starter; - }))); - } - - public String urlRequestPOSTOauth(String url, String body) { - setTokenViaRefresh(); - if (body.isEmpty()) { body = "{\"message\": \"\",}"; } - - String finalBody = body; - - if(DestinyAPI.isDebugEnabled()) { - System.out.println("Body: " + finalBody); - } - - return getStringResponse(getRequest(true, url, starter -> { - starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) - .setHeader("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(finalBody)); - return starter; })); } - public JsonObject urlRequestPOSTOauth(String url, JsonObject body) { + public JsonObject urlRequestPOSTOauth(String url, JsonObject body) throws APIException { setTokenViaRefresh(); if (body.toString().isEmpty()) { body = new JsonObject(); @@ -113,13 +108,28 @@ public JsonObject urlRequestPOSTOauth(String url, JsonObject body) { System.out.println("Body: " + finalBody); } - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { - starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) - .setHeader("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(finalBody)); + try { + return getJsonObject(getRequest(true, url, starter -> { + starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) + .setHeader("Content-Type", "application/json") + .POST(HttpRequest.BodyPublishers.ofString(finalBody)); + + return starter; + })); + } catch (AccessTokenExpiredException e) { + setTokenViaRefresh(); + return getJsonObject(getRequest(true, url, starter -> { + starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) + .setHeader("Content-Type", "application/json") + .POST(HttpRequest.BodyPublishers.ofString(finalBody)); + + return starter; + })); + } + } - return starter; - }))); + public JsonObject urlRequestPOSTOauth(String url) throws APIException { + return urlRequestPOSTOauth(url, new JsonObject()); } /** @@ -128,7 +138,7 @@ public JsonObject urlRequestPOSTOauth(String url, JsonObject body) { * Deprecated in favor of DestinyManifest#manifestGET() */ @Deprecated - public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentifier) { + public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentifier) throws APIException { return urlRequestGET("https://www.bungie.net/Platform/Destiny2/Manifest/" + entityType.getBungieEntityValue() + "/" + hashIdentifier + "/"); } @@ -137,18 +147,22 @@ public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentif * * @return Returns the new access token */ - public String setTokenViaRefresh() { + public String setTokenViaRefresh() throws APIException { String url = "https://www.bungie.net/Platform/App/OAuth/Token/"; String requestBody = "grant_type=refresh_token&refresh_token=" + DestinyAPI.getRefreshToken(); - JsonObject response = getJsonObject(getStringResponse(getRequest(false, url, starter -> { + JsonObject response = getJsonObject(getRequest(false, url, starter -> { starter.setHeader("Content-Type", "application/x-www-form-urlencoded") .setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((DestinyAPI.getClientId() + ":" + DestinyAPI.getClientSecret()).getBytes())) .POST(HttpRequest.BodyPublishers.ofString(requestBody)); return starter; - }))); + })); + + if(response.has("error_description") && response.get("error_description").getAsString().equals("ApplicationTokenKeyIdDoesNotExist")) { + throw new RefreshTokenExpiredException(); + } if(!response.has("access_token")) { return null; @@ -159,28 +173,32 @@ public String setTokenViaRefresh() { bearerToken = at; new DestinyAPI().setAccessToken(at).setRefreshToken(rt); + if(DestinyAPI.isDebugEnabled()) { + System.out.println("TOKENS REFRESHED"); + } + return at; } /** * Requries an OAuthCode to be manually set inside of the DestinyAPI.setOAuthCode() */ - public void setTokenViaAuth() { + public void setTokenViaAuth() throws APIException { setTokenViaAuth(DestinyAPI.getOauthCode()); } - public void setTokenViaAuth(String oAuthCode) { + public void setTokenViaAuth(String oAuthCode) throws APIException { String url = "https://www.bungie.net/Platform/App/OAuth/Token/"; String requestBody = "grant_type=authorization_code&code=" + oAuthCode; - JsonObject jsonObject = getJsonObject(getStringResponse(getRequest(false, url, starter -> { + JsonObject jsonObject = getJsonObject(getRequest(false, url, starter -> { starter.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((DestinyAPI.getClientId() + ":" + DestinyAPI.getClientSecret()).getBytes())) .setHeader("Content-Type", "application/x-www-form-urlencoded") .POST(HttpRequest.BodyPublishers.ofString(requestBody)); return starter; - }))); + })); String accessToken = jsonObject.get("access_token").getAsString(); String refreshToken = jsonObject.get("refresh_token").getAsString(); @@ -190,49 +208,59 @@ public void setTokenViaAuth(String oAuthCode) { HttpUtils.bearerToken = accessToken; } - public boolean checkFor401(String input) { - if (input.contains("401 - Unauthorized")) { - try { - setTokenViaRefresh(); - throw new AccessTokenInvalidException("The access token used in this OAuth request was not accepted by the server \nI've already taken the liberty of getting a new access token for you :D"); - } catch (AccessTokenInvalidException e) { - e.printStackTrace(); - return true; + private JsonObject getJsonObject(HttpRequest httpRequest) throws APIException { + HttpClient httpClient = HttpClient.newHttpClient(); + String responseString; + + try { // TODO: are we even taking advantage of async? this seems pointless to just block right away + responseString = httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body).get(); + + if (DestinyAPI.isDebugEnabled()) { + System.out.println(httpRequest.method() + " " + httpRequest.uri().toString()); + System.out.println(responseString); } + } catch (InterruptedException | ExecutionException e) { + throw new ConnectionException(e); } - return false; - } + JsonObject jsonObject; - private JsonObject getJsonObject(String stringResponse) { - JsonObject jsonObject = new JsonParser().parse(stringResponse).getAsJsonObject(); + try { + jsonObject = JsonParser.parseString(responseString).getAsJsonObject(); + } catch (JsonSyntaxException e) { + throw new JsonParsingError(e); + } - // API Offline Check - if(jsonObject.has("ErrorCode") && jsonObject.get("ErrorCode").getAsInt() == 5) { - try { - throw new APIOfflineException(jsonObject.get("Message").getAsString()); - } catch (APIOfflineException exception) { - exception.printStackTrace(); + // Check for API errors - https://bungie-net.github.io/multi/schema_Exceptions-PlatformErrorCodes.html#schema_Exceptions-PlatformErrorCodes + if(jsonObject.has("ErrorCode")) { + switch (jsonObject.get("ErrorCode").getAsInt()) { //TODO: lots of errors we could catch here + case 5: // APIOffline + throw new APIOfflineException(jsonObject.get("Message").getAsString()); + case 99: // WebAuthRequired + throw new OAuthUnauthorizedException("OAuth - access denied. Try authenticating."); + case 2111 | 2115: // AccessTokenHasExpired, OAuthAccessTokenExpired + throw new AccessTokenExpiredException(); + case 2118: // RefreshTokenExpired -- need to reauth using oauth + throw new RefreshTokenExpiredException(); } } + return jsonObject; } - private String getStringResponse(HttpRequest httpRequest) { + private String getStringResponse(HttpRequest httpRequest) throws ConnectionException { HttpClient httpClient = HttpClient.newHttpClient(); try { String responseString = httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body).get(); if (DestinyAPI.isDebugEnabled()) { System.out.println(httpRequest.method() + " " + httpRequest.uri().toString()); - System.out.println(responseString); + System.out.println("Response: " + responseString); } return responseString; } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + throw new ConnectionException(e); } - - return null; } private HttpRequest getRequest(boolean standardRequest, String url, HttpRequestModifier httpRequestModifier) { diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java index 2cfe989..24b1e4d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java @@ -1,14 +1,15 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils; import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseException; @@ -21,7 +22,6 @@ public class StringUtils { /** * @param zuluTimeInString The Zulu time, in the form of a String, you wish to convert * @return Returns a date object representing the Zulu time provided - * @throws ParseException */ public static Date valueOfZTime(String zuluTimeInString) { String temp = zuluTimeInString; @@ -33,10 +33,9 @@ public static Date valueOfZTime(String zuluTimeInString) { df.setTimeZone(TimeZone.getTimeZone("Zulu")); try { return df.parse(temp); - } catch (ParseException e) { - e.printStackTrace(); + } catch (ParseException e) { // TODO: log error here + return null; } - return null; } /** @@ -53,7 +52,7 @@ public static double getDaysSinceTime(Date date) { * Specific characters need to be encoded in order to have a successful request */ public static String httpEncode(String input) { - return input.replace(" ", "%20").replace("#", "%23").replace("^", "%5E"); + return URLEncoder.encode(input, StandardCharsets.UTF_8); } public static void executeCommandLine(String command) { diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java index 1902fb3..8135626 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.fast; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java index 9081bde..344697d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.fast; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java index 94956a5..a7ee892 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java @@ -1,14 +1,14 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -39,7 +39,7 @@ public ContentFramework(ManifestEntityTypes manifestType, String url, JsonObject } @Override - public void checkJO() { + public void checkJO() throws APIException { if(jo == null) { if(manifestType == null) { jo = DestinyAPI.getHttpUtils().urlRequestGET(url); @@ -52,7 +52,7 @@ public void checkJO() { /** * Refresh the jsonobject to potentially account for new changes */ - public void refreshJO() { + public void refreshJO() throws APIException { if(manifestType == null) { jo = DestinyAPI.getHttpUtils().urlRequestGET(url); } else { @@ -60,7 +60,7 @@ public void refreshJO() { } } - public JsonObject getJO() { + public JsonObject getJO() throws APIException { checkJO(); return jsonObjectModifier.modify(jo); } diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java index 901c98f..88626fd 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java @@ -1,18 +1,19 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; +import net.dec4234.javadestinyapi.exceptions.APIException; + public interface ContentInterface { /** * Used to verify if the raw JsonObject has been initialized * Initialize the JsonObject from here if it is not initialized */ - void checkJO(); + void checkJO() throws APIException; } diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java index 240eea4..d58f2b4 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java @@ -1,13 +1,18 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; +/** + * Contains all of the functions needed for the API to adequately store OAuth tokens. + *
+ * Note: OAuth could allow potenially dangerous actions such as full control over your clan (if you are an admin) as + * well as your inventory. Use at your own risk, and use good data management and protection practices. + */ public interface JDAOAuth { String getAccessToken(); diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java index 50bc091..d65661d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java index 96c7036..9379e35 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java @@ -1,14 +1,15 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; import com.sun.net.httpserver.*; +import net.dec4234.javadestinyapi.exceptions.APIException; +import net.dec4234.javadestinyapi.exceptions.InvalidConditionException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.StringUtils; @@ -23,6 +24,29 @@ import java.security.KeyStore; import java.util.concurrent.Executors; +/** + * The OAuthFlow class allows a user to easily generate oauth tokens for a small project that is not distributed to + * external users. This class could be replicated by an experienced user to allow for handling multiple oauth tokens. + *

+ * Note: OAuth could allow potenially dangerous actions such as full control over your clan (if you are an admin) as + * well as your inventory. Use at your own risk, and use good data management and protection practices. + *

+ * Here is the process:
+ * 1. Go to your app on https://www.bungie.net/en/Application
+ * 2. Under "App authentication" set the client type to confidential and set the redirect to something like + * "https://localhost:8080". Note that is MUST be HTTPS not HTTP
+ * 3. Adjust the permissions for the app using the checkboxes right below it.
+ * 4. Use the following code to init your oauth tokens. + *

{@code
+ * OAuthFlow oAuthFlow = new OAuthFlow();
+ * oAuthFlow.initOAuthFlowIfNeeded(8080);
+ * }
+ * This will open the browser on your local machine where it will direct you to do oauth. It might say that the site is + * unsafe since it doesn't have a valid certificate. On chrome, click the "advanced" button and then "continue". You + * should now be able to perform OAuth requests and all the interesting things you can build with it.
+ * 5.(Optionally) When initializing the DestinyAPI you can use {@link DestinyAPI#setOauthManager(OAuthManager)} to save + * the tokens however you want, so you don't have to oauth frequently. + */ public class OAuthFlow { // keytool -genkey -dname "cn=dec 4234, ou=github/JavaDestinyAPI, o=ou=github/JavaDestinyAPI, c=US" -keyalg RSA -alias alias -keystore keystore.jks -storepass mypassword -keypass mypassword -validity 360 -keysize 2048 @@ -39,7 +63,7 @@ public class OAuthFlow { * 4. Sets the tokens using that information * @param port The port to start the server on */ - public void initOAuthFlow(int port) { + public void initOAuthFlow(int port) throws APIException { setTokens(port); } @@ -47,13 +71,17 @@ public void initOAuthFlow(int port) { * Initiate the OAuth Flow only if an exisiting key cannot be found or if it has expired * @param port The port to start the server on */ - public void initOAuthFlowIfNeeded(int port) { - if(!DestinyAPI.hasOauthManager() || DestinyAPI.getAccessToken() == null || DestinyAPI.getHttpUtils().setTokenViaRefresh() == null) { + public void initOAuthFlowIfNeeded(int port) throws APIException { + try { + if(!DestinyAPI.hasOauthManager() || DestinyAPI.getAccessToken() == null || DestinyAPI.getHttpUtils().setTokenViaRefresh() == null) { + initOAuthFlow(port); + } + } catch (InvalidConditionException e) { initOAuthFlow(port); } } - private void setTokens(int serverPort) { + private void setTokens(int serverPort) throws APIException { openOAuthPage(); startSecureServer(serverPort); diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java index cb91d64..468ca0e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java @@ -1,12 +1,18 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; +/** + * Used to direct the storage of OAuth tokens using the user's own code. See {@link OAuthFlow} and {@link JDAOAuth} for + * more info. + *
+ * Note: OAuth could allow potenially dangerous actions such as full control over your clan (if you are an admin) as + * well as your inventory. Use at your own risk, and use good data management and protection practices. + */ public abstract class OAuthManager implements JDAOAuth { }