mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Add support for BlueMap
This commit is contained in:
1 parent
36703c55f5
commit
25d90530d3
13 files changed
+148
-8
No files matched your search
@@ -24,6 +24,7 @@ import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -251,6 +252,15 @@ public interface HuskHomes {
|
||||
@NotNull
|
||||
Server getServer(@NotNull OnlineUser requester);
|
||||
|
||||
/**
|
||||
* Returns a resource read from the plugin resources folder
|
||||
*
|
||||
* @param name the name of the resource
|
||||
* @return the resource read as an {@link InputStream}
|
||||
*/
|
||||
@Nullable
|
||||
InputStream getResource(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Returns a list of worlds on the server
|
||||
*
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package net.william278.huskhomes.hook;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
import de.bluecolored.bluemap.api.BlueMapAPI;
|
||||
import de.bluecolored.bluemap.api.markers.MarkerSet;
|
||||
import de.bluecolored.bluemap.api.markers.POIMarker;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Hook to display warps and public homes on <a href="https://github.com/BlueMap-Minecraft/BlueMap">BlueMap</a> maps
|
||||
*/
|
||||
public class BlueMapHook extends MapHook {
|
||||
|
||||
private String publicHomeMarkerIconPath;
|
||||
private String warpMarkerIconPath;
|
||||
|
||||
public BlueMapHook(@NotNull HuskHomes implementor) {
|
||||
super(implementor, "BlueMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<Void> initializeMap() {
|
||||
final CompletableFuture<Void> initializedFuture = new CompletableFuture<>();
|
||||
CompletableFuture.runAsync(() -> BlueMapAPI.onEnable(blueMapAPI -> {
|
||||
// Create marker sets
|
||||
plugin.getWorlds().forEach(world -> blueMapAPI.getWorld(world.uuid)
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(map -> {
|
||||
if (plugin.getSettings().publicHomesOnMap) {
|
||||
map.getMarkerSets().put(world.uuid + ":" + PUBLIC_HOMES_MARKER_SET_ID,
|
||||
MarkerSet.builder().label("Public Homes").build());
|
||||
}
|
||||
if (plugin.getSettings().warpsOnMap) {
|
||||
map.getMarkerSets().put(world.uuid + ":" + WARPS_MARKER_SET_ID,
|
||||
MarkerSet.builder().label("Warps").build());
|
||||
}
|
||||
})));
|
||||
|
||||
// Create marker icons
|
||||
try {
|
||||
publicHomeMarkerIconPath = blueMapAPI.getWebApp().createImage(
|
||||
ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + PUBLIC_HOME_MARKER_IMAGE_NAME + ".png"))),
|
||||
"huskhomes/" + PUBLIC_HOMES_MARKER_SET_ID + ".png");
|
||||
warpMarkerIconPath = blueMapAPI.getWebApp().createImage(
|
||||
ImageIO.read(Objects.requireNonNull(plugin.getResource("markers/50x/" + WARP_MARKER_IMAGE_NAME + ".png"))),
|
||||
"huskhomes/" + WARP_MARKER_IMAGE_NAME + ".png");
|
||||
} catch (IOException e) {
|
||||
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to create warp marker image", e);
|
||||
}
|
||||
|
||||
initializedFuture.complete(null);
|
||||
}));
|
||||
return initializedFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> updateHome(@NotNull Home home) {
|
||||
if (!plugin.getSettings().publicHomesOnMap) return CompletableFuture.completedFuture(null);
|
||||
return removeHome(home).thenRun(() -> BlueMapAPI.getInstance().flatMap(
|
||||
blueMapAPI -> blueMapAPI.getWorld(home.world.uuid)).ifPresent(blueMapWorld -> blueMapWorld.getMaps()
|
||||
.forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(home.world.uuid + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().put(home.uuid.toString(),
|
||||
POIMarker.toBuilder()
|
||||
.label(home.meta.name)
|
||||
.position((int) home.x, (int) home.y, (int) home.z)
|
||||
.icon(publicHomeMarkerIconPath, Vector2i.from(25, 25))
|
||||
.maxDistance(5000)
|
||||
.build());
|
||||
return markerSet;
|
||||
}))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeHome(@NotNull Home home) {
|
||||
if (!plugin.getSettings().publicHomesOnMap) return CompletableFuture.completedFuture(null);
|
||||
BlueMapAPI.getInstance().flatMap(blueMapAPI -> blueMapAPI.getWorld(home.world.uuid))
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(home.world.uuid + ":" + PUBLIC_HOMES_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().remove(home.uuid.toString());
|
||||
return markerSet;
|
||||
})));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> updateWarp(@NotNull Warp warp) {
|
||||
if (!plugin.getSettings().warpsOnMap) return CompletableFuture.completedFuture(null);
|
||||
return removeWarp(warp).thenRun(() -> BlueMapAPI.getInstance().flatMap(blueMapAPI -> blueMapAPI.getWorld(warp.world.uuid))
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(warp.world.uuid + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().put(warp.uuid.toString(),
|
||||
POIMarker.toBuilder()
|
||||
.label(warp.meta.name)
|
||||
.position((int) warp.x, (int) warp.y, (int) warp.z)
|
||||
.icon(warpMarkerIconPath, Vector2i.from(25, 25))
|
||||
.maxDistance(10000)
|
||||
.build());
|
||||
return markerSet;
|
||||
}))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeWarp(@NotNull Warp warp) {
|
||||
if (!plugin.getSettings().warpsOnMap) return CompletableFuture.completedFuture(null);
|
||||
BlueMapAPI.getInstance().flatMap(blueMapAPI -> blueMapAPI.getWorld(warp.world.uuid))
|
||||
.ifPresent(blueMapWorld -> blueMapWorld.getMaps().forEach(blueMapMap -> blueMapMap.getMarkerSets()
|
||||
.computeIfPresent(warp.world.uuid + ":" + WARPS_MARKER_SET_ID, (s, markerSet) -> {
|
||||
markerSet.getMarkers().remove(warp.uuid.toString());
|
||||
return markerSet;
|
||||
})));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public abstract class MapHook extends PluginHook {
|
||||
|
||||
protected static final String PUBLIC_HOMES_MARKER_SET_ID = "huskhomes-public-homes";
|
||||
protected static final String WARPS_MARKER_SET_ID = "huskhomes-warps";
|
||||
protected static final String WARP_MARKER_IMAGE_NAME = "warp";
|
||||
protected static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public-home";
|
||||
|
||||
protected MapHook(@NotNull HuskHomes implementor, @NotNull String hookName) {
|
||||
super(implementor, hookName);
|
||||
|
||||
Reference in new issue
Block a user