Skip to content

Commit

Permalink
Merge pull request #7 from dec4234/dec4234-patch-1
Browse files Browse the repository at this point in the history
Introduction of new features and various improvements
  • Loading branch information
dec4234 authored Sep 5, 2020
2 parents 0db53f1 + 628a0f8 commit 1742fc7
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 2 deletions.
1 change: 0 additions & 1 deletion JavaDestinyAPI/src/main/java/material/DestinyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public List<BungieUser> getUsersWithName(String name) {
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
JsonElement parse = new JsonParser().parse(reader);
JsonObject obj = parse.getAsJsonObject();
System.out.println(hu.urlRequestGETstring("https://www.bungie.net/platform/Destiny2/SearchDestinyPlayer/-1/" + name.replace(" ", "%20")));
if (obj.get("Response").isJsonArray()) {
for (JsonElement objj : obj.getAsJsonArray("Response")) {
JsonObject us = objj.getAsJsonObject();
Expand Down
12 changes: 12 additions & 0 deletions JavaDestinyAPI/src/main/java/material/clan/Clan.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public List<BungieUser> getAdmins() {
return temp;
}

public double getAverageInactivityAmongMembers() {
ArrayList<Double> averages = new ArrayList<Double>();
int a = 0;
for(BungieUser bu : this.getMembers()) {
averages.add(bu.getDaysSinceLastPlayed());
}
for(Double d : averages) {
a += d;
}
return a / getMembers().size();
}

public List<BungieUser> getMembers() {
if (!members.isEmpty()) { return members; }

Expand Down
83 changes: 83 additions & 0 deletions JavaDestinyAPI/src/main/java/material/inventory/DestinyItem.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,97 @@
package material.inventory;

import com.google.gson.JsonObject;
import material.manifest.ManifestEntityTypes;
import utils.HttpUtils;

public class DestinyItem {

HttpUtils hu = new HttpUtils();

private String hashID;
private String name;
private String icon;
private String description;
private boolean hasIcon;
private String collectibleHash;
private String screenshot;
private ItemTier itemType;

private ItemTier tier;

private JsonObject jo;

public DestinyItem(String hashID) {
this.hashID = hashID;
jo = hu.manifestGET(ManifestEntityTypes.INVENTORYITEM, hashID).getAsJsonObject("Response");
assignValues();
}

private void assignValues() {
JsonObject dp = jo.getAsJsonObject("displayProperties");
name = dp.get("name").getAsString();
description = dp.get("description").getAsString();
icon = dp.get("icon").getAsString();
hasIcon = dp.get("hasIcon").getAsBoolean();
collectibleHash = jo.get("collectibleHash").getAsString();
screenshot = jo.get("screenshot").getAsString();
itemType = asessItemTier();
}

public String getHashID() {
return hashID;
}

/**
* Gets the name of the item
*/
public String getName() {
return name;
}

/**
* Plug this after https://www.bungie.net/ in a browser
*/
public String getIcon() {
return icon;
}

/**
* Gets the lore descriptions associated with this item
*/
public String getDescription() {
return description;
}

public boolean hasIcon() {
return hasIcon;
}

public String getCollectibleHash() {
return collectibleHash;
}

public ItemTier asessItemTier() {
switch(jo.getAsJsonObject("inventory").get("tierTypeName").getAsString()) {
case "Common":
return ItemTier.COMMON;
case "Uncommon":
return ItemTier.UNCOMMON;
case "Rare":
return ItemTier.RARE;
case "Legendary":
return ItemTier.LEGENDARY;
case "Exotic":
return ItemTier.EXOTIC;
}
return null;
}

enum ItemTier {
COMMON,
UNCOMMON,
RARE,
LEGENDARY,
EXOTIC;
}
}
4 changes: 3 additions & 1 deletion JavaDestinyAPI/src/main/java/material/user/BungieUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ private void assignValues() {
/**
* Gets an integer representing the number of days since the user last played
*/
public int getDaysSinceLastPlayed() { return (int) ChronoUnit.DAYS.between(getLastPlayed().toInstant(), new Date().toInstant()); }
public double getDaysSinceLastPlayed() {
return (double) ChronoUnit.DAYS.between(getLastPlayed().toInstant(), new Date().toInstant());
}

public boolean isOverriden() { return isOverriden; }
public boolean isCrossSavePrimary() { return isCrossSavePrimary; }
Expand Down
5 changes: 5 additions & 0 deletions JavaDestinyAPI/src/main/java/utils/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentif
return urlRequestGET("https://www.bungie.net/Platform/Destiny2/Manifest/" + entityType.getBungieEntityValue() + "/" + hashIdentifier + "/");
}

public String generateLineGraph() {
String body = "{\"chart\": {\"type\": \"line\", \"data\": {\"labels\": [\"Hello\", \"World\"], \"datasets\": [{\"label\": \"Foo\", \"data\": [1, 2]}]}}}";
return urlRequestPOST("https://quickchart.io/chart/create", body);
}

/**
* Gets an access token using the refresh token in storage and replaces the old refresh token with the new one
* @return Returns the new access token
Expand Down
Binary file modified JavaDestinyAPI/target/classes/jdaSrc/Testing.class
Binary file not shown.
Binary file modified JavaDestinyAPI/target/classes/material/DestinyAPI.class
Binary file not shown.
Binary file modified JavaDestinyAPI/target/classes/material/clan/Clan.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified JavaDestinyAPI/target/classes/material/user/BungieUser.class
Binary file not shown.
Binary file modified JavaDestinyAPI/target/classes/utils/HttpUtils.class
Binary file not shown.

0 comments on commit 1742fc7

Please sign in to comment.