|
| 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.manifest; |
| 10 | + |
| 11 | +import com.google.gson.JsonObject; |
| 12 | +import utils.HttpUtils; |
| 13 | +import utils.framework.ContentFramework; |
| 14 | + |
| 15 | +import java.util.HashMap; |
| 16 | + |
| 17 | +public class DestinyManifest extends ContentFramework { |
| 18 | + |
| 19 | + private static HashMap<String, JsonObject> worldComponents = new HashMap<>(); |
| 20 | + |
| 21 | + public DestinyManifest() { |
| 22 | + super("https://www.bungie.net/Platform/Destiny2/Manifest/", source -> { |
| 23 | + return source.getAsJsonObject("Response"); |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * A standard Manifest GET |
| 29 | + * Unlike the manifestGET in HttpUtils(), this will not make a request every single time |
| 30 | + * |
| 31 | + * It'll download the entire definition library the first time and it'll cache it |
| 32 | + */ |
| 33 | + public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String hash) { |
| 34 | + JsonObject jsonObject = getDefinitionLibrary(manifestEntityTypes); |
| 35 | + |
| 36 | + if(jsonObject.has(hash)) { |
| 37 | + return jsonObject.getAsJsonObject(hash); |
| 38 | + } |
| 39 | + |
| 40 | + return null; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Get the current version of the manifest |
| 45 | + * Useful for checking for updates |
| 46 | + */ |
| 47 | + public String getVersion() { |
| 48 | + return getJO().get("version").getAsString(); |
| 49 | + } |
| 50 | + |
| 51 | + public String getMobileAssetContentPath() { |
| 52 | + return getJO().get("mobileAssetContentPath").getAsString(); |
| 53 | + } |
| 54 | + |
| 55 | + public String getMobileWorldContentPath(Language language) { |
| 56 | + return getJO().getAsJsonObject("mobileWorldContentPaths").get(language.getCode()).getAsString(); |
| 57 | + } |
| 58 | + |
| 59 | + public String getJsonWorldContentPath(Language language) { |
| 60 | + return getJO().getAsJsonObject("jsonWorldContentPaths").get(language.getCode()).getAsString(); |
| 61 | + } |
| 62 | + |
| 63 | + public JsonObject getWorldContent(Language language) { |
| 64 | + return new HttpUtils().urlRequestGET("https://www.bungie.net" + getJsonWorldContentPath(language)); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Get the entirety of the specified definition library |
| 69 | + */ |
| 70 | + public JsonObject getDefinitionLibrary(ManifestEntityTypes manifestEntityTypes) { |
| 71 | + Language language = Language.ENGLISH; |
| 72 | + |
| 73 | + if(!worldComponents.containsKey(manifestEntityTypes.getBungieEntityValue())) { |
| 74 | + worldComponents.put(manifestEntityTypes.getBungieEntityValue(), new HttpUtils().urlRequestGET("https://www.bungie.net" + getJO().getAsJsonObject("jsonWorldComponentContentPaths").getAsJsonObject(language.getCode()).get(manifestEntityTypes.getBungieEntityValue()).getAsString())); |
| 75 | + } |
| 76 | + |
| 77 | + return worldComponents.get(manifestEntityTypes.getBungieEntityValue()); |
| 78 | + } |
| 79 | + |
| 80 | + public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes manifestEntityTypes) { |
| 81 | + if(!worldComponents.containsKey(manifestEntityTypes.getBungieEntityValue())) { |
| 82 | + worldComponents.put(manifestEntityTypes.getBungieEntityValue(), new HttpUtils().urlRequestGET("https://www.bungie.net" + getJO().getAsJsonObject("jsonWorldComponentContentPaths").getAsJsonObject(language.getCode()).get(manifestEntityTypes.getBungieEntityValue()).getAsString())); |
| 83 | + } |
| 84 | + |
| 85 | + return worldComponents.get(manifestEntityTypes.getBungieEntityValue()); |
| 86 | + } |
| 87 | + |
| 88 | + public String getMobileClanBannerDatabasePath() { |
| 89 | + return getJO().get("mobileClanBannerDatabasePath").getAsString(); |
| 90 | + } |
| 91 | + |
| 92 | + public enum Language { |
| 93 | + |
| 94 | + ENGLISH("en"), |
| 95 | + FRENCH("fr"), |
| 96 | + SPANISH("es"), |
| 97 | + SPANISH_MEXICO("es-mx"), |
| 98 | + GERMAN("de"), |
| 99 | + ITALIAN("it"), |
| 100 | + JAPANESE("ja"), |
| 101 | + PORTUGEUSE_BRAZIL("pt-br"), |
| 102 | + RUSSIAN("ru"), |
| 103 | + KOREAN("ko"), |
| 104 | + ZH_CHT("zh-cht"), |
| 105 | + ZH_CHS("zh-chs"); |
| 106 | + |
| 107 | + String code; |
| 108 | + |
| 109 | + private Language(String code) { |
| 110 | + this.code = code; |
| 111 | + } |
| 112 | + |
| 113 | + public String getCode() { |
| 114 | + return code; |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments