Add methods to control player-skin API and PlayerMarker-Icon generation

This commit is contained in:
Lukas Rieger (Blue) 2022-12-12 21:13:46 +01:00
parent 6b78d0d433
commit 4cf0629e52
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
5 changed files with 89 additions and 1 deletions

View File

@ -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()) {

View File

@ -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

View File

@ -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<UUID, BufferedImage, BufferedImage> {
/**
* Takes a players UUID and skin-image and creates an icon
* @param playerUuid the players UUID
* @param playerSkin the input image
* @return a <b>new</b> {@link BufferedImage} generated based on the input image
*/
BufferedImage apply(UUID playerUuid, BufferedImage playerSkin);
}

View File

@ -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);
}

View File

@ -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<BufferedImage> load(UUID playerUUID) throws IOException;
}