Adds full configuration for quest area marker style
This commit is contained in:
parent
0cbc7ae1b2
commit
ac5b82b3f1
@ -45,6 +45,8 @@ public final class DynmapCitizens extends JavaPlugin {
|
||||
this.saveDefaultConfig();
|
||||
configuration.options().copyDefaults(true);
|
||||
this.saveConfig();
|
||||
this.reloadConfig();
|
||||
configuration = this.getConfig();
|
||||
this.globalSettings.load(configuration);
|
||||
|
||||
//Initialize all enabled traits
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
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,7 +299,7 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,25 +309,40 @@ public class QuestsHandler extends AbstractTraitHandler {
|
||||
* @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 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,130 @@
|
||||
package net.knarcraft.dynmapcitizens.settings;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* Stores information about one kind of area marker
|
||||
*/
|
||||
public class AreaMarkerSettings {
|
||||
|
||||
private boolean enabled;
|
||||
private int markerSetPriority;
|
||||
private String markerSetId;
|
||||
private String markerSetName;
|
||||
private boolean markersHiddenByDefault;
|
||||
private String fillColor;
|
||||
private String lineColor;
|
||||
private double fillOpacity;
|
||||
private double lineOpacity;
|
||||
private int lineThickness;
|
||||
|
||||
/**
|
||||
* Loads all configuration values for one area marker
|
||||
*
|
||||
* @param fileConfiguration <p>The file configuration to load settings from</p>
|
||||
* @param configRoot <p>The config root node containing all config values for one marker</p>
|
||||
*/
|
||||
public void load(FileConfiguration fileConfiguration, String configRoot) {
|
||||
this.enabled = fileConfiguration.getBoolean(configRoot + ".enabled", false);
|
||||
this.markerSetPriority = fileConfiguration.getInt(configRoot + ".markerSetPriority", 1);
|
||||
this.markerSetId = fileConfiguration.getString(configRoot + ".markerSetId", null);
|
||||
this.markerSetName = fileConfiguration.getString(configRoot + ".markerSetName", null);
|
||||
this.markersHiddenByDefault = fileConfiguration.getBoolean(configRoot + ".markersHiddenByDefault", true);
|
||||
this.fillColor = fileConfiguration.getString(configRoot + ".fillColor", null);
|
||||
this.lineColor = fileConfiguration.getString(configRoot + ".lineColor", null);
|
||||
this.fillOpacity = fileConfiguration.getDouble(configRoot + ".lineColor", 0.3);
|
||||
this.lineOpacity = fileConfiguration.getDouble(configRoot + ".lineOpacity", 1.0);
|
||||
this.lineThickness = fileConfiguration.getInt(configRoot + ".lineThickness", 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the display of this type of area marker is disabled
|
||||
*
|
||||
* @return <p>True if this are marker type is disabled</p>
|
||||
*/
|
||||
public boolean isDisabled() {
|
||||
return !this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the priority of this marker-set's markers (dynmap layer priority)
|
||||
*
|
||||
* @return <p>The priority of this marker set</p>
|
||||
*/
|
||||
public int getMarkerSetPriority() {
|
||||
return this.markerSetPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the dynmap id of this marker set
|
||||
*
|
||||
* @return <p>The dynmap id of this marker set</p>
|
||||
*/
|
||||
public String getMarkerSetId() {
|
||||
return this.markerSetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this marker set
|
||||
*
|
||||
* @return <p>The name of this marker set</p>
|
||||
*/
|
||||
public String getMarkerSetName() {
|
||||
return this.markerSetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this marker set should be hidden by default
|
||||
*
|
||||
* @return <p>Whether this marker set should be hidden by default</p>
|
||||
*/
|
||||
public boolean markersHiddenByDefault() {
|
||||
return this.markersHiddenByDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the filled-in area of this set's markers
|
||||
*
|
||||
* @return <p>The marker fill color</p>
|
||||
*/
|
||||
public String getFillColor() {
|
||||
return this.fillColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the line around the filled-in area of this set's markers
|
||||
*
|
||||
* @return <p>The marker outline color</p>
|
||||
*/
|
||||
public String getLineColor() {
|
||||
return this.lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opacity of the filled-in are of this set's markers
|
||||
*
|
||||
* @return <p>The opacity of the filled area</p>
|
||||
*/
|
||||
public double getFillOpacity() {
|
||||
return this.fillOpacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opacity of the line around the filled-in area of this set's markers
|
||||
*
|
||||
* @return <p>The marker outline opacity</p>
|
||||
*/
|
||||
public double getLineOpacity() {
|
||||
return this.lineOpacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the thickness of the line around the filled-in area of this set's markers
|
||||
*
|
||||
* @return <p>The marker outline thickness</p>
|
||||
*/
|
||||
public int getLineThickness() {
|
||||
return this.lineThickness;
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,8 @@ public class QuestsSettings extends AbstractTraitSettings {
|
||||
private boolean displayPlannerInfo;
|
||||
private boolean displayStageInfo;
|
||||
private boolean displayRequirementInfo;
|
||||
private final AreaMarkerSettings killAreaSettings = new AreaMarkerSettings();
|
||||
private final AreaMarkerSettings reachAreaSettings = new AreaMarkerSettings();
|
||||
|
||||
@Override
|
||||
public void load(FileConfiguration configuration) {
|
||||
@ -19,6 +21,8 @@ public class QuestsSettings extends AbstractTraitSettings {
|
||||
this.displayPlannerInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayPlannerInfo", true);
|
||||
this.displayStageInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayStageInfo", true);
|
||||
this.displayRequirementInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayRequirementInfo", true);
|
||||
this.killAreaSettings.load(configuration, getTraitConfigRoot() + ".circleMarker.killMarker");
|
||||
this.reachAreaSettings.load(configuration, getTraitConfigRoot() + ".circleMarker.reachMarker");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,4 +66,22 @@ public class QuestsSettings extends AbstractTraitSettings {
|
||||
return this.displayRequirementInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets settings for the kill area markers
|
||||
*
|
||||
* @return <p>Settings for the kill area markers</p>
|
||||
*/
|
||||
public AreaMarkerSettings getKillAreaSettings() {
|
||||
return killAreaSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets settings for the reach area markers
|
||||
*
|
||||
* @return <p>Settings for the reach area markers</p>
|
||||
*/
|
||||
public AreaMarkerSettings getReachAreaSettings() {
|
||||
return reachAreaSettings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ traits:
|
||||
markerSetPriority: 1
|
||||
# The id of the quest kill area marker set. Change if it overlaps with an existing set id
|
||||
markerSetId: "quests_kill"
|
||||
# The name of the kill areas marker set. Change it if you want a cooler name
|
||||
markerSetName: "Kill regions"
|
||||
# Whether to hide the quest kill area layer by default
|
||||
markersHiddenByDefault: true
|
||||
# The color used for the filled in area
|
||||
@ -73,6 +75,8 @@ traits:
|
||||
markerSetPriority: 1
|
||||
# The id of the quest reach area marker set. Change if it overlaps with an existing set id
|
||||
markerSetId: "quests_reach"
|
||||
# The name of the reach areas marker set. Change it if you want a cooler name
|
||||
markerSetName: "Reach areas"
|
||||
# Whether to hide the quest reach area layer by default
|
||||
markersHiddenByDefault: true
|
||||
# The color used for the filled in area
|
||||
|
Loading…
Reference in New Issue
Block a user