diff --git a/README.md b/README.md index 99c20a1..603215e 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,11 @@ This function gets the ID of your Native BlueMap Addon. BMNative.getAddonID(ClassLoader) ``` +With this function, you can get any arbitrary key from your Native BlueMap Addon's config file. +```java +BMNative.getAddonMetadataKey(ClassLoader, String key) +``` + ### Get Player Head Icon Address ([Docs](https://technicjelle.com/BMUtils/com/technicjelle/BMSkin.html)) This function returns the address of a player head icon, and automatically generates the icon if it doesn't exist yet.\ diff --git a/pom.xml b/pom.xml index a21abce..e16dcd2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.technicjelle BMUtils - 4.0 + 4.1 16 diff --git a/src/main/java/com/technicjelle/BMUtils/BMNative.java b/src/main/java/com/technicjelle/BMUtils/BMNative.java index f05093f..95c56c0 100644 --- a/src/main/java/com/technicjelle/BMUtils/BMNative.java +++ b/src/main/java/com/technicjelle/BMUtils/BMNative.java @@ -74,13 +74,25 @@ public static Path getAddonsDirectory(BlueMapAPI api) { * @throws IOException If the metadata file could not be read */ public static String getAddonID(ClassLoader classLoader) throws IOException { + return getAddonMetadataKey(classLoader, KEY_ID); + } + + /** + * Gets any arbitrary key from the addon metadata file. (bluemap.addon.json) + * + * @param classLoader The class loader of the addon + * @param key The key to get + * @return The value of the key + * @throws IOException If the metadata file could not be read + */ + public static String getAddonMetadataKey(ClassLoader classLoader, String key) throws IOException { try ( final InputStream in = classLoader.getResourceAsStream(ADDON_METADATA_FILE) ) { if (in == null) throw new IOException("Resource not found: " + ADDON_METADATA_FILE); final String json = new String(in.readAllBytes()); final JsonObject o = JSON_PARSER.parse(json).getAsJsonObject(); - return o.get(KEY_ID).getAsString(); + return o.get(key).getAsString(); } } }