Adds full configuration for quest area marker style
This commit is contained in:
@ -8,6 +8,7 @@ import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
import net.knarcraft.dynmapcitizens.DynmapCitizens;
|
||||
import net.knarcraft.dynmapcitizens.handler.trait.AbstractTraitHandler;
|
||||
import net.knarcraft.dynmapcitizens.property.Icon;
|
||||
import net.knarcraft.dynmapcitizens.settings.AreaMarkerSettings;
|
||||
import net.knarcraft.dynmapcitizens.settings.QuestsSettings;
|
||||
import net.knarcraft.dynmapcitizens.settings.TraitSettings;
|
||||
import net.knarcraft.dynmapcitizens.util.QuestsHelper;
|
||||
@ -35,7 +36,8 @@ import java.util.logging.Level;
|
||||
public class QuestsHandler extends AbstractTraitHandler {
|
||||
|
||||
private QuestsAPI questsAPI;
|
||||
private MarkerSet questAreaMarkerSet;
|
||||
private MarkerSet killAreaMarkerSet;
|
||||
private MarkerSet reachAreaMarkerSet;
|
||||
private Map<Icon, MarkerIcon> markerIcons;
|
||||
private Map<UUID, NPCQuestInfo> questGiverInfo;
|
||||
private final QuestsSettings settings = new QuestsSettings();
|
||||
@ -47,13 +49,10 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
markerIcons = DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons();
|
||||
if (questsAPI != null) {
|
||||
super.initializeMarkerSet();
|
||||
questAreaMarkerSet = getMarkerSet(dynmapAPI, "quest_areas", "Quest areas");
|
||||
if (questAreaMarkerSet != null) {
|
||||
questAreaMarkerSet.setHideByDefault(true);
|
||||
questAreaMarkerSet.setLayerPriority(2);
|
||||
//Remove old quest markers
|
||||
super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
||||
}
|
||||
super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
|
||||
|
||||
killAreaMarkerSet = initializeMarkerSet(dynmapAPI, settings.getKillAreaSettings());
|
||||
reachAreaMarkerSet = initializeMarkerSet(dynmapAPI, settings.getReachAreaSettings());
|
||||
} else {
|
||||
isEnabled = false;
|
||||
}
|
||||
@ -87,6 +86,22 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
generateAllMarkers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a marker set from the given settings
|
||||
*
|
||||
* @param dynmapAPI <p>A reference to the Dynmap API</p>
|
||||
* @param markerSettings <p>The settings to use for initialization</p>
|
||||
* @return <p>The initialized marker</p>
|
||||
*/
|
||||
private MarkerSet initializeMarkerSet(DynmapAPI dynmapAPI, AreaMarkerSettings markerSettings) {
|
||||
MarkerSet markerSet = getMarkerSet(dynmapAPI, markerSettings.getMarkerSetId(), markerSettings.getMarkerSetName());
|
||||
if (markerSet != null) {
|
||||
markerSet.setHideByDefault(markerSettings.markersHiddenByDefault());
|
||||
markerSet.setLayerPriority(markerSettings.getMarkerSetPriority());
|
||||
}
|
||||
return markerSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates information about all NPCs involved in quests
|
||||
*/
|
||||
@ -227,10 +242,10 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
* Updates all quest area markers
|
||||
*/
|
||||
private void updateQuestAreas() {
|
||||
questAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker);
|
||||
this.killAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker);
|
||||
this.reachAreaMarkerSet.getCircleMarkers().forEach(GenericMarker::deleteMarker);
|
||||
for (IQuest quest : questsAPI.getLoadedQuests()) {
|
||||
for (IStage stage : quest.getStages()) {
|
||||
//TODO: Put kill and reach locations in separate marker sets
|
||||
markKillLocations(quest, stage);
|
||||
markReachLocations(quest, stage);
|
||||
}
|
||||
@ -245,6 +260,9 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
* @param stage <p>The stage to search for reach locations</p>
|
||||
*/
|
||||
private void markReachLocations(IQuest quest, IStage stage) {
|
||||
if (settings.getReachAreaSettings().isDisabled()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < stage.getLocationsToReach().size(); i++) {
|
||||
Location location = stage.getLocationsToReach().get(i);
|
||||
int radius = stage.getRadiiToReachWithin().get(i);
|
||||
@ -254,7 +272,7 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
description += "<b>" + areaName + "</b><br>";
|
||||
}
|
||||
description += "Target location for " + quest.getName();
|
||||
markLocation(location, radius, description, "FFFF99", "36c90e");
|
||||
markLocation(location, radius, description, reachAreaMarkerSet, settings.getReachAreaSettings());
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,6 +283,9 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
* @param stage <p>The stage to search for kill locations</p>
|
||||
*/
|
||||
private void markKillLocations(IQuest quest, IStage stage) {
|
||||
if (settings.getKillAreaSettings().isDisabled()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < stage.getLocationsToKillWithin().size(); i++) {
|
||||
Location location = stage.getLocationsToKillWithin().get(i);
|
||||
int radius = stage.getRadiiToKillWithin().get(i);
|
||||
@ -278,35 +299,50 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
}
|
||||
description += "Kill location for " + quest.getName() +
|
||||
"<br>Kill " + QuestsHelper.normalizeName(mob.name()) + " x " + mobAmount;
|
||||
markLocation(location, radius, description, "EDAFA0", "8B0000");
|
||||
markLocation(location, radius, description, killAreaMarkerSet, settings.getKillAreaSettings());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a location on the dynamic map
|
||||
*
|
||||
* @param location <p>The location to mark</p>
|
||||
* @param radius <p>The radius of the circular area to mark</p>
|
||||
* @param description <p>The description to put on the marker</p>
|
||||
* @param fillColor <p>The color to use inside the marker area</p>
|
||||
* @param lineColor <p>The color to use outside the marker area</p>
|
||||
* @param location <p>The location to mark</p>
|
||||
* @param radius <p>The radius of the circular area to mark</p>
|
||||
* @param description <p>The description to put on the marker</p>
|
||||
* @param markerSet <p>The marker set to use when marking the location</p>
|
||||
* @param markerSettings <p>The settings to use for the marker</p>
|
||||
*/
|
||||
private void markLocation(Location location, Integer radius, String description, String fillColor, String lineColor) {
|
||||
private void markLocation(Location location, Integer radius, String description, MarkerSet markerSet,
|
||||
AreaMarkerSettings markerSettings) {
|
||||
//Skip if location is invalid
|
||||
World world = location.getWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CircleMarker circleMarker = questAreaMarkerSet.createCircleMarker(null, description, true,
|
||||
CircleMarker circleMarker = markerSet.createCircleMarker(null, description, true,
|
||||
world.getName(), location.getX(), location.getY(), location.getZ(), radius, radius, false);
|
||||
if (circleMarker == null) {
|
||||
DynmapCitizens.getInstance().getLogger().log(Level.WARNING, "Unable to create circle marker at " +
|
||||
location + " with radius " + radius);
|
||||
} else {
|
||||
//TODO: Make colors configurable
|
||||
circleMarker.setFillStyle(0.3, Integer.parseInt(fillColor, 16));
|
||||
circleMarker.setLineStyle(2, 1.0, Integer.parseInt(lineColor, 16));
|
||||
circleMarker.setFillStyle(markerSettings.getFillOpacity(), getColor(markerSettings.getFillColor()));
|
||||
circleMarker.setLineStyle(markerSettings.getLineThickness(), markerSettings.getLineOpacity(),
|
||||
getColor(markerSettings.getLineColor()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an integer representation from a hexadecimal color code
|
||||
*
|
||||
* @param color <p>A hexadecimal color</p>
|
||||
* @return <p>An integer representation of the color</p>
|
||||
*/
|
||||
private int getColor(String color) {
|
||||
try {
|
||||
return Integer.parseInt(color, 16);
|
||||
} catch (NumberFormatException exception) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user