Adds nullability annotations for all methods Fixes some nullability problems and inconsistencies Gets rid of RelativeBlockVector's inner class Changes RelativeBlockVector to a record Simplifies FromTheEndTeleportation's storage, and makes it into a minimal record Removes the putStringInList method Gets rid of some primitive list usage Fixes some incorrect method accessibility Removes some redundancy in PortalOption
145 lines
5.1 KiB
Java
145 lines
5.1 KiB
Java
package net.knarcraft.stargate.config;
|
|
|
|
import net.knarcraft.stargate.Stargate;
|
|
import net.knarcraft.stargate.container.RelativeBlockVector;
|
|
import net.knarcraft.stargate.portal.Portal;
|
|
import net.knarcraft.stargate.portal.PortalRegistry;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.World;
|
|
import org.dynmap.DynmapAPI;
|
|
import org.dynmap.markers.GenericMarker;
|
|
import org.dynmap.markers.Marker;
|
|
import org.dynmap.markers.MarkerIcon;
|
|
import org.dynmap.markers.MarkerSet;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
/**
|
|
* A manager for dealing with everything Dynmap
|
|
*/
|
|
public final class DynmapManager {
|
|
|
|
private static MarkerSet markerSet;
|
|
private static MarkerIcon portalIcon;
|
|
|
|
private DynmapManager() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Initializes the dynmap manager
|
|
*
|
|
* @param dynmapAPI <p>A reference</p>
|
|
* @throws NullPointerException <p>If dynmap has an invalid state</p>
|
|
*/
|
|
public static void initialize(@Nullable DynmapAPI dynmapAPI) throws NullPointerException {
|
|
if (dynmapAPI == null || !dynmapAPI.markerAPIInitialized() || dynmapAPI.getMarkerAPI() == null) {
|
|
markerSet = null;
|
|
portalIcon = null;
|
|
} else {
|
|
markerSet = dynmapAPI.getMarkerAPI().createMarkerSet("stargate", "Stargate", null, false);
|
|
if (markerSet != null) {
|
|
markerSet.setHideByDefault(Stargate.getStargateConfig().hideDynmapIcons());
|
|
}
|
|
portalIcon = dynmapAPI.getMarkerAPI().getMarkerIcon("portal");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Adds all portal markers for all current portals
|
|
*/
|
|
public static void addAllPortalMarkers() {
|
|
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
|
//Remove any existing markers if dynmap has been disabled after startup
|
|
if (markerSet != null) {
|
|
markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
|
}
|
|
return;
|
|
}
|
|
markerSet.setHideByDefault(Stargate.getStargateConfig().hideDynmapIcons());
|
|
//Remove all existing markers for a clean start
|
|
markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
|
|
|
for (Portal portal : PortalRegistry.getAllPortals()) {
|
|
addPortalMarker(portal);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Adds a portal marker for the given portal
|
|
*
|
|
* @param portal <p>The portal to add a marker for</p>
|
|
*/
|
|
public static void addPortalMarker(@NotNull Portal portal) {
|
|
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
|
return;
|
|
}
|
|
World world = portal.getWorld();
|
|
if (portal.getOptions().isHidden() || world == null) {
|
|
return;
|
|
}
|
|
|
|
Location location;
|
|
@Nullable RelativeBlockVector exit = portal.getGate().getLayout().getExit();
|
|
if (exit == null) {
|
|
location = portal.getTopLeft();
|
|
} else {
|
|
location = portal.getBlockAt(exit);
|
|
}
|
|
Marker marker = markerSet.createMarker(getPortalMarkerId(portal), portal.getName(), world.getName(),
|
|
location.getX(), location.getY(), location.getZ(), portalIcon, false);
|
|
if (marker == null) {
|
|
Stargate.logWarning(String.format(
|
|
"""
|
|
Unable to create marker for portal
|
|
Portal marker id: %s
|
|
Portal name: %s
|
|
Portal world: %s
|
|
Portal location: %s,%s,%s""",
|
|
getPortalMarkerId(portal), portal.getName(), world.getName(), location.getX(), location.getY(),
|
|
location.getZ()));
|
|
return;
|
|
}
|
|
String networkPrompt;
|
|
if (portal.getOptions().isBungee()) {
|
|
networkPrompt = "Server";
|
|
} else {
|
|
networkPrompt = "Network";
|
|
}
|
|
String markerDescription = String.format("<b>Name:</b> %s<br /><b>%s:</b> %s<br /><b>Destination:</b> " +
|
|
"%s<br /><b>Owner:</b> %s<br />", portal.getName(), networkPrompt, portal.getNetwork(),
|
|
portal.getDestinationName(), portal.getOwner().getName());
|
|
marker.setDescription(markerDescription);
|
|
marker.setLabel(portal.getName(), true);
|
|
if (portalIcon != null) {
|
|
marker.setMarkerIcon(portalIcon);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Removes the portal marker for the given portal
|
|
*
|
|
* @param portal <p>The portal to remove the marker for</p>
|
|
*/
|
|
public static void removePortalMarker(@NotNull Portal portal) {
|
|
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
|
|
return;
|
|
}
|
|
Marker marker = markerSet.findMarker(getPortalMarkerId(portal));
|
|
if (marker != null) {
|
|
marker.deleteMarker();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets the id used for the given portal's marker
|
|
*
|
|
* @param portal <p>The portal to get a marker id for</p>
|
|
* @return <p></p>
|
|
*/
|
|
private static String getPortalMarkerId(@NotNull Portal portal) {
|
|
return portal.getNetwork() + "-:-" + portal.getName();
|
|
}
|
|
|
|
}
|