Skip to content

Commit 0f2e8a8

Browse files
authored
Add files via upload
1 parent fa40bb0 commit 0f2e8a8

File tree

15 files changed

+128
-22
lines changed

15 files changed

+128
-22
lines changed

JavaDestinyAPI/pom.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
</properties>
4040

4141
<dependencies>
42+
<dependency>
43+
<groupId>com.google.code.gson</groupId>
44+
<artifactId>gson</artifactId>
45+
<version>2.8.6</version>
46+
</dependency>
4247
<dependency>
4348
<groupId>org.jetbrains</groupId>
4449
<artifactId>annotations</artifactId>
@@ -52,4 +57,45 @@
5257
</dependency>
5358
</dependencies>
5459

60+
61+
<distributionManagement>
62+
<snapshotRepository>
63+
<id>ossrh</id>
64+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
65+
</snapshotRepository>
66+
<repository>
67+
<id>ossrh</id>
68+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
69+
</repository>
70+
</distributionManagement>
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.sonatype.plugins</groupId>
75+
<artifactId>nexus-staging-maven-plugin</artifactId>
76+
<version>1.6.7</version>
77+
<extensions>true</extensions>
78+
<configuration>
79+
<serverId>ossrh</serverId>
80+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
81+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-gpg-plugin</artifactId>
87+
<version>1.5</version>
88+
<executions>
89+
<execution>
90+
<id>sign-artifacts</id>
91+
<phase>verify</phase>
92+
<goals>
93+
<goal>sign</goal>
94+
</goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
</plugins>
99+
</build>
100+
55101
</project>

JavaDestinyAPI/settings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
2+
<servers>
3+
<server>
4+
<id>ossrh</id>
5+
<username>dec4234</username>
6+
<password></password>
7+
</server>
8+
</servers>
9+
</settings>

JavaDestinyAPI/src/main/java/material/DestinyAPI.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.gson.*;
44
import material.clan.Clan;
55
import material.user.BungieUser;
6+
import utils.HttpUtils;
67

78
import java.io.IOException;
89
import java.io.InputStreamReader;
@@ -38,10 +39,16 @@ public DestinyAPI setOauthCode(String oauthCode) {
3839
return this;
3940
}
4041

42+
4143
public BungieUser getUser(String id) { return new BungieUser(id); }
4244

45+
/**
46+
* Gets the users with this name (There can be multiple users with the same name)
47+
*/
4348
public List<BungieUser> getUsersWithName(String name) {
49+
HttpUtils hu = new HttpUtils();
4450
List<BungieUser> temp = new ArrayList<>();
51+
List<String> ids = new ArrayList<>();
4552
try {
4653
String url = "https://www.bungie.net/platform/Destiny2/SearchDestinyPlayer/-1/" + name.replace(" ", "%20");
4754
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
@@ -51,29 +58,37 @@ public List<BungieUser> getUsersWithName(String name) {
5158
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
5259
JsonElement parse = new JsonParser().parse(reader);
5360
JsonObject obj = parse.getAsJsonObject();
61+
System.out.println(hu.urlRequestGETstring("https://www.bungie.net/platform/Destiny2/SearchDestinyPlayer/-1/" + name.replace(" ", "%20")));
5462
if (obj.get("Response").isJsonArray()) {
5563
for (JsonElement objj : obj.getAsJsonArray("Response")) {
5664
JsonObject us = objj.getAsJsonObject();
57-
temp.add(new BungieUser(us.get("membershipId").getAsString()));
65+
BungieUser bu = new BungieUser(us.get("membershipId").getAsString());
66+
if(!ids.contains(bu.getBungieMembershipID())) {
67+
temp.add(bu);
68+
ids.add(bu.getBungieMembershipID());
69+
}
5870
}
59-
}
60-
return temp;
61-
} catch (IOException ioException) {
62-
ioException.printStackTrace();
6371
}
64-
return null;
72+
} catch (IOException ioException) {
73+
ioException.printStackTrace();
6574
}
75+
return temp;
76+
}
6677

6778
public Clan getClan(long id) {
6879
return new Clan(id);
6980
}
81+
7082
public Clan getClan(String name) {
7183
return new Clan(name);
7284
}
7385

7486
public static String getApiKey() { return apiKey; }
87+
7588
public static String getClientId() { return clientId; }
89+
7690
public static String getClientSecret() { return clientSecret; }
91+
7792
public static String getOauthCode() { return oauthCode; }
7893

7994
}

