From ac5b82b3f1cbfc2e3972f2ee1e77b40590ca15c2 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 3 Nov 2022 17:15:37 +0100 Subject: [PATCH] Adds full configuration for quest area marker style --- .../dynmapcitizens/DynmapCitizens.java | 2 + .../handler/trait/quests/QuestsHandler.java | 80 ++++++++--- .../settings/AreaMarkerSettings.java | 130 ++++++++++++++++++ .../settings/QuestsSettings.java | 22 +++ src/main/resources/config.yml | 4 + 5 files changed, 216 insertions(+), 22 deletions(-) create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/AreaMarkerSettings.java diff --git a/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java b/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java index 8af37d9..44a9cb6 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java @@ -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 diff --git a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/quests/QuestsHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/quests/QuestsHandler.java index 83109b0..cca3612 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/quests/QuestsHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/quests/QuestsHandler.java @@ -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 markerIcons; private Map 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

A reference to the Dynmap API

+ * @param markerSettings

The settings to use for initialization

+ * @return

The initialized marker

+ */ + 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

The stage to search for reach locations

*/ 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 += "" + areaName + "
"; } 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

The stage to search for kill locations

*/ 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() + "
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

The location to mark

- * @param radius

The radius of the circular area to mark

- * @param description

The description to put on the marker

- * @param fillColor

The color to use inside the marker area

- * @param lineColor

The color to use outside the marker area

+ * @param location

The location to mark

+ * @param radius

The radius of the circular area to mark

+ * @param description

The description to put on the marker

+ * @param markerSet

The marker set to use when marking the location

+ * @param markerSettings

The settings to use for the marker

*/ - 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

A hexadecimal color

+ * @return

An integer representation of the color

+ */ + private int getColor(String color) { + try { + return Integer.parseInt(color, 16); + } catch (NumberFormatException exception) { + return 0; } } diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/AreaMarkerSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/AreaMarkerSettings.java new file mode 100644 index 0000000..f581383 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/AreaMarkerSettings.java @@ -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

The file configuration to load settings from

+ * @param configRoot

The config root node containing all config values for one marker

+ */ + 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

True if this are marker type is disabled

+ */ + public boolean isDisabled() { + return !this.enabled; + } + + /** + * Gets the priority of this marker-set's markers (dynmap layer priority) + * + * @return

The priority of this marker set

+ */ + public int getMarkerSetPriority() { + return this.markerSetPriority; + } + + /** + * Gets the dynmap id of this marker set + * + * @return

The dynmap id of this marker set

+ */ + public String getMarkerSetId() { + return this.markerSetId; + } + + /** + * Gets the name of this marker set + * + * @return

The name of this marker set

+ */ + public String getMarkerSetName() { + return this.markerSetName; + } + + /** + * Gets whether this marker set should be hidden by default + * + * @return

Whether this marker set should be hidden by default

+ */ + public boolean markersHiddenByDefault() { + return this.markersHiddenByDefault; + } + + /** + * Gets the color of the filled-in area of this set's markers + * + * @return

The marker fill color

+ */ + public String getFillColor() { + return this.fillColor; + } + + /** + * Gets the color of the line around the filled-in area of this set's markers + * + * @return

The marker outline color

+ */ + public String getLineColor() { + return this.lineColor; + } + + /** + * Gets the opacity of the filled-in are of this set's markers + * + * @return

The opacity of the filled area

+ */ + public double getFillOpacity() { + return this.fillOpacity; + } + + /** + * Gets the opacity of the line around the filled-in area of this set's markers + * + * @return

The marker outline opacity

+ */ + public double getLineOpacity() { + return this.lineOpacity; + } + + /** + * Gets the thickness of the line around the filled-in area of this set's markers + * + * @return

The marker outline thickness

+ */ + public int getLineThickness() { + return this.lineThickness; + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java index c89fa92..ac279a3 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java @@ -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

Settings for the kill area markers

+ */ + public AreaMarkerSettings getKillAreaSettings() { + return killAreaSettings; + } + + /** + * Gets settings for the reach area markers + * + * @return

Settings for the reach area markers

+ */ + public AreaMarkerSettings getReachAreaSettings() { + return reachAreaSettings; + } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index aa95b02..0cad028 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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