-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6fa897a
Showing
8 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Generate JavaDoc and Deploy to Pages | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# Single deploy job since we're just deploying | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
- name: Generate JavaDoc | ||
run: mvn javadoc:javadoc | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: 'target/site/apidocs/' | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# BMUtils | ||
A small library with a collection of useful functions for BlueMap addons. | ||
|
||
Should work with any plugin/mod-loader. Currently only tested with Paper. Please let me know if you have any issues when using other platforms! | ||
|
||
## Installation | ||
Visit https://jitpack.io/#TechnicJelle/BMUtils for details on how to install this library. | ||
|
||
## Usage | ||
Please see the javadoc for the full API reference: [technicjelle.com/BMUtils](https://technicjelle.com/BMUtils/com/technicjelle/BMUtils.html) | ||
|
||
### Copy Jar Resource To BlueMap | ||
This function copies any file from your jar to the BlueMap assets folder. This is useful for adding custom icons, scripts, or styles from your own addon. | ||
```java | ||
copyJarResourceToBlueMap(ClassLoader, BlueMapAPI, String fromResource, String toAsset, boolean overwrite) | ||
``` | ||
|
||
### Get Player Head Icon Address | ||
This function returns the address of a player head icon. This is useful when you want to use a playerhead on the map. For example, when adding custom icons to the map. | ||
```java | ||
getPlayerHeadIconAddress(BlueMapAPI, UUID playerUUID, BlueMapMap blueMapMap) | ||
``` | ||
|
||
## Contributing | ||
If you have any suggestions for more useful functions to add, please let me know by creating an issue on GitHub. | ||
|
||
To get support with this library, join the [BlueMap Discord server](https://bluecolo.red/map-discord) | ||
and ask your questions in [#3rd-party-support](https://discord.com/channels/665868367416131594/863844716047106068). You're welcome to ping me, @TechnicJelle. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.technicjelle</groupId> | ||
<artifactId>BMUtils</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>3.5.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>23.1.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.BlueMap-Minecraft</groupId> | ||
<artifactId>BlueMapAPI</artifactId> | ||
<version>v2.5.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.technicjelle; | ||
|
||
import de.bluecolored.bluemap.api.BlueMapAPI; | ||
import de.bluecolored.bluemap.api.BlueMapMap; | ||
import de.bluecolored.bluemap.api.plugin.SkinProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
|
||
public class BMUtils { | ||
static final String FALLBACK_ICON = "assets/steve.png"; | ||
|
||
/** | ||
* Copies a resource from the jar to the BlueMap asset folder.<br> | ||
* If the resource is a script or style, it will be registered with BlueMap.<br> | ||
* <b>This functions should be called directly inside {@link BlueMapAPI#onEnable(Consumer)}, not in a separate thread from there.</b> | ||
* | ||
* @param classLoader The class loader to get the resource from the correct jar | ||
* @param blueMapAPI The BlueMapAPI instance | ||
* @param fromResource The resource to copy from the jar | ||
* @param toAsset The asset to copy to, relative to BlueMap's asset folder (<code>bluemap/web/assets</code>) | ||
* @param overwrite Whether to overwrite the asset if it already exists | ||
* @throws IOException If the resource could not be found or copied | ||
*/ | ||
public static void copyJarResourceToBlueMap(@NotNull ClassLoader classLoader, @NotNull BlueMapAPI blueMapAPI, String fromResource, String toAsset, boolean overwrite) throws IOException { | ||
Path toPath = blueMapAPI.getWebApp().getWebRoot().resolve("assets").resolve(toAsset); | ||
|
||
//Register script or style | ||
String assetPath = "assets/" + toAsset; | ||
if (toAsset.endsWith(".js")) blueMapAPI.getWebApp().registerScript(assetPath); | ||
if (toAsset.endsWith(".css")) blueMapAPI.getWebApp().registerStyle(assetPath); | ||
|
||
//Copy resource | ||
if (Files.exists(toPath) && !overwrite) return; | ||
Files.createDirectories(toPath.getParent()); | ||
try ( | ||
InputStream in = classLoader.getResourceAsStream(fromResource); | ||
OutputStream out = Files.newOutputStream(toPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING) | ||
) { | ||
if (in == null) throw new IOException("Resource not found: " + fromResource); | ||
in.transferTo(out); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the URL to a player head icon for a specific map.<br> | ||
* If the icon doesn't exist yet, it will be created. | ||
* | ||
* @param blueMapAPI The BlueMapAPI instance | ||
* @param playerUUID The player to get the head of | ||
* @param blueMapMap The map to get the head for (each map has its own playerheads folder) | ||
* @return The URL to the player head, relative to BlueMap's web root,<br>or a Steve head if the head couldn't be found | ||
*/ | ||
public static String getPlayerHeadIconAddress(@NotNull BlueMapAPI blueMapAPI, @NotNull UUID playerUUID, @NotNull BlueMapMap blueMapMap) { | ||
final String assetName = "playerheads/" + playerUUID + ".png"; | ||
|
||
try { | ||
if (!blueMapMap.getAssetStorage().assetExists(assetName)) { | ||
createPlayerHead(blueMapAPI, playerUUID, assetName, blueMapMap); | ||
} | ||
} catch (IOException e) { | ||
return FALLBACK_ICON; | ||
} | ||
|
||
return blueMapMap.getAssetStorage().getAssetUrl(assetName); | ||
} | ||
|
||
/** | ||
* For when BlueMap doesn't have an icon for this player yet, so we need to make it create one. | ||
*/ | ||
private static void createPlayerHead(@NotNull BlueMapAPI blueMapAPI, @NotNull UUID playerUUID, String assetName, BlueMapMap map) throws IOException { | ||
SkinProvider skinProvider = blueMapAPI.getPlugin().getSkinProvider(); | ||
try { | ||
Optional<BufferedImage> oImgSkin = skinProvider.load(playerUUID); | ||
if (oImgSkin.isEmpty()) { | ||
throw new IOException(playerUUID + " doesn't have a skin"); | ||
} | ||
|
||
try (OutputStream out = map.getAssetStorage().writeAsset(assetName)) { | ||
BufferedImage head = blueMapAPI.getPlugin().getPlayerMarkerIconFactory() | ||
.apply(playerUUID, oImgSkin.get()); | ||
ImageIO.write(head, "png", out); | ||
} catch (IOException e) { | ||
throw new IOException("Failed to write " + playerUUID + "'s head to asset-storage", e); | ||
} | ||
} catch (IOException e) { | ||
throw new IOException("Failed to load skin for player " + playerUUID, e); | ||
} | ||
} | ||
} |