Skip to content

Commit 026f740

Browse files
committed
getMemberFromSteamID, ContentFramework and beta ActivityInfo
1 parent 4286fff commit 026f740

File tree

6 files changed

+249
-7
lines changed

6 files changed

+249
-7
lines changed

src/main/java/material/DestinyAPI.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ public static boolean hasOauthManager() {
9090

9191
public static BungieUser getUser(String id) { return new BungieUser(id); }
9292

93+
/**
94+
* Get a BungieUser from a Steam ID
95+
* NOT the same IDs used by Bungie to identify individual users
96+
*/
97+
public static BungieUser getMemberFromSteamID(String steamID) {
98+
return getMemberFromPlatformID("SteamId", steamID);
99+
}
100+
101+
private static BungieUser getMemberFromPlatformID(String platformName, String platformID) {
102+
JsonObject jsonObject = new HttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/GetMembershipFromHardLinkedCredential/" + platformName + "/" + platformID + "/").getAsJsonObject("Responseg");
103+
104+
return new BungieUser(jsonObject.get("membershipId").getAsString());
105+
}
106+
93107
/**
94108
* Gets the users with this name (There can be multiple users with the same name)
95109
*/

src/main/java/material/stats/Activity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
/**
2222
* An activity in this case is a PGCR (Post Game Carnage Report)
2323
* It contains data about an activity that happened like a raid or crucible match
24+
*
25+
* Can not retrieve info about Activities that have not ended yet
2426
*/
2527
public class Activity extends ContentFramework {
2628

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*
2+
* Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of
3+
* any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or
4+
* ownership of this software without the explicit permission of the author.
5+
*
6+
* GitHub -> https://github.com/dec4234/JavaDestinyAPI
7+
*/
8+
9+
package material.stats;
10+
11+
import com.google.gson.JsonObject;
12+
import material.manifest.ManifestEntityTypes;
13+
import utils.framework.ContentFramework;
14+
15+
public class ActivityInfo extends ContentFramework {
16+
17+
private String name, hash, completionUnlockHash, destinationHash, placeHash, activityTypeHash, activityModeHash, description, icon, pgcrImage, releaseIcon;
18+
private int modeType, activityModeCategory, releaseTime, activityLightLevel, tier, minParty, maxParty, maxPlayers;
19+
private ActivityMode activityMode;
20+
private boolean hasIcon, isPlaylist, inheritFromFreeRoam, suppressOtherRewards, isMatchmade, requiresGuardianOath, isPvP;
21+
22+
public ActivityInfo(String hash) {
23+
super(ManifestEntityTypes.ACTIVITY, hash, source -> {
24+
return source.getAsJsonObject("Response");
25+
});
26+
27+
// Intialize values of the Activity Mode
28+
this.name = getDisplayProperties().get("name").getAsString();
29+
this.description = getDisplayProperties().get("description").getAsString();
30+
31+
this.hasIcon = getDisplayProperties().get("hasIcon").getAsBoolean();
32+
33+
if(hasIcon) {
34+
icon = getDisplayProperties().get("icon").getAsString();
35+
}
36+
37+
// this.pgcrImage = getJO().get("pgcrImage").getAsString();
38+
this.releaseIcon = getJO().get("releaseIcon").getAsString();
39+
40+
// Hashes
41+
this.hash = hash;
42+
this.completionUnlockHash = getJO().get("completionUnlockHash").getAsString();
43+
this.destinationHash = getJO().get("destinationHash").getAsString();
44+
this.placeHash = getJO().get("placeHash").getAsString();
45+
this.activityTypeHash = getJO().get("activityTypeHash").getAsString();
46+
// this.activityModeHash = getJO().get("activityModeHash").getAsString();
47+
48+
// Numbers
49+
this.modeType = getJO().get("directActivityModeType").getAsInt();
50+
this.activityMode = ActivityMode.fromBungieValue(modeType);
51+
this.activityModeCategory = getJO().get("activityModeCategory").getAsInt();
52+
this.releaseTime = getJO().get("releaseTime").getAsInt();
53+
this.tier = getJO().get("tier").getAsInt();
54+
this.activityLightLevel = getJO().get("activityLightLevel").getAsInt();
55+
56+
// Random booleans
57+
this.isPlaylist = getJO().get("isPlaylist").getAsBoolean();
58+
this.inheritFromFreeRoam = getJO().get("inheritFromFreeRoam").getAsBoolean();
59+
this.suppressOtherRewards = getJO().get("suppressOtherRewards").getAsBoolean();
60+
this.isPvP = getJO().get("isPvP").getAsBoolean();
61+
62+
// Matchmaking
63+
this.isMatchmade = getMatchmaking().get("isMatchmade").getAsBoolean();
64+
this.minParty = getMatchmaking().get("minParty").getAsInt();
65+
this.maxParty = getMatchmaking().get("maxParty").getAsInt();
66+
this.maxPlayers = getMatchmaking().get("maxPlayers").getAsInt();
67+
this.requiresGuardianOath = getMatchmaking().get("requiresGuardianOath").getAsBoolean();
68+
}
69+
70+
public JsonObject getDisplayProperties() {
71+
return getJO().getAsJsonObject("displayProperties");
72+
}
73+
74+
public JsonObject getMatchmaking() {
75+
return getJO().getAsJsonObject("matchmaking");
76+
}
77+
78+
public String getName() {
79+
return name;
80+
}
81+
82+
public String getHash() {
83+
return hash;
84+
}
85+
86+
public String getCompletionUnlockHash() {
87+
return completionUnlockHash;
88+
}
89+
90+
public String getDestinationHash() {
91+
return destinationHash;
92+
}
93+
94+
public String getPlaceHash() {
95+
return placeHash;
96+
}
97+
98+
public String getActivityTypeHash() {
99+
return activityTypeHash;
100+
}
101+
102+
public String getActivityModeHash() {
103+
return activityModeHash;
104+
}
105+
106+
public String getDescription() {
107+
return description;
108+
}
109+
110+
public String getIcon() {
111+
return icon;
112+
}
113+
114+
public String getPgcrImage() {
115+
return pgcrImage;
116+
}
117+
118+
public String getReleaseIcon() {
119+
return releaseIcon;
120+
}
121+
122+
public int getModeType() {
123+
return modeType;
124+
}
125+
126+
public int getActivityModeCategory() {
127+
return activityModeCategory;
128+
}
129+
130+
public int getReleaseTime() {
131+
return releaseTime;
132+
}
133+
134+
public int getActivityLightLevel() {
135+
return activityLightLevel;
136+
}
137+
138+
public int getTier() {
139+
return tier;
140+
}
141+
142+
public int getMinParty() {
143+
return minParty;
144+
}
145+
146+
public int getMaxParty() {
147+
return maxParty;
148+
}
149+
150+
public int getMaxPlayers() {
151+
return maxPlayers;
152+
}
153+
154+
public ActivityMode getActivityMode() {
155+
return activityMode;
156+
}
157+
158+
public boolean isHasIcon() {
159+
return hasIcon;
160+
}
161+
162+
public boolean isPlaylist() {
163+
return isPlaylist;
164+
}
165+
166+
public boolean isInheritFromFreeRoam() {
167+
return inheritFromFreeRoam;
168+
}
169+
170+
public boolean isSuppressOtherRewards() {
171+
return suppressOtherRewards;
172+
}
173+
174+
public boolean isMatchmade() {
175+
return isMatchmade;
176+
}
177+
178+
public boolean isRequiresGuardianOath() {
179+
return requiresGuardianOath;
180+
}
181+
182+
public boolean isPvP() {
183+
return isPvP;
184+
}
185+
}

src/main/java/material/stats/ActivityMode.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,14 @@ private ActivityMode(int bungieValue) {
9191
public int getBungieValue() {
9292
return bungieValue;
9393
}
94+
95+
public static ActivityMode fromBungieValue(int bungieValue) {
96+
for(ActivityMode activityMode : ActivityMode.values()) {
97+
if(activityMode.getBungieValue() == bungieValue) {
98+
return activityMode;
99+
}
100+
}
101+
102+
return null;
103+
}
94104
}

src/main/java/material/user/BungieUser.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.gson.JsonElement;
1313
import com.google.gson.JsonObject;
1414
import material.clan.Clan;
15+
import material.stats.ActivityInfo;
1516
import utils.HttpUtils;
1617
import utils.StringUtils;
1718

@@ -24,8 +25,6 @@
2425

2526
public class BungieUser {
2627

27-
private boolean isValidUser;
28-
2928
private String bungieMembershipID;
3029
private String displayName;
3130
private Date lastPlayed;
@@ -181,8 +180,8 @@ public int getTimePlayed() {
181180
public Clan getClan() {
182181
if (clan != null) { return clan; }
183182

184-
JsonObject jo = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/User/" + getMembershipType() + "/" + getBungieMembershipID() + "/0/1/?components=200").get("Response").getAsJsonObject();
185-
clan = new Clan(jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("group").getAsJsonObject().get("groupId").getAsLong());
183+
JsonObject jo = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/User/" + getMembershipType() + "/" + getBungieMembershipID() + "/0/1/?components=200").getAsJsonObject("Response");
184+
clan = new Clan(jo.get("results").getAsJsonArray().get(0).getAsJsonObject().getAsJsonObject("group").get("groupId").getAsLong());
186185
return clan;
187186
}
188187

@@ -195,6 +194,26 @@ public void allowClanInvites(boolean allowInvites) {
195194

196195
}
197196

197+
/**
198+
* Return a lot of information pertaining to the activity the user is currently in
199+
* E.g. If I am on the tower it will provide information about the ActivityMode and Icons related to it
200+
* @return Null if no information about the current activity is found
201+
*/
202+
public ActivityInfo getCurrentActivityInfo() {
203+
JsonObject data = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + getBungieMembershipID() + "/?components=204").getAsJsonObject("Response").getAsJsonObject("characterActivities").getAsJsonObject("data");
204+
205+
for(DestinyCharacter character : getCharacters()) {
206+
if(data.has(character.getCharacterID())) {
207+
String hash = data.getAsJsonObject(character.getCharacterID()).get("currentActivityHash").getAsString();
208+
if (!hash.equals("0")) {
209+
return new ActivityInfo(hash);
210+
}
211+
}
212+
}
213+
214+
return null;
215+
}
216+
198217
/**
199218
* Request to join the specified clan
200219
*/

src/main/java/utils/framework/ContentFramework.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package utils.framework;
1010

1111
import com.google.gson.JsonObject;
12+
import material.manifest.ManifestEntityTypes;
1213
import utils.HttpUtils;
1314

1415
/**
@@ -17,23 +18,34 @@
1718
public class ContentFramework implements ContentInterface {
1819

1920
private String url;
20-
private JsonObject jo = null;
21+
private ManifestEntityTypes manifestType;
22+
protected JsonObject jo = null;
2123
private JsonObjectModifier jsonObjectModifier;
2224

2325
public ContentFramework(String url, JsonObjectModifier jsonObjectModifier) {
2426
this.url = url;
2527
this.jsonObjectModifier = jsonObjectModifier;
2628
}
2729

30+
public ContentFramework(ManifestEntityTypes manifestType, String url, JsonObjectModifier jsonObjectModifier) {
31+
this.manifestType = manifestType;
32+
this.url = url;
33+
this.jsonObjectModifier = jsonObjectModifier;
34+
}
35+
2836
@Override
2937
public void checkJO() {
3038
if(jo == null) {
31-
jo = jsonObjectModifier.modify(new HttpUtils().urlRequestGET(url));
39+
if(manifestType == null) {
40+
jo = new HttpUtils().urlRequestGET(url);
41+
} else {
42+
jo = new HttpUtils().manifestGET(manifestType, url);
43+
}
3244
}
3345
}
3446

3547
public JsonObject getJO() {
3648
checkJO();
37-
return jo;
49+
return jsonObjectModifier.modify(jo);
3850
}
3951
}

0 commit comments

Comments
 (0)