JavaDestinyAPI/src/main/java/material/clan/Clan.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,24 @@ public class Clan {
3434
private List<BungieUser> admins;
3535
private List<BungieUser> members = new ArrayList<>();
3636
private ClanManagement clanManagement;
37+
private JsonObject jso;
38+
private JsonArray ja;
3739

3840
public Clan(long clanId) {
3941
this.clanId = clanId;
40-
cjo = hu.urlRequestGET("https://www.bungie.net/platform/GroupV2/" + clanId +"/?components=200").get("Response").getAsJsonObject().get("detail").getAsJsonObject();
42+
cjo = hu.urlRequestGET("https://www.bungie.net/platform/GroupV2/" + clanId + "/?components=200").get("Response").getAsJsonObject().get("detail").getAsJsonObject();
4143
assignValues();
4244
}
4345

4446
public Clan(String clanName) {
4547
this.clanName = clanName;
46-
jo = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/Name/" + clanName.replace(" ", "%20") +"/1/?components=200").get("Response").getAsJsonObject();
48+
jo = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/Name/" + clanName.replace(" ", "%20") + "/1/?components=200").get("Response").getAsJsonObject();
4749
cjo = jo.get("detail").getAsJsonObject();
4850
assignValues();
4951
}
5052

5153
private void assignValues() {
52-
if(clanName == null) { // If the clan object was created via ID then the clanName would be null by default
54+
if (clanName == null) { // If the clan object was created via ID then the clanName would be null by default
5355
clanName = cjo.get("name").getAsString();
5456
} else { // Opposite of previous reason
5557
clanId = cjo.get("groupId").getAsLong();
@@ -92,33 +94,33 @@ public String getClanName() {
9294
* Followed by the admins in the order they were promoted
9395
*/
9496
public List<BungieUser> getAdmins() {
95-
if(admins != null) return admins;
97+
if (admins != null) { return admins; }
9698

9799
List<BungieUser> temp = new ArrayList<>();
98100
JsonArray ja = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + clanId + "/AdminsAndFounder/?componenets=200").get("Response").getAsJsonObject().get("results").getAsJsonArray();
99101

100-
for(JsonElement je : ja) {
102+
for (JsonElement je : ja) {
101103
temp.add(new BungieUser(je.getAsJsonObject().get("destinyUserInfo").getAsJsonObject().get("membershipId").getAsString()));
102104
}
103105

104106
return temp;
105107
}
106108

107109
public List<BungieUser> getMembers() {
108-
if(!members.isEmpty()) return members;
110+
if (!members.isEmpty()) { return members; }
109111

110-
JsonObject jo = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + clanId + "/Members/").get("Response").getAsJsonObject();
112+
jso = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + clanId + "/Members/").get("Response").getAsJsonObject();
111113

112-
for(JsonElement je : jo.get("results").getAsJsonArray()) {
114+
for (JsonElement je : jso.get("results").getAsJsonArray()) {
113115
members.add(new BungieUser(je.getAsJsonObject().get("destinyUserInfo").getAsJsonObject().get("membershipId").getAsString()));
114116
}
115117

116118
return members;
117119
}
118120

119121
public ClanManagement getClanManagement() {
120-
if(clanManagement != null) return clanManagement;
122+
if (clanManagement != null) { return clanManagement; }
121123
clanManagement = new ClanManagement(this);
122-
return clanManagement;
124+
return clanManagement;
123125
}
124126
}

JavaDestinyAPI/src/main/java/material/clan/ClanManagement.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ public List<BungieUser> getBannedMembers() {
106106
}
107107

108108
/**
109-
* Returns a list of pending members to the clan
109+
* Returns a list of pending members to the clan, Never cached: always makes a new request
110110
*/
111111
public List<BungieUser> getPendingMembers() {
112-
if(pendingMembers != null) return pendingMembers;
113-
114112
List<BungieUser> temp = new ArrayList<>();
115113
JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Pending/?components=200").get("Response").getAsJsonObject().get("results").getAsJsonArray();
116114

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package material.inventory;
2+
3+
import com.google.gson.JsonObject;
4+
5+
public class DestinyItem {
6+
7+
private String hashID;
8+
9+
private JsonObject jo;
10+
11+
public DestinyItem(String hashID) {
12+
this.hashID = hashID;
13+
}
14+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import utils.HttpUtils;
88
import utils.StringUtils;
99

10+
import java.time.LocalDate;
11+
import java.time.temporal.ChronoUnit;
12+
import java.time.temporal.Temporal;
13+
import java.time.temporal.TemporalAccessor;
1014
import java.util.ArrayList;
1115
import java.util.Date;
1216
import java.util.List;
@@ -34,9 +38,10 @@ public class BungieUser {
3438
private String iconPath;
3539
private Clan clan;
3640

41+
private boolean assigned = false;
42+
3743
public BungieUser(String bungieMembershipID) {
3844
this.bungieMembershipID = bungieMembershipID;
39-
4045
jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/-1/Profile/" + bungieMembershipID + "/LinkedProfiles/?components=200");
4146
assignValues();
4247
}
@@ -89,7 +94,7 @@ private void assignValues() {
8994
/**
9095
* Gets an integer representing the number of days since the user last played
9196
*/
92-
public int getDaysSinceLastPlayed() { return (int) (new Date().getTime() - getLastPlayed().getTime()) / 86400000; }
97+
public int getDaysSinceLastPlayed() { return (int) ChronoUnit.DAYS.between(getLastPlayed().toInstant(), new Date().toInstant()); }
9398

9499
public boolean isOverriden() { return isOverriden; }
95100
public boolean isCrossSavePrimary() { return isCrossSavePrimary; }
@@ -138,7 +143,6 @@ public Clan getClan() {
138143
}
139144

140145
public void allowClanInvites(boolean allowInvites) {
141-
142146
}
143147

144148
/**

JavaDestinyAPI/src/main/java/utils/HttpUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ public JsonObject urlRequestGET(String url) {
4848
return parse.getAsJsonObject();
4949
}
5050

51+
public String urlRequestGETstring(String url) {
52+
HttpClient client = HttpClient.newHttpClient();
53+
HttpRequest request = HttpRequest.newBuilder()
54+
.uri(URI.create(url))
55+
.timeout(Duration.ofMinutes(1))
56+
.header("X-API-KEY", apiKey)
57+
.GET()
58+
.build();
59+
CompletableFuture<String> response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body);
60+
JsonElement parse = null;
61+
try {
62+
return response.get();
63+
} catch (InterruptedException | ExecutionException e) {
64+
e.printStackTrace();
65+
}
66+
return null;
67+
}
68+
5169
public JsonObject urlRequestGETOauth(String url) {
5270
HttpClient client = HttpClient.newHttpClient();
5371
HttpRequest request = HttpRequest.newBuilder()
483 Bytes
Binary file not shown.
479 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)