diff --git a/build.gradle.kts b/build.gradle.kts index 682eb08..b740de5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import java.io.IOException +import java.util.concurrent.TimeoutException plugins { java @@ -12,7 +13,11 @@ fun String.runCommand(): String = ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`] .redirectOutput(ProcessBuilder.Redirect.PIPE) .redirectError(ProcessBuilder.Redirect.PIPE) .start() - .apply { waitFor(60, TimeUnit.SECONDS) } + .apply { + if (!waitFor(10, TimeUnit.SECONDS)) { + throw TimeoutException("Failed to execute command: '" + this@runCommand + "'") + } + } .run { val error = errorStream.bufferedReader().readText().trim() if (error.isNotEmpty()) { diff --git a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java index 4bf24ad..d715ffe 100644 --- a/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java +++ b/src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java @@ -28,6 +28,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import de.bluecolored.bluemap.api.debug.DebugDump; +import de.bluecolored.bluemap.api.plugin.Plugin; import java.io.InputStream; import java.io.InputStreamReader; @@ -87,6 +88,13 @@ public abstract class BlueMapAPI { @DebugDump public abstract WebApp getWebApp(); + /** + * Getter for the {@link Plugin} + * @return the {@link Plugin} + */ + @DebugDump + public abstract Plugin getPlugin(); + /** * Getter for all {@link BlueMapMap}s loaded by BlueMap. * @return an unmodifiable collection of all loaded {@link BlueMapMap}s diff --git a/src/main/java/de/bluecolored/bluemap/api/plugin/PlayerIconFactory.java b/src/main/java/de/bluecolored/bluemap/api/plugin/PlayerIconFactory.java new file mode 100644 index 0000000..429a233 --- /dev/null +++ b/src/main/java/de/bluecolored/bluemap/api/plugin/PlayerIconFactory.java @@ -0,0 +1,18 @@ +package de.bluecolored.bluemap.api.plugin; + +import java.awt.image.BufferedImage; +import java.util.UUID; +import java.util.function.BiFunction; + +@FunctionalInterface +public interface PlayerIconFactory extends BiFunction { + + /** + * Takes a players UUID and skin-image and creates an icon + * @param playerUuid the players UUID + * @param playerSkin the input image + * @return a new {@link BufferedImage} generated based on the input image + */ + BufferedImage apply(UUID playerUuid, BufferedImage playerSkin); + +} diff --git a/src/main/java/de/bluecolored/bluemap/api/plugin/Plugin.java b/src/main/java/de/bluecolored/bluemap/api/plugin/Plugin.java new file mode 100644 index 0000000..3aa11e2 --- /dev/null +++ b/src/main/java/de/bluecolored/bluemap/api/plugin/Plugin.java @@ -0,0 +1,35 @@ +package de.bluecolored.bluemap.api.plugin; + +import de.bluecolored.bluemap.api.debug.DebugDump; + +public interface Plugin { + + /** + * Get the {@link SkinProvider} that bluemap is using to fetch player-skins + * @return the {@link SkinProvider} instance bluemap is using + */ + @DebugDump + SkinProvider getSkinProvider(); + + /** + * Sets the {@link SkinProvider} that bluemap will use to fetch new player-skins. + * @param skinProvider The new {@link SkinProvider} bluemap should use + */ + void setSkinProvider(SkinProvider skinProvider); + + /** + * Get the {@link PlayerIconFactory} that bluemap is using to convert a player-skin into the icon-image that is used + * for the Player-Markers + * @return The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons + */ + @DebugDump + PlayerIconFactory getPlayerMarkerIconFactory(); + + /** + * Set the {@link PlayerIconFactory} that bluemap will use to convert a player-skin into the icon-image that is used + * for the Player-Markers + * @param playerMarkerIconFactory The {@link PlayerIconFactory} bluemap uses to convert skins into player-marker icons + */ + void setPlayerMarkerIconFactory(PlayerIconFactory playerMarkerIconFactory); + +} diff --git a/src/main/java/de/bluecolored/bluemap/api/plugin/SkinProvider.java b/src/main/java/de/bluecolored/bluemap/api/plugin/SkinProvider.java new file mode 100644 index 0000000..7b9a81f --- /dev/null +++ b/src/main/java/de/bluecolored/bluemap/api/plugin/SkinProvider.java @@ -0,0 +1,22 @@ +package de.bluecolored.bluemap.api.plugin; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; + +/** + * A skin-provider capable of loading minecraft player-skins for a given UUID + */ +@FunctionalInterface +public interface SkinProvider { + + /** + * Attempts to load a minecraft-skin from this skin-provider. + * @return an {@link Optional} containing a {@link BufferedImage} with the skin-image or an empty Optional if there is no + * skin for this UUID + * @throws IOException if something went wrong trying to load the skin + */ + Optional load(UUID playerUUID) throws IOException; + +}