78 lines
2.7 KiB
Java
78 lines
2.7 KiB
Java
|
package net.knarcraft.dynmapcitizens.trait;
|
||
|
|
||
|
import net.citizensnpcs.api.CitizensAPI;
|
||
|
import net.citizensnpcs.api.npc.NPC;
|
||
|
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||
|
import org.bukkit.Location;
|
||
|
import org.bukkit.World;
|
||
|
import org.dynmap.DynmapAPI;
|
||
|
import org.dynmap.markers.Marker;
|
||
|
import org.dynmap.markers.MarkerIcon;
|
||
|
import org.dynmap.markers.MarkerSet;
|
||
|
|
||
|
import java.util.UUID;
|
||
|
import java.util.logging.Level;
|
||
|
|
||
|
public abstract class AbstractTraitHandler implements CitizensTraitHandler {
|
||
|
|
||
|
protected boolean isEnabled = false;
|
||
|
|
||
|
@Override
|
||
|
public boolean isEnabled() {
|
||
|
return isEnabled;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Gets the given marker set (and creates it if necessary)
|
||
|
*
|
||
|
* @param dynmapAPI <p>A reference to dynmap's API</p>
|
||
|
* @param setId <p>The id of the marker set to get</p>
|
||
|
* @param label <p>The label of the marker set if creation is necessary</p>
|
||
|
* @return <p>The marker set, or null if something went wrong</p>
|
||
|
*/
|
||
|
protected MarkerSet getMarkerSet(DynmapAPI dynmapAPI, String setId, String label) {
|
||
|
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet(setId);
|
||
|
if (markerSet == null) {
|
||
|
markerSet = dynmapAPI.getMarkerAPI().createMarkerSet(setId, label, null, false);
|
||
|
if (markerSet == null) {
|
||
|
DynmapCitizens.getInstance().getLogger().log(Level.SEVERE, "Unable to get or create " + setId +
|
||
|
" marker set");
|
||
|
DynmapCitizens.getInstance().onDisable();
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
return markerSet;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Adds a marker for an NPC
|
||
|
*
|
||
|
* @param npcId <p>The if of the NPC</p>
|
||
|
* @param markerName <p>The name of the NPC marker</p>
|
||
|
* @param markerDescription <p>The description of the NPC marker</p>
|
||
|
* @param icon <p>The icon used for the marker</p>
|
||
|
* @param markerSet <p>The marker set to add the marker to</p>
|
||
|
*/
|
||
|
protected void addNPCMarker(UUID npcId, String markerName, String markerDescription, MarkerIcon icon, MarkerSet markerSet) {
|
||
|
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(npcId);
|
||
|
//If the NPC has been removed, abort
|
||
|
if (npc == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
//Skip if not a proper location
|
||
|
Location npcLocation = npc.getStoredLocation();
|
||
|
World world = npcLocation.getWorld();
|
||
|
if (world == null) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Marker marker = markerSet.createMarker(null, markerName + npc.getName(), npcLocation.getWorld().getName(),
|
||
|
npcLocation.getX(), npcLocation.getY(), npcLocation.getZ(), icon, false);
|
||
|
if (marker != null) {
|
||
|
marker.setDescription(markerDescription);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|