Pl3xMap: update to latest API, fabric platform support (#382)

This commit is contained in:
William authored and GitHub committed 2023-05-03 15:51:03 +01:00
1 parent 0606e49d02
commit 3db08349cd
8 files changed
+148 -114

No files matched your search

@@ -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("&nbsp;");
}
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();
}
}
}