1616import material .stats .Activity ;
1717import utils .HttpUtils ;
1818import utils .StringUtils ;
19+ import utils .framework .ContentFramework ;
20+ import utils .framework .ContentInterface ;
1921
2022import java .util .ArrayList ;
2123import java .util .Date ;
2224import java .util .List ;
2325
24- public class DestinyCharacter {
26+ public class DestinyCharacter extends ContentFramework {
27+
28+ private BungieUser bungieUser ;
2529
26- private String membershipID ;
2730 private String characterID ;
2831 private Date lastPlayed ;
29- private String minutesPlayedThisSession ;
30- private String minutesPlayedTotal ;
31- private String lightLevel ;
32- private String membershipType ;
32+ private int minutesPlayedThisSession , minutesPlayedTotal , lightLevel = -1 ;
3333
3434 private Gender gender ;
3535 private DestinyClass d2class ;
3636 private Race race ;
3737
38- private String emblemPath ;
39- private String emblemBackgroundPath ;
40- private String emblemHash ;
38+ private String emblemPath , emblemBackgroundPath , emblemHash ;
4139
4240 private List <Activity > allActivities ;
4341
4442 HttpUtils hu = new HttpUtils ();
45- private JsonObject jo ;
4643
4744 public DestinyCharacter (BungieUser bungieUser , String characterID ) {
45+ super ("https://www.bungie.net/Platform/Destiny2/" + bungieUser .getMembershipType () + "/Profile/" + bungieUser .getBungieMembershipID () + "/Character/" + characterID + "/?components=200" ,
46+ source -> source .getAsJsonObject ("Response" ).getAsJsonObject ("character" ).getAsJsonObject ("data" ));
4847 this .characterID = characterID ;
49- jo = hu .urlRequestGET ("https://www.bungie.net/Platform/Destiny2/" + bungieUser .getMembershipType () + "/Profile/" + bungieUser .getBungieMembershipID () + "/Character/" + characterID + "/?components=200" ).getAsJsonObject ("Response" ).getAsJsonObject ("character" ).getAsJsonObject ("data" );
50- assignValues ();
48+ this .bungieUser = bungieUser ;
5149 }
5250
53- private void assignValues () {
54- membershipID = jo .get ("membershipId" ).getAsString ();
55- membershipType = jo .get ("membershipType" ).getAsString ();
56- characterID = jo .get ("characterId" ).getAsString ();
57- lastPlayed = StringUtils .valueOfZTime (jo .get ("dateLastPlayed" ).getAsString ());
58- minutesPlayedThisSession = jo .get ("minutesPlayedThisSession" ).getAsString ();
59- minutesPlayedTotal = jo .get ("minutesPlayedTotal" ).getAsString ();
60- lightLevel = jo .get ("light" ).getAsString ();
61-
62- race = evaluateRace (jo .get ("raceHash" ).getAsString ());
63- gender = evaluateGender (jo .get ("genderHash" ).getAsString ());
64- d2class = evaluateClass (jo .get ("classHash" ).getAsString ());
51+ public String getMembershipID () {
52+ return bungieUser .getBungieMembershipID ();
53+ }
6554
66- emblemPath = jo .get ("emblemPath" ).getAsString ();
67- emblemBackgroundPath = jo .get ("emblemBackgroundPath" ).getAsString ();
68- emblemHash = jo .get ("emblemHash" ).getAsString ();
55+ public int getMembershipType () {
56+ return bungieUser .getMembershipType ();
6957 }
7058
71- public String getMembershipID () { return membershipID ; }
72- public String getMembershipType () { return membershipType ; }
7359 public String getCharacterID () { return characterID ; }
74- public Date getLastPlayed () { return lastPlayed ; }
75- public String getMinutesPlayedThisSession () { return minutesPlayedThisSession ; }
76- public String getMinutesPlayedTotal () { return minutesPlayedTotal ; }
77- public String getLightLevel () { return lightLevel ; }
7860
79- public Race getRace () { return race ; }
80- public Gender getGender () { return gender ; }
81- public DestinyClass getD2class () { return d2class ; }
61+ public Date getLastPlayed () {
62+ if (lastPlayed == null ) {
63+ lastPlayed = StringUtils .valueOfZTime (getJO ().get ("dateLastPlayed" ).getAsString ());
64+ }
65+ return lastPlayed ;
66+ }
67+
68+ public int getMinutesPlayedThisSession () {
69+ if (minutesPlayedThisSession == -1 ) {
70+ minutesPlayedThisSession = getJO ().get ("minutesPlayedThisSession" ).getAsInt ();
71+ }
72+ return minutesPlayedThisSession ;
73+ }
74+
75+ public int getMinutesPlayedTotal () {
76+ if (minutesPlayedTotal == -1 ) {
77+ minutesPlayedTotal = getJO ().get ("minutesPlayedTotal" ).getAsInt ();
78+ }
79+ return minutesPlayedTotal ;
80+ }
81+
82+ public int getLightLevel () {
83+ if (lightLevel == -1 ) {
84+ lightLevel = getJO ().get ("light" ).getAsInt ();
85+ }
86+ return lightLevel ;
87+ }
88+
89+ public Race getRace () {
90+ if (race == null ) {
91+ race = evaluateRace (getJO ().get ("raceHash" ).getAsString ());
92+ }
93+ return race ;
94+ }
95+
96+ public Gender getGender () {
97+ if (gender == null ) {
98+ gender = evaluateGender (getJO ().get ("genderHash" ).getAsString ());
99+ }
100+ return gender ;
101+ }
102+
103+ public DestinyClass getD2class () {
104+ if (d2class == null ) {
105+ d2class = evaluateClass (getJO ().get ("classHash" ).getAsString ());
106+ }
107+ return d2class ;
108+ }
109+
110+ public String getEmblemPath () {
111+ if (emblemPath == null ) {
112+ emblemPath = getJO ().get ("emblemPath" ).getAsString ();
113+ }
114+ return emblemPath ;
115+ }
82116
83- public String getEmblemPath () { return emblemPath ; }
84- public String getEmblemBackgroundPath () { return emblemBackgroundPath ; }
85- public String getEmblemHash () { return emblemHash ; }
86- public JsonObject getJsonObject () { return jo ; }
117+ public String getEmblemBackgroundPath () {
118+ if (emblemBackgroundPath == null ) {
119+ emblemBackgroundPath = getJO ().get ("emblemBackgroundPath" ).getAsString ();
120+ }
121+ return emblemBackgroundPath ;
122+ }
123+
124+ public String getEmblemHash () {
125+ if (emblemHash == null ) {
126+ emblemHash = getJO ().get ("emblemHash" ).getAsString ();
127+ }
128+ return emblemHash ;
129+ }
130+
131+ public JsonObject getJsonObject () { return getJO (); }
87132
88133 public List <DestinyItem > getEquippedItems () {
89- JsonArray jsonArray = new HttpUtils ().urlRequestGET ("https://www.bungie.net/Platform/Destiny2/" + getMembershipType () + "/Profile/" + membershipID + "/Character/"
90- + getCharacterID () + "/?components=205" ).getAsJsonObject ("Response" ).getAsJsonObject ("equipment" ).getAsJsonObject ("data" ).getAsJsonArray ("items" );
134+ JsonArray jsonArray = new HttpUtils ().urlRequestGET ("https://www.bungie.net/Platform/Destiny2/" + getMembershipType () + "/Profile/" + bungieUser . getBungieMembershipID () + "/Character/"
135+ + getCharacterID () + "/?components=205" ).getAsJsonObject ("Response" ).getAsJsonObject ("equipment" ).getAsJsonObject ("data" ).getAsJsonArray ("items" );
91136
92137 List <DestinyItem > destinyItems = new ArrayList <>();
93138
94- for (JsonElement jsonElement : jsonArray ) {
139+ for (JsonElement jsonElement : jsonArray ) {
95140 destinyItems .add (new DestinyItem (jsonElement .getAsJsonObject ().get ("itemHash" ).getAsString ()));
96141 }
97142
@@ -101,20 +146,21 @@ public List<DestinyItem> getEquippedItems() {
101146 /**
102147 * A very resource intensive task, use at your own risk
103148 * Needs work because not all activities return the same JSON info
104- = */
149+ * =
150+ */
105151 public List <Activity > getAllActivities () {
106- if (allActivities != null ) return allActivities ;
152+ if (allActivities != null ) { return allActivities ; }
107153 allActivities = new ArrayList <>();
108154 JsonObject jj = hu .urlRequestGET ("https://www.bungie.net/Platform/Destiny2/" + getMembershipType () + "/Account/" + getMembershipID () + "/Character/" + getCharacterID () + "/Stats/AggregateActivityStats/" );
109- for (JsonElement je : jj .getAsJsonObject ("Response" ).getAsJsonArray ("activities" )) {
155+ for (JsonElement je : jj .getAsJsonObject ("Response" ).getAsJsonArray ("activities" )) {
110156 allActivities .add (new Activity (je .getAsJsonObject ().getAsJsonObject ("values" ).getAsJsonObject ("fastestCompletionMsForActivity" ).get ("activityId" ).getAsString ()));
111157 }
112158 return allActivities ;
113159 }
114160
115161 private Gender evaluateGender (String genderHash ) {
116162 JsonObject jj = hu .manifestGET (ManifestEntityTypes .GENDER , genderHash ).getAsJsonObject ("Response" );
117- switch (jj .get ("genderType" ).getAsString ()) {
163+ switch (jj .get ("genderType" ).getAsString ()) {
118164 case "0" :
119165 return Gender .MALE ;
120166 case "1" :
@@ -125,7 +171,7 @@ private Gender evaluateGender(String genderHash) {
125171
126172 private DestinyClass evaluateClass (String classHash ) {
127173 JsonObject jj = hu .manifestGET (ManifestEntityTypes .CLASS , classHash ).getAsJsonObject ("Response" );
128- switch (jj .getAsJsonObject ("displayProperties" ).get ("name" ).getAsString ()) {
174+ switch (jj .getAsJsonObject ("displayProperties" ).get ("name" ).getAsString ()) {
129175 case "Warlock" :
130176 return DestinyClass .WARLOCK ;
131177 case "Titan" :
@@ -138,7 +184,7 @@ private DestinyClass evaluateClass(String classHash) {
138184
139185 private Race evaluateRace (String raceHash ) {
140186 JsonObject jj = hu .manifestGET (ManifestEntityTypes .RACE , raceHash ).getAsJsonObject ("Response" );
141- switch (jj .getAsJsonObject ("displayProperties" ).get ("name" ).getAsString ()) {
187+ switch (jj .getAsJsonObject ("displayProperties" ).get ("name" ).getAsString ()) {
142188 case "Exo" :
143189 return Race .EXO ;
144190 case "Awoken" :
@@ -154,9 +200,11 @@ public enum Gender {
154200 FEMALE ("Female" );
155201
156202 private String value ;
203+
157204 private Gender (String value ) {
158205 this .value = value ;
159206 }
207+
160208 public String getValue () { return value ; }
161209
162210 }
@@ -167,9 +215,11 @@ public enum DestinyClass {
167215 WARLOCK ("Warlock" );
168216
169217 private String value ;
218+
170219 private DestinyClass (String value ) {
171220 this .value = value ;
172221 }
222+
173223 public String getValue () { return value ; }
174224 }
175225
@@ -179,9 +229,11 @@ public enum Race {
179229 HUMAN ("Human" );
180230
181231 private String value ;
232+
182233 private Race (String value ) {
183234 this .value = value ;
184235 }
236+
185237 public String getValue () { return value ; }
186238 }
187239}
0 commit comments