mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Pl3xMap: update to latest API, fabric platform support (#382)
This commit is contained in:
1 parent
0606e49d02
commit
3db08349cd
8 files changed
+148
-114
No files matched your search
@@ -46,8 +46,8 @@ jobs:
|
||||
modrinth-featured: false
|
||||
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||
modrinth-dependencies: |
|
||||
bluemap | suggests | *
|
||||
dynmap | suggests | *
|
||||
bluemap | suggests | *
|
||||
pl3xmap | suggests | *
|
||||
plan-player-analytics | suggests | *
|
||||
hangar-id: William278/HuskHomes
|
||||
@@ -101,10 +101,11 @@ jobs:
|
||||
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
|
||||
dependencies: |
|
||||
fabric-api | requires | *
|
||||
bluemap | suggests | *
|
||||
dynmap | suggests | *
|
||||
plan-player-analytics | suggests | *
|
||||
bluemap | suggests | *
|
||||
pl3xmap | suggests | *
|
||||
luckperms | suggests | *
|
||||
plan-player-analytics | suggests | *
|
||||
files-primary: target/HuskHomes-Fabric-*.jar
|
||||
name: HuskHomes (Fabric) v${{ env.version_name }}
|
||||
version: ${{ env.version_name }}
|
||||
|
||||
@@ -35,8 +35,8 @@ jobs:
|
||||
modrinth-featured: false
|
||||
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||
modrinth-dependencies: |
|
||||
bluemap | suggests | *
|
||||
dynmap | suggests | *
|
||||
bluemap | suggests | *
|
||||
pl3xmap | suggests | *
|
||||
plan-player-analytics | suggests | *
|
||||
hangar-id: William278/HuskHomes
|
||||
@@ -89,8 +89,9 @@ jobs:
|
||||
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
|
||||
dependencies: |
|
||||
fabric-api | requires | *
|
||||
bluemap | suggests | *
|
||||
dynmap | suggests | *
|
||||
bluemap | suggests | *
|
||||
pl3xmap | suggests | *
|
||||
luckperms | suggests | *
|
||||
plan-player-analytics | suggests | *
|
||||
files-primary: target/HuskHomes-Fabric-*.jar
|
||||
|
||||
@@ -29,6 +29,7 @@ dependencies {
|
||||
compileOnly 'com.github.plan-player-analytics:Plan:5.5.1923'
|
||||
compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:2.5.0'
|
||||
compileOnly 'us.dynmap:DynmapCoreAPI:3.4'
|
||||
compileOnly 'maven.modrinth:pl3xmap:1.19.4-382'
|
||||
|
||||
testImplementation 'com.github.plan-player-analytics:Plan:5.5.1923'
|
||||
testImplementation 'com.github.yuriy-g:simple-java-plot:5c502c2e98'
|
||||
|
||||
@@ -359,6 +359,8 @@ public interface HuskHomes extends TaskRunner, EventDispatcher, SafetyResolver {
|
||||
getHooks().add(new DynmapHook(this));
|
||||
} else if (isDependencyLoaded("BlueMap")) {
|
||||
getHooks().add(new BlueMapHook(this));
|
||||
} else if (isDependencyLoaded("Pl3xMap")) {
|
||||
getHooks().add(new Pl3xMapHook(this));
|
||||
}
|
||||
}
|
||||
if (isDependencyLoaded("Plan")) {
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.dynmap.DynmapCommonAPI;
|
||||
import org.dynmap.DynmapCommonAPIListener;
|
||||
import org.dynmap.markers.Marker;
|
||||
@@ -32,8 +31,6 @@ import org.dynmap.markers.MarkerSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -41,6 +38,7 @@ import java.util.Optional;
|
||||
*/
|
||||
public class DynmapHook extends MapHook {
|
||||
|
||||
private static final String ICON_PATH = "/tiles/_markers_/";
|
||||
@Nullable
|
||||
private DynmapCommonAPI dynmapApi;
|
||||
@Nullable
|
||||
@@ -90,12 +88,9 @@ public class DynmapHook extends MapHook {
|
||||
markerSet.createMarker(markerId, home.getName(), home.getWorld().getName(),
|
||||
home.getX(), home.getY(), home.getZ(),
|
||||
getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME).orElseThrow(), false)
|
||||
.setDescription(MarkerInformationPopup.create(home.getName())
|
||||
.thumbnail(PUBLIC_HOME_MARKER_IMAGE_NAME)
|
||||
.field("Owner", home.getOwner().getUsername())
|
||||
.field("Description", plugin.getLocales().wrapText(home.getMeta().getDescription(), 60))
|
||||
.field("Command", "/phome " + home.getIdentifier())
|
||||
.toHtml());
|
||||
.setDescription(MarkerInformationPopup.publicHome(
|
||||
home, ICON_PATH + PUBLIC_HOME_MARKER_IMAGE_NAME, plugin
|
||||
).toHtml());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -132,11 +127,9 @@ public class DynmapHook extends MapHook {
|
||||
markerSet.createMarker(markerId, warp.getName(), warp.getWorld().getName(),
|
||||
warp.getX(), warp.getY(), warp.getZ(),
|
||||
getMarkerIcon(WARP_MARKER_IMAGE_NAME).orElseThrow(), false)
|
||||
.setDescription(MarkerInformationPopup.create(warp.getName())
|
||||
.thumbnail(WARP_MARKER_IMAGE_NAME)
|
||||
.field("Description", plugin.getLocales().wrapText(warp.getMeta().getDescription(), 60))
|
||||
.field("Command", "/warp " + warp.getName())
|
||||
.toHtml());
|
||||
.setDescription(MarkerInformationPopup.warp(
|
||||
warp, ICON_PATH + WARP_MARKER_IMAGE_NAME, plugin
|
||||
).toHtml());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -198,61 +191,4 @@ public class DynmapHook extends MapHook {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an HTML Dynmap marker information popup widget
|
||||
*/
|
||||
private static class MarkerInformationPopup {
|
||||
@NotNull
|
||||
private final String title;
|
||||
|
||||
@Nullable
|
||||
private String thumbnailMarkerId;
|
||||
|
||||
@NotNull
|
||||
private final Map<String, String> fields;
|
||||
|
||||
private MarkerInformationPopup(@NotNull String title) {
|
||||
this.title = title;
|
||||
this.fields = new HashMap<>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static DynmapHook.MarkerInformationPopup create(@NotNull String title) {
|
||||
return new MarkerInformationPopup(title);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DynmapHook.MarkerInformationPopup thumbnail(@NotNull String thumbnailMarkerId) {
|
||||
this.thumbnailMarkerId = thumbnailMarkerId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DynmapHook.MarkerInformationPopup field(@NotNull String key, @NotNull String value) {
|
||||
fields.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String toHtml() {
|
||||
final StringBuilder html = new StringBuilder();
|
||||
html.append("<div class=\"infowindow\">");
|
||||
if (thumbnailMarkerId != null) {
|
||||
html.append("<img src=\"/tiles/_markers_/")
|
||||
.append(thumbnailMarkerId)
|
||||
.append(".png\" class=\"thumbnail\"/>")
|
||||
.append(" ");
|
||||
}
|
||||
html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml4(title))
|
||||
.append("</span><br/>");
|
||||
fields.forEach((key, value) -> html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml4(key))
|
||||
.append(": </span><span>")
|
||||
.append(StringEscapeUtils.escapeHtml4(value))
|
||||
.append("</span><br/>"));
|
||||
return html.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,12 @@ import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.SavedPosition;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A hook for a mapping plugin, such as Dynmap
|
||||
@@ -134,4 +139,79 @@ public abstract class MapHook extends Hook {
|
||||
.orElse("Warps");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an HTML Dynmap marker information popup widget
|
||||
*/
|
||||
protected static class MarkerInformationPopup {
|
||||
@NotNull
|
||||
private final String title;
|
||||
|
||||
@Nullable
|
||||
private String thumbnail;
|
||||
|
||||
@NotNull
|
||||
private final Map<String, String> fields;
|
||||
|
||||
private MarkerInformationPopup(@NotNull String title) {
|
||||
this.title = title;
|
||||
this.fields = new HashMap<>();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static DynmapHook.MarkerInformationPopup warp(@NotNull Warp warp, @NotNull String thumbnail, @NotNull HuskHomes plugin) {
|
||||
return MarkerInformationPopup.create(warp.getName())
|
||||
.thumbnail(thumbnail)
|
||||
.field("Description", plugin.getLocales().wrapText(warp.getMeta().getDescription(), 60))
|
||||
.field("Location", warp.toString())
|
||||
.field("Command", "/warp " + warp.getSafeIdentifier());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static DynmapHook.MarkerInformationPopup publicHome(@NotNull Home home, @NotNull String thumbnail, @NotNull HuskHomes plugin) {
|
||||
return MarkerInformationPopup.create(home.getName())
|
||||
.thumbnail(thumbnail)
|
||||
.field("Owner", home.getOwner().getUsername())
|
||||
.field("Description", plugin.getLocales().wrapText(home.getMeta().getDescription(), 60))
|
||||
.field("Location", home.toString())
|
||||
.field("Command", "/phome " + home.getSafeIdentifier());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static DynmapHook.MarkerInformationPopup create(@NotNull String title) {
|
||||
return new MarkerInformationPopup(title);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected DynmapHook.MarkerInformationPopup thumbnail(@NotNull String thumbnail) {
|
||||
this.thumbnail = thumbnail;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected DynmapHook.MarkerInformationPopup field(@NotNull String key, @NotNull String value) {
|
||||
fields.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String toHtml() {
|
||||
final StringBuilder html = new StringBuilder();
|
||||
html.append("<div class=\"infowindow\">");
|
||||
if (thumbnail != null) {
|
||||
html.append("<img src=\"")
|
||||
.append(thumbnail)
|
||||
.append(".png\" class=\"thumbnail\"/>")
|
||||
.append(" ");
|
||||
}
|
||||
html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml4(title))
|
||||
.append("</span><br/>");
|
||||
fields.forEach((key, value) -> html.append("<span style=\"font-weight: bold;\">")
|
||||
.append(StringEscapeUtils.escapeHtml4(key))
|
||||
.append(": </span><span>")
|
||||
.append(StringEscapeUtils.escapeHtml4(value))
|
||||
.append("</span><br/>"));
|
||||
return html.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-37
@@ -19,21 +19,24 @@
|
||||
|
||||
package net.william278.huskhomes.hook;
|
||||
|
||||
import net.pl3x.map.Key;
|
||||
import net.pl3x.map.Pl3xMap;
|
||||
import net.pl3x.map.event.EventHandler;
|
||||
import net.pl3x.map.event.EventListener;
|
||||
import net.pl3x.map.event.server.ServerLoadedEvent;
|
||||
import net.pl3x.map.event.world.WorldLoadedEvent;
|
||||
import net.pl3x.map.event.world.WorldUnloadedEvent;
|
||||
import net.pl3x.map.image.IconImage;
|
||||
import net.pl3x.map.markers.Point;
|
||||
import net.pl3x.map.markers.layer.SimpleLayer;
|
||||
import net.pl3x.map.markers.marker.Icon;
|
||||
import net.pl3x.map.markers.marker.Marker;
|
||||
import net.pl3x.map.world.World;
|
||||
import net.pl3x.map.core.Pl3xMap;
|
||||
import net.pl3x.map.core.event.EventHandler;
|
||||
import net.pl3x.map.core.event.EventListener;
|
||||
import net.pl3x.map.core.event.server.ServerLoadedEvent;
|
||||
import net.pl3x.map.core.event.world.WorldLoadedEvent;
|
||||
import net.pl3x.map.core.event.world.WorldUnloadedEvent;
|
||||
import net.pl3x.map.core.image.IconImage;
|
||||
import net.pl3x.map.core.markers.Point;
|
||||
import net.pl3x.map.core.markers.layer.SimpleLayer;
|
||||
import net.pl3x.map.core.markers.marker.Icon;
|
||||
import net.pl3x.map.core.markers.marker.Marker;
|
||||
import net.pl3x.map.core.markers.option.Options;
|
||||
import net.pl3x.map.core.markers.option.Popup;
|
||||
import net.pl3x.map.core.markers.option.Tooltip;
|
||||
import net.pl3x.map.core.world.World;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.position.Home;
|
||||
import net.william278.huskhomes.position.SavedPosition;
|
||||
import net.william278.huskhomes.position.Warp;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -49,15 +52,14 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
|
||||
private static final String ICON_PATH = "/images/icon/registered/";
|
||||
private static final String WARPS_LAYER = "warp_markers";
|
||||
private static final String PUBLIC_HOMES_LAYER = "public_home_markers";
|
||||
private final ConcurrentLinkedQueue<Home> publicHomes = new ConcurrentLinkedQueue<>();
|
||||
private final ConcurrentLinkedQueue<Warp> warps = new ConcurrentLinkedQueue<>();
|
||||
private final Key warpsLayerKey;
|
||||
private final Key publicHomesLayerKey;
|
||||
|
||||
public Pl3xMapHook(@NotNull HuskHomes plugin) {
|
||||
super(plugin, "Pl3xMap");
|
||||
this.warpsLayerKey = Key.of("warp_markers");
|
||||
this.publicHomesLayerKey = Key.of("public_home_markers");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,10 +67,10 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
Pl3xMap.api().getEventRegistry().register(this);
|
||||
|
||||
if (plugin.getSettings().doWarpsOnMap()) {
|
||||
this.registerIcon(warpsLayerKey, "markers/16x/warp.png");
|
||||
this.registerIcon(WARPS_LAYER, "markers/16x/warp.png");
|
||||
}
|
||||
if (plugin.getSettings().doPublicHomesOnMap()) {
|
||||
this.registerIcon(publicHomesLayerKey, "markers/16x/public-home.png");
|
||||
this.registerIcon(PUBLIC_HOMES_LAYER, "markers/16x/public-home.png");
|
||||
}
|
||||
|
||||
plugin.runAsync(() -> {
|
||||
@@ -113,15 +115,15 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
warps.clear();
|
||||
}
|
||||
|
||||
private void registerIcon(@NotNull Key key, @NotNull String iconFileName) {
|
||||
private void registerIcon(@NotNull String key, @NotNull String iconFileName) {
|
||||
try (InputStream iconStream = plugin.getResource(iconFileName)) {
|
||||
if (iconStream == null) {
|
||||
plugin.log(Level.WARNING, "Failed to load Pl3xMap icon ("+ key + "): icon file not found");
|
||||
plugin.log(Level.WARNING, "Failed to load Pl3xMap icon (" + key + "): icon file not found");
|
||||
return;
|
||||
}
|
||||
Pl3xMap.api().getIconRegistry().register(new IconImage(key, ImageIO.read(iconStream), "png"));
|
||||
} catch (IOException e) {
|
||||
plugin.log(Level.WARNING, "Failed to load Pl3xMap icon ("+ key + "): " + e.getMessage(), e);
|
||||
plugin.log(Level.WARNING, "Failed to load Pl3xMap icon (" + key + "): " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,21 +140,33 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EventHandler
|
||||
public void onServerLoaded(ServerLoadedEvent event) {
|
||||
Pl3xMap.api().getWorldRegistry().entries().values().forEach(this::registerLayers);
|
||||
public void onServerLoaded(@NotNull ServerLoadedEvent event) {
|
||||
Pl3xMap.api().getWorldRegistry().forEach(this::registerLayers);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EventHandler
|
||||
public void onWorldLoaded(WorldLoadedEvent event) {
|
||||
public void onWorldLoaded(@NotNull WorldLoadedEvent event) {
|
||||
registerLayers(event.getWorld());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@EventHandler
|
||||
public void onWorldUnloaded(WorldUnloadedEvent event) {
|
||||
event.getWorld().getLayerRegistry().unregister(warpsLayerKey);
|
||||
event.getWorld().getLayerRegistry().unregister(publicHomesLayerKey);
|
||||
public void onWorldUnloaded(@NotNull WorldUnloadedEvent event) {
|
||||
event.getWorld().getLayerRegistry().unregister(WARPS_LAYER);
|
||||
event.getWorld().getLayerRegistry().unregister(PUBLIC_HOMES_LAYER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Options getMarkerOptions(@NotNull SavedPosition position) {
|
||||
return Options.builder()
|
||||
.tooltip(new Tooltip(position.getIdentifier()))
|
||||
.popup(new Popup(position instanceof Home home ? MarkerInformationPopup.publicHome(
|
||||
home, ICON_PATH + WARPS_LAYER, plugin
|
||||
).toHtml() : position instanceof Warp warp ? MarkerInformationPopup.warp(
|
||||
warp, ICON_PATH + PUBLIC_HOMES_LAYER, plugin
|
||||
).toHtml() : ""))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static class WarpsLayer extends SimpleLayer {
|
||||
@@ -161,7 +175,7 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
private final World mapWorld;
|
||||
|
||||
public WarpsLayer(@NotNull Pl3xMapHook hook, @NotNull World mapWorld) {
|
||||
super(hook.warpsLayerKey, hook::getWarpsMarkerSetName);
|
||||
super(WARPS_LAYER, hook::getWarpsMarkerSetName);
|
||||
this.hook = hook;
|
||||
this.mapWorld = mapWorld;
|
||||
}
|
||||
@@ -172,10 +186,10 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
return hook.warps.stream()
|
||||
.filter(warp -> warp.getWorld().getName().equals(mapWorld.getName()))
|
||||
.map(warp -> Icon.of(
|
||||
Key.of("warp_" + warp.getUuid()),
|
||||
hook.plugin.getKey("warp_" + warp.getUuid()).asString(),
|
||||
Point.of(warp.getX(), warp.getZ()),
|
||||
hook.warpsLayerKey
|
||||
))
|
||||
WARPS_LAYER
|
||||
).setOptions(hook.getMarkerOptions(warp)))
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
}
|
||||
|
||||
@@ -187,7 +201,7 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
private final World mapWorld;
|
||||
|
||||
public PublicHomesLayer(@NotNull Pl3xMapHook hook, @NotNull World mapWorld) {
|
||||
super(hook.publicHomesLayerKey, hook::getPublicHomesMarkerSetName);
|
||||
super(PUBLIC_HOMES_LAYER, hook::getPublicHomesMarkerSetName);
|
||||
this.hook = hook;
|
||||
this.mapWorld = mapWorld;
|
||||
}
|
||||
@@ -197,11 +211,11 @@ public class Pl3xMapHook extends MapHook implements EventListener {
|
||||
public Collection<Marker<?>> getMarkers() {
|
||||
return hook.publicHomes.stream()
|
||||
.filter(home -> home.getWorld().getName().equals(mapWorld.getName()))
|
||||
.map(home -> Icon.of(
|
||||
Key.of("public_home_" + home.getUuid()),
|
||||
.map(home -> Marker.icon(
|
||||
hook.plugin.getKey("public_home_" + home.getUuid()).asString(),
|
||||
Point.of(home.getX(), home.getZ()),
|
||||
hook.publicHomesLayerKey
|
||||
))
|
||||
PUBLIC_HOMES_LAYER
|
||||
).setOptions(hook.getMarkerOptions(home)))
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ dependencies {
|
||||
compileOnly project(':common')
|
||||
|
||||
compileOnly 'io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT'
|
||||
compileOnly 'maven.modrinth:pl3xmap:1.19.3-321'
|
||||
|
||||
compileOnly 'org.bstats:bstats-bukkit:3.0.2'
|
||||
compileOnly 'org.jetbrains:annotations:24.0.1'
|
||||
|
||||
Reference in new issue
Block a user