fix: inconsistencies with Pl3xMap loading, close #570

This commit is contained in:
William committed 2024-03-31 19:07:16 +01:00
1 parent e2a7fec1d1
commit 9d2a73fd2c
4 files changed
+39 -10

No files matched your search

@@ -176,37 +176,43 @@ public abstract class MapHook extends Hook {
}
@NotNull
protected static DynmapHook.MarkerInformationPopup warp(@NotNull Warp warp, @NotNull String thumbnail) {
return MarkerInformationPopup.create(warp.getName())
protected static MarkerInformationPopup warp(@NotNull Warp warp, @NotNull String thumbnail) {
final MarkerInformationPopup popup = MarkerInformationPopup.create(warp.getName())
.thumbnail(thumbnail)
.field("Description", warp.getMeta().getDescription())
.field("Location", warp.toString())
.field("Command", "/warp " + warp.getSafeIdentifier());
if (!warp.getMeta().getDescription().isBlank()) {
popup.field("Description", warp.getMeta().getDescription());
}
return popup;
}
@NotNull
protected static DynmapHook.MarkerInformationPopup publicHome(@NotNull Home home, @NotNull String thumbnail) {
return MarkerInformationPopup.create(home.getName())
protected static MarkerInformationPopup publicHome(@NotNull Home home, @NotNull String thumbnail) {
final MarkerInformationPopup popup = MarkerInformationPopup.create(home.getName())
.thumbnail(thumbnail)
.field("Owner", home.getOwner().getUsername())
.field("Description", home.getMeta().getDescription())
.field("Location", home.toString())
.field("Command", "/phome " + home.getSafeIdentifier());
if (!home.getMeta().getDescription().isBlank()) {
popup.field("Description", home.getMeta().getDescription());
}
return popup;
}
@NotNull
protected static DynmapHook.MarkerInformationPopup create(@NotNull String title) {
protected static MarkerInformationPopup create(@NotNull String title) {
return new MarkerInformationPopup(title);
}
@NotNull
protected DynmapHook.MarkerInformationPopup thumbnail(@NotNull String thumbnail) {
protected MarkerInformationPopup thumbnail(@NotNull String thumbnail) {
this.thumbnail = thumbnail;
return this;
}
@NotNull
protected DynmapHook.MarkerInformationPopup field(@NotNull String key, @NotNull String value) {
protected MarkerInformationPopup field(@NotNull String key, @NotNull String value) {
fields.put(key, value);
return this;
}
@@ -22,6 +22,7 @@ package net.william278.huskhomes.hook;
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.Pl3xMapDisabledEvent;
import net.pl3x.map.core.event.server.Pl3xMapEnabledEvent;
import net.pl3x.map.core.event.world.WorldLoadedEvent;
import net.pl3x.map.core.event.world.WorldUnloadedEvent;
@@ -51,6 +52,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.stream.Collectors;
@SuppressWarnings("unused")
public class Pl3xMapHook extends MapHook implements EventListener {
private static final String ICON_PATH = "/images/icon/registered/";
@@ -66,6 +68,9 @@ public class Pl3xMapHook extends MapHook implements EventListener {
@Override
public void initialize() {
Pl3xMap.api().getEventRegistry().register(this);
if (Pl3xMap.api().isEnabled()) {
onPl3xMapEnabled(new Pl3xMapEnabledEvent());
}
}
@Override
@@ -159,6 +164,14 @@ public class Pl3xMapHook extends MapHook implements EventListener {
});
}
@EventHandler
public void onPl3xMapDisabled(@NotNull Pl3xMapDisabledEvent event) {
Pl3xMap.api().getWorldRegistry().forEach(world -> {
world.getLayerRegistry().unregister(WARPS_LAYER);
world.getLayerRegistry().unregister(PUBLIC_HOMES_LAYER);
});
}
@EventHandler
public void onWorldLoaded(@NotNull WorldLoadedEvent event) {
registerLayers(event.getWorld());