Skip to content

Commit

Permalink
Support custom metadata key retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Jun 17, 2024
1 parent 256a67e commit 63915c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.\
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.technicjelle</groupId>
<artifactId>BMUtils</artifactId>
<version>4.0</version>
<version>4.1</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/technicjelle/BMUtils/BMNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. (<code>bluemap.addon.json</code>)
*
* @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();
}
}
}
Expand Down

0 comments on commit 63915c6

Please sign in to comment.