From 1906e593e3773aea4e277cc970c7570823c0634c Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 3 Nov 2022 14:14:24 +0100 Subject: [PATCH] Implements configuration for common configuration values Makes "enabled", marker set id, marker set priority, hide markers by default and marker set name configurable for all trait handlers. Makes "displayMinstrelSongs" configurable for minstrels --- .../dynmapcitizens/DynmapCitizens.java | 93 ++++++++++--------- .../handler/trait/AbstractTraitHandler.java | 20 +++- .../handler/trait/BlacksmithHandler.java | 27 +++--- .../handler/trait/CitizensTraitHandler.java | 9 ++ .../handler/trait/MinstrelHandler.java | 38 ++++---- .../handler/trait/SentinelHandler.java | 27 +++--- .../handler/trait/quests/QuestsHandler.java | 30 +++--- .../settings/AbstractTraitSettings.java | 57 ++++++++++++ .../settings/BlacksmithSettings.java | 20 ++++ .../settings/GlobalSettings.java | 88 ++++++++++++++++++ .../settings/MinstrelSettings.java | 32 +++++++ .../settings/QuestsSettings.java | 20 ++++ .../settings/SentinelSettings.java | 20 ++++ .../settings/TraitSettings.java | 54 +++++++++++ src/main/resources/config.yml | 44 ++++++++- 15 files changed, 471 insertions(+), 108 deletions(-) create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/AbstractTraitSettings.java create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/BlacksmithSettings.java create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/GlobalSettings.java create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/MinstrelSettings.java create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/SentinelSettings.java create mode 100644 src/main/java/net/knarcraft/dynmapcitizens/settings/TraitSettings.java diff --git a/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java b/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java index 3622c69..e32881e 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/DynmapCitizens.java @@ -6,19 +6,16 @@ import net.knarcraft.dynmapcitizens.handler.trait.CitizensTraitHandler; import net.knarcraft.dynmapcitizens.handler.trait.MinstrelHandler; import net.knarcraft.dynmapcitizens.handler.trait.SentinelHandler; import net.knarcraft.dynmapcitizens.handler.trait.quests.QuestsHandler; -import net.knarcraft.dynmapcitizens.property.Icon; +import net.knarcraft.dynmapcitizens.settings.GlobalSettings; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.dynmap.DynmapAPI; -import org.dynmap.markers.MarkerAPI; -import org.dynmap.markers.MarkerIcon; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.logging.Level; @SuppressWarnings("unused") @@ -26,8 +23,9 @@ public final class DynmapCitizens extends JavaPlugin { private static DynmapCitizens instance; private DynmapAPI dynmapAPI; - private Map markerIcons; private VaultHandler vaultHandler; + private GlobalSettings globalSettings; + private List traitHandlers; @Override public void onEnable() { @@ -42,28 +40,24 @@ public final class DynmapCitizens extends JavaPlugin { } this.dynmapAPI = dynmapAPI; - //Sets all icons used for displaying NPC locations - loadMarkerIcons(); + globalSettings = new GlobalSettings(); + FileConfiguration configuration = this.getConfig(); + this.saveDefaultConfig(); + configuration.options().copyDefaults(true); + this.saveConfig(); + globalSettings.load(configuration); - //Setup all trait handlers - List handlers = new ArrayList<>(); - handlers.add(new BlacksmithHandler()); - handlers.add(new QuestsHandler()); - handlers.add(new SentinelHandler()); - handlers.add(new MinstrelHandler()); - for (CitizensTraitHandler handler : handlers) { - handler.initialize(); - handler.updateMarkers(); - } + //Initialize all enabled traits + initializeTraitHandlers(configuration); //Schedule handlers to run periodically Bukkit.getScheduler().runTaskTimer(this, () -> { - for (CitizensTraitHandler handler : handlers) { + for (CitizensTraitHandler handler : traitHandlers) { if (handler.isEnabled()) { handler.updateMarkers(); } } - }, 10 * 20, 300 * 20); + }, 10 * 20, globalSettings.getUpdateAllMarkersDelay() * 20); vaultHandler = new VaultHandler(this.getServer().getServicesManager()); } @@ -73,6 +67,15 @@ public final class DynmapCitizens extends JavaPlugin { } + /** + * Gets the global settings for this plugin + * + * @return

The global settings for this plugin

+ */ + public GlobalSettings getGlobalSettings() { + return globalSettings; + } + /** * Gets the Vault handler to use for anything Vault-related * @@ -91,15 +94,6 @@ public final class DynmapCitizens extends JavaPlugin { return this.dynmapAPI; } - /** - * Gets a map of loaded marker icons - * - * @return

All marker icons

- */ - public Map getMarkerIcons() { - return new HashMap<>(this.markerIcons); - } - /** * Gets an instance of this plugin * @@ -110,21 +104,34 @@ public final class DynmapCitizens extends JavaPlugin { } /** - * Loads necessary marker icons, and updates icons for the dynmap drawer + * Initializes all trait handlers + * + * @param configuration

The configuration to read settings from

*/ - private void loadMarkerIcons() { - //TODO: Make every icon configurable - MarkerAPI markerAPI = dynmapAPI.getMarkerAPI(); - Map markerIcons = new HashMap<>(); - markerIcons.put(Icon.QUEST_GIVER, markerAPI.getMarkerIcon("exclamation")); - markerIcons.put(Icon.QUEST_DELIVER, markerAPI.getMarkerIcon("basket")); - markerIcons.put(Icon.QUEST_KILL, markerAPI.getMarkerIcon("skull")); - markerIcons.put(Icon.QUEST_INTERACT, markerAPI.getMarkerIcon("comment")); - markerIcons.put(Icon.BLACKSMITH, markerAPI.getMarkerIcon("hammer")); - markerIcons.put(Icon.SENTINEL, markerAPI.getMarkerIcon("shield")); - markerIcons.put(Icon.QUEST_CHAIN, markerAPI.getMarkerIcon("caution")); - markerIcons.put(Icon.MINSTREL, markerAPI.getMarkerIcon("theater")); - this.markerIcons = markerIcons; + private void initializeTraitHandlers(FileConfiguration configuration) { + //Register all trait handlers + traitHandlers = new ArrayList<>(); + traitHandlers.add(new BlacksmithHandler()); + traitHandlers.add(new QuestsHandler()); + traitHandlers.add(new SentinelHandler()); + traitHandlers.add(new MinstrelHandler()); + + //Load and initialize all enabled trait handlers + for (CitizensTraitHandler handler : traitHandlers) { + //Load configuration values from the config file + handler.getSettings().load(configuration); + //Check if the handler is enabled in the config before doing anything + if (!handler.getSettings().isEnabled()) { + getLogger().log(Level.INFO, handler + " is disabled"); + continue; + } + //Initialize, and update markers if successfully enabled + handler.initialize(); + if (handler.isEnabled()) { + getLogger().log(Level.INFO, handler + " is enabled"); + handler.updateMarkers(); + } + } } } diff --git a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/AbstractTraitHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/AbstractTraitHandler.java index a2d50d6..e5c22c4 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/AbstractTraitHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/AbstractTraitHandler.java @@ -3,6 +3,7 @@ package net.knarcraft.dynmapcitizens.handler.trait; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; import net.knarcraft.dynmapcitizens.DynmapCitizens; +import net.knarcraft.dynmapcitizens.settings.TraitSettings; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -20,12 +21,27 @@ import java.util.logging.Level; public abstract class AbstractTraitHandler implements CitizensTraitHandler { protected boolean isEnabled = false; + protected MarkerSet markerSet; @Override public boolean isEnabled() { return isEnabled; } + /** + * Initializes this trait's marker set + */ + protected void initializeMarkerSet() { + TraitSettings settings = getSettings(); + DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); + markerSet = getMarkerSet(dynmapAPI, settings.getMarkerSetId(), settings.getMarkerSetName()); + if (markerSet != null) { + markerSet.setHideByDefault(settings.markersHiddenByDefault()); + markerSet.setLayerPriority(settings.getMarkerSetPriority()); + isEnabled = true; + } + } + /** * Gets the given marker set (and creates it if necessary) * @@ -84,8 +100,8 @@ public abstract class AbstractTraitHandler implements CitizensTraitHandler { if (marker != null && isMoving(npc)) { Bukkit.getScheduler().scheduleSyncRepeatingTask(DynmapCitizens.getInstance(), () -> marker.setLocation(npcLocation.getWorld().getName(), npc.getStoredLocation().getX(), - npc.getStoredLocation().getY(), npc.getStoredLocation().getZ()), 20, 10 * 20); - //TODO: Make the update rate configurable + npc.getStoredLocation().getY(), npc.getStoredLocation().getZ()), 20, + DynmapCitizens.getInstance().getGlobalSettings().getUpdateMovingNPCDelay() * 20); } } diff --git a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/BlacksmithHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/BlacksmithHandler.java index 4ed0c0c..c4a3d06 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/BlacksmithHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/BlacksmithHandler.java @@ -8,11 +8,11 @@ import net.knarcraft.blacksmith.config.NPCSettings; import net.knarcraft.blacksmith.trait.BlacksmithTrait; import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.property.Icon; +import net.knarcraft.dynmapcitizens.settings.BlacksmithSettings; +import net.knarcraft.dynmapcitizens.settings.TraitSettings; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.dynmap.DynmapAPI; import org.dynmap.markers.GenericMarker; -import org.dynmap.markers.MarkerSet; import java.util.ArrayList; import java.util.List; @@ -23,28 +23,27 @@ import java.util.logging.Level; */ public class BlacksmithHandler extends AbstractTraitHandler { - private MarkerSet blacksmithSet; + private final BlacksmithSettings settings = new BlacksmithSettings(); @Override public void initialize() { BlacksmithPlugin blacksmithPlugin = (BlacksmithPlugin) Bukkit.getServer().getPluginManager().getPlugin("Blacksmith"); - DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); if (blacksmithPlugin != null) { - blacksmithSet = getMarkerSet(dynmapAPI, "blacksmiths", "Blacksmiths"); - if (blacksmithSet != null) { - blacksmithSet.setHideByDefault(false); - blacksmithSet.setLayerPriority(3); - isEnabled = true; - return; - } + super.initializeMarkerSet(); + } else { + super.isEnabled = false; } - isEnabled = false; + } + + @Override + public TraitSettings getSettings() { + return this.settings; } @Override public void updateMarkers() { //Remove existing markers - blacksmithSet.getMarkers().forEach(GenericMarker::deleteMarker); + super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker); Class blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith"); for (NPC npc : CitizensAPI.getNPCRegistry()) { @@ -58,7 +57,7 @@ public class BlacksmithHandler extends AbstractTraitHandler { description = getDetailedBlacksmithInfo(npc, trait.getSettings()); } addNPCMarker(npc.getUniqueId(), "Blacksmith NPC: ", description, - DynmapCitizens.getInstance().getMarkerIcons().get(Icon.BLACKSMITH), blacksmithSet); + DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.BLACKSMITH), super.markerSet); } } } diff --git a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/CitizensTraitHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/CitizensTraitHandler.java index a9cbaf6..c740edf 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/CitizensTraitHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/CitizensTraitHandler.java @@ -1,5 +1,7 @@ package net.knarcraft.dynmapcitizens.handler.trait; +import net.knarcraft.dynmapcitizens.settings.TraitSettings; + /** * A handler which takes care of everything for one citizen trait */ @@ -17,6 +19,13 @@ public interface CitizensTraitHandler { */ boolean isEnabled(); + /** + * Gets the settings set for this trait + * + * @return

The settings for this trait

+ */ + TraitSettings getSettings(); + /** * Updates all markers used for this handler */ diff --git a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/MinstrelHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/MinstrelHandler.java index 07ef46c..d4b8708 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/MinstrelHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/MinstrelHandler.java @@ -5,13 +5,13 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.property.Icon; +import net.knarcraft.dynmapcitizens.settings.MinstrelSettings; +import net.knarcraft.dynmapcitizens.settings.TraitSettings; import net.knarcraft.minstrel.MinstrelPlugin; import net.knarcraft.minstrel.music.Song; import net.knarcraft.minstrel.trait.MinstrelTrait; import org.bukkit.Bukkit; -import org.dynmap.DynmapAPI; import org.dynmap.markers.GenericMarker; -import org.dynmap.markers.MarkerSet; import java.util.logging.Level; @@ -20,28 +20,27 @@ import java.util.logging.Level; */ public class MinstrelHandler extends AbstractTraitHandler { - private MarkerSet minstrelSet; + private final MinstrelSettings settings = new MinstrelSettings(); @Override public void initialize() { MinstrelPlugin minstrelPlugin = (MinstrelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Minstrel"); - DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); if (minstrelPlugin != null) { - minstrelSet = getMarkerSet(dynmapAPI, "minstrels", "Minstrels"); - if (minstrelSet != null) { - minstrelSet.setHideByDefault(false); - minstrelSet.setLayerPriority(3); - isEnabled = true; - return; - } + super.initializeMarkerSet(); + } else { + super.isEnabled = false; } - isEnabled = false; + } + + @Override + public TraitSettings getSettings() { + return this.settings; } @Override public void updateMarkers() { //Remove existing markers - minstrelSet.getMarkers().forEach(GenericMarker::deleteMarker); + super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker); Class minstrelTrait = CitizensAPI.getTraitFactory().getTraitClass("minstrel"); for (NPC npc : CitizensAPI.getNPCRegistry()) { @@ -54,7 +53,7 @@ public class MinstrelHandler extends AbstractTraitHandler { description = getDetailedMinstrelInfo(npc, trait); } addNPCMarker(npc.getUniqueId(), "Minstrel NPC: ", description, - DynmapCitizens.getInstance().getMarkerIcons().get(Icon.MINSTREL), minstrelSet); + DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.MINSTREL), super.markerSet); } } } @@ -68,11 +67,14 @@ public class MinstrelHandler extends AbstractTraitHandler { */ private String getDetailedMinstrelInfo(NPC npc, MinstrelTrait trait) { StringBuilder info = new StringBuilder("

" + npc.getName() + "

"); - info.append("Songs:
    "); - for (Song song : trait.getPlaylist().getSongs()) { - info.append("
  • Category: ").append(song.getCategory()).append("
    Sound: ").append(song.getSound()).append("
  • "); + if (this.settings.displayMinstrelSongs()) { + info.append("Songs:
      "); + for (Song song : trait.getPlaylist().getSongs()) { + info.append("
    • Category: ").append(song.getCategory()).append("
      Sound: ").append(song.getSound()); + info.append("
    • "); + } + info.append("
    "); } - info.append("
"); return info.toString(); } diff --git a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/SentinelHandler.java b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/SentinelHandler.java index 245bda3..24fb7e9 100644 --- a/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/SentinelHandler.java +++ b/src/main/java/net/knarcraft/dynmapcitizens/handler/trait/SentinelHandler.java @@ -5,10 +5,10 @@ import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.property.Icon; +import net.knarcraft.dynmapcitizens.settings.SentinelSettings; +import net.knarcraft.dynmapcitizens.settings.TraitSettings; import org.bukkit.Bukkit; -import org.dynmap.DynmapAPI; import org.dynmap.markers.GenericMarker; -import org.dynmap.markers.MarkerSet; import org.mcmonkey.sentinel.SentinelPlugin; import org.mcmonkey.sentinel.SentinelTrait; @@ -17,27 +17,26 @@ import org.mcmonkey.sentinel.SentinelTrait; */ public class SentinelHandler extends AbstractTraitHandler { - private MarkerSet sentinelSet; + protected final SentinelSettings settings = new SentinelSettings(); @Override public void initialize() { SentinelPlugin sentinelPlugin = (SentinelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Sentinel"); - DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); if (sentinelPlugin != null) { - sentinelSet = getMarkerSet(dynmapAPI, "sentinels", "Sentinels"); - if (sentinelSet != null) { - sentinelSet.setHideByDefault(false); - sentinelSet.setLayerPriority(1); - isEnabled = true; - return; - } + super.initializeMarkerSet(); + } else { + super.isEnabled = false; } - isEnabled = false; + } + + @Override + public TraitSettings getSettings() { + return this.settings; } @Override public void updateMarkers() { - sentinelSet.getMarkers().forEach(GenericMarker::deleteMarker); + super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker); Class sentinelTrait = CitizensAPI.getTraitFactory().getTraitClass("sentinel"); for (NPC npc : CitizensAPI.getNPCRegistry()) { @@ -54,7 +53,7 @@ public class SentinelHandler extends AbstractTraitHandler { description += "
Targets: " + trait.allTargets.toAllInOneString() + "
Avoids: " + trait.allAvoids.toAllInOneString() + "
Ignores: " + trait.allIgnores.toAllInOneString(); addNPCMarker(npc.getUniqueId(), "Sentinel NPC: ", description, - DynmapCitizens.getInstance().getMarkerIcons().get(Icon.SENTINEL), sentinelSet); + DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.SENTINEL), super.markerSet); } } } 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 ef40440..2dbb68a 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,8 @@ 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.QuestsSettings; +import net.knarcraft.dynmapcitizens.settings.TraitSettings; import net.knarcraft.dynmapcitizens.util.QuestsHelper; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -33,31 +35,33 @@ import java.util.logging.Level; public class QuestsHandler extends AbstractTraitHandler { private QuestsAPI questsAPI; - private MarkerSet questMarkerSet; private MarkerSet questAreaMarkerSet; private Map markerIcons; private Map questGiverInfo; + private final QuestsSettings settings = new QuestsSettings(); @Override public void initialize() { questsAPI = (QuestsAPI) Bukkit.getServer().getPluginManager().getPlugin("Quests"); DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); - markerIcons = DynmapCitizens.getInstance().getMarkerIcons(); + markerIcons = DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons(); if (questsAPI != null) { - questMarkerSet = getMarkerSet(dynmapAPI, "quests", "Quests"); + super.initializeMarkerSet(); questAreaMarkerSet = getMarkerSet(dynmapAPI, "quest_areas", "Quest areas"); - if (questMarkerSet != null && questAreaMarkerSet != null) { - questMarkerSet.setHideByDefault(false); + if (questAreaMarkerSet != null) { questAreaMarkerSet.setHideByDefault(true); - questMarkerSet.setLayerPriority(3); questAreaMarkerSet.setLayerPriority(2); - isEnabled = true; //Remove old quest markers - questMarkerSet.getMarkers().forEach(GenericMarker::deleteMarker); - return; + super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker); } + } else { + isEnabled = false; } - isEnabled = false; + } + + @Override + public TraitSettings getSettings() { + return settings; } @Override @@ -73,7 +77,7 @@ public class QuestsHandler extends AbstractTraitHandler { generateQuestNPCInfo(); //Remove any markers for deleted quests - for (Marker marker : questMarkerSet.getMarkers()) { + for (Marker marker : super.markerSet.getMarkers()) { if (!questGiverInfo.containsKey(UUID.fromString(marker.getMarkerID()))) { marker.deleteMarker(); } @@ -137,14 +141,14 @@ public class QuestsHandler extends AbstractTraitHandler { markerDescription.append(getInvolvedInQuestsString(info)); - Marker existingMarker = questMarkerSet.findMarker(npcId.toString()); + Marker existingMarker = super.markerSet.findMarker(npcId.toString()); String newDescription = markerDescription.toString(); if (existingMarker != null) { if (!existingMarker.getDescription().equals(newDescription)) { existingMarker.setDescription(newDescription); } } else { - addNPCMarker(npcId, QuestsHelper.getMarkerTitle(info.getQuestNPCType()), newDescription, icon, questMarkerSet); + addNPCMarker(npcId, QuestsHelper.getMarkerTitle(info.getQuestNPCType()), newDescription, icon, super.markerSet); } } } diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/AbstractTraitSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/AbstractTraitSettings.java new file mode 100644 index 0000000..e767e10 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/AbstractTraitSettings.java @@ -0,0 +1,57 @@ +package net.knarcraft.dynmapcitizens.settings; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * An abstract implementation of trait settings + */ +public abstract class AbstractTraitSettings implements TraitSettings { + + private boolean isEnabled; + private String markerSetId; + private int markerSetPriority; + private boolean hideMarkersByDefault; + private String markerSetName; + + @Override + public void load(FileConfiguration configuration) { + this.isEnabled = configuration.getBoolean(getTraitConfigRoot() + ".enabled", false); + this.markerSetId = configuration.getString(getTraitConfigRoot() + ".markerSetId", null); + this.markerSetPriority = configuration.getInt(getTraitConfigRoot() + ".markerSetPriority", 1); + this.hideMarkersByDefault = configuration.getBoolean(getTraitConfigRoot() + ".markersHiddenByDefault", false); + this.markerSetName = configuration.getString(getTraitConfigRoot() + ".markerSetName", null); + } + + @Override + public boolean isEnabled() { + return isEnabled; + } + + @Override + public String getMarkerSetId() { + return markerSetId; + } + + @Override + public String getMarkerSetName() { + return markerSetName; + } + + @Override + public int getMarkerSetPriority() { + return markerSetPriority; + } + + @Override + public boolean markersHiddenByDefault() { + return hideMarkersByDefault; + } + + /** + * Gets the root config node for this trait's settings + * + * @return

The root config node for this trait's settings

+ */ + protected abstract String getTraitConfigRoot(); + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/BlacksmithSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/BlacksmithSettings.java new file mode 100644 index 0000000..4faade9 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/BlacksmithSettings.java @@ -0,0 +1,20 @@ +package net.knarcraft.dynmapcitizens.settings; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * All settings for the blacksmith trait + */ +public class BlacksmithSettings extends AbstractTraitSettings { + + @Override + public void load(FileConfiguration configuration) { + super.load(configuration); + } + + @Override + protected String getTraitConfigRoot() { + return "traits.blacksmith"; + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/GlobalSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/GlobalSettings.java new file mode 100644 index 0000000..a7fe753 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/GlobalSettings.java @@ -0,0 +1,88 @@ +package net.knarcraft.dynmapcitizens.settings; + +import net.knarcraft.dynmapcitizens.DynmapCitizens; +import net.knarcraft.dynmapcitizens.property.Icon; +import org.bukkit.configuration.file.FileConfiguration; +import org.dynmap.DynmapAPI; +import org.dynmap.markers.MarkerAPI; +import org.dynmap.markers.MarkerIcon; + +import java.util.HashMap; +import java.util.Map; + +/** + * A representation of all settings not specific to one trait + */ +public class GlobalSettings { + + private final Map markerIcons = new HashMap<>(); + private long updateMovingNPCDelay; + private long updateAllMarkersDelay; + + /** + * Loads all global settings from the given configuration + * + * @param configuration

The configuration to load from

+ */ + public void load(FileConfiguration configuration) { + DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); + MarkerAPI markerAPI = dynmapAPI.getMarkerAPI(); + + //Load the icons to use + for (Icon icon : Icon.values()) { + markerIcons.put(icon, markerAPI.getMarkerIcon(configuration.getString("icon." + icon.name(), + getDefaultIconName(icon)))); + } + + updateMovingNPCDelay = configuration.getLong("timer.updateMovingNPCDelay", 10); + updateAllMarkersDelay = configuration.getLong("timer.updateAllMarkersDelay", 300); + } + + /** + * Gets the marker icons to use + * + * @return

The marker icons to use

+ */ + public Map getMarkerIcons() { + return new HashMap<>(markerIcons); + } + + /** + * Gets the delay to wait between each time a moving NPC's marker is updated + * + * @return

The update delay for moving NPCs

+ */ + public long getUpdateMovingNPCDelay() { + return updateMovingNPCDelay; + } + + /** + * Gets the delay to wait between each time all markers are updated + * + * @return

The update delay for all markers

+ */ + public long getUpdateAllMarkersDelay() { + return updateAllMarkersDelay; + } + + /** + * Gets the default icon name for the given icon identifier + * + * @param icon

The icon identifier to get the icon for

+ * @return

The default icon name

+ */ + private String getDefaultIconName(Icon icon) { + //The advantage of this switch over a map is that it will throw an error if a case is missing + return switch (icon) { + case QUEST_GIVER -> "exclamation"; + case QUEST_DELIVER -> "basket"; + case QUEST_KILL -> "skull"; + case QUEST_INTERACT -> "comment"; + case QUEST_CHAIN -> "caution"; + case BLACKSMITH -> "hammer"; + case SENTINEL -> "shield"; + case MINSTREL -> "theater"; + }; + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/MinstrelSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/MinstrelSettings.java new file mode 100644 index 0000000..bf63599 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/MinstrelSettings.java @@ -0,0 +1,32 @@ +package net.knarcraft.dynmapcitizens.settings; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * All settings for the minstrel trait + */ +public class MinstrelSettings extends AbstractTraitSettings { + + private boolean displayMinstrelSongs; + + @Override + public void load(FileConfiguration configuration) { + super.load(configuration); + displayMinstrelSongs = configuration.getBoolean(getTraitConfigRoot() + ".displayMinstrelSongs", true); + } + + @Override + protected String getTraitConfigRoot() { + return "traits.minstrel"; + } + + /** + * Gets whether a minstrel's songs should be displayed in their description + * + * @return

True if minstrel songs should be displayed

+ */ + public boolean displayMinstrelSongs() { + return displayMinstrelSongs; + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java new file mode 100644 index 0000000..962179f --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/QuestsSettings.java @@ -0,0 +1,20 @@ +package net.knarcraft.dynmapcitizens.settings; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * All settings for the quests trait + */ +public class QuestsSettings extends AbstractTraitSettings { + + @Override + public void load(FileConfiguration configuration) { + super.load(configuration); + } + + @Override + protected String getTraitConfigRoot() { + return "traits.quests"; + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/SentinelSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/SentinelSettings.java new file mode 100644 index 0000000..c3a2849 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/SentinelSettings.java @@ -0,0 +1,20 @@ +package net.knarcraft.dynmapcitizens.settings; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * All settings for the sentinel trait + */ +public class SentinelSettings extends AbstractTraitSettings { + + @Override + public void load(FileConfiguration configuration) { + super.load(configuration); + } + + @Override + protected String getTraitConfigRoot() { + return "traits.sentinel"; + } + +} diff --git a/src/main/java/net/knarcraft/dynmapcitizens/settings/TraitSettings.java b/src/main/java/net/knarcraft/dynmapcitizens/settings/TraitSettings.java new file mode 100644 index 0000000..58256a8 --- /dev/null +++ b/src/main/java/net/knarcraft/dynmapcitizens/settings/TraitSettings.java @@ -0,0 +1,54 @@ +package net.knarcraft.dynmapcitizens.settings; + +import org.bukkit.configuration.file.FileConfiguration; + +/** + * An interface describing a generic trait settings class + */ +public interface TraitSettings { + + /** + * Loads the current values of this trait's settings from the given file configuration + * + * @param configuration

The configuration to load values from

+ */ + void load(FileConfiguration configuration); + + /** + * Gets whether this trait type is enabled in the config + * + * @return

True if this trait is enabled

+ */ + boolean isEnabled(); + + /** + * Gets the id of the trait's marker set + * + *

This is mainly configurable in case of duplicate ids

+ * + * @return

The id of the marker set

+ */ + String getMarkerSetId(); + + /** + * Gets the name of this trait's marker set + * + * @return

The name of the marker set

+ */ + String getMarkerSetName(); + + /** + * Gets the priority of the trait's marker set + * + * @return

The priority of the marker set

+ */ + int getMarkerSetPriority(); + + /** + * Gets whether this trait's markers should be hidden by default + * + * @return

Whether markers should be hidden by default

+ */ + boolean markersHiddenByDefault(); + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 78329c8..6ea95aa 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -30,7 +30,13 @@ traits: quests: enabled: true # The priority of quest markers. Higher priority markers will display on top of lower priority ones - priority: 3 + markerSetPriority: 3 + # The id of the quest marker set. Change if it overlaps with an existing set id + markerSetId: "quests" + # The name of the quest marker set. Change it if you want a cooler name + markerSetName: "Quests" + # Whether to hide the quest icon layer by default + markersHiddenByDefault: false # The priority of quest area markers, such as kill areas areaMarkerPriority: 2 # Whether to mark kill areas and similar on the map @@ -47,6 +53,12 @@ traits: circleMarker: # Settings for kill zone markers killMarker: + # The priority of quest kill area markers. Higher priority markers will display on top of lower priority ones + markerSetPriority: 1 + # The id of the quest kill area marker set. Change if it overlaps with an existing set id + markerSetId: "quests_kill" + # Whether to hide the quest kill area layer by default + markersHiddenByDefault: true # The color used for the filled in area fillColor: "EDAFA0" # The color used for the outer line @@ -59,6 +71,12 @@ traits: lineThickness: 2 # Settings for reach area markers reachMarker: + # The priority of quest reach area markers. Higher priority markers will display on top of lower priority ones + markerSetPriority: 1 + # The id of the quest reach area marker set. Change if it overlaps with an existing set id + markerSetId: "quests_reach" + # Whether to hide the quest reach area layer by default + markersHiddenByDefault: true # The color used for the filled in area fillColor: "FFFF99" # The color used for the outer line @@ -73,20 +91,38 @@ traits: blacksmith: enabled: true # The priority of blacksmith markers. Higher priority markers will display on top of lower priority ones - priority: 3 + markerSetPriority: 3 + # The id of the blacksmith marker set. Change if it overlaps with an existing set id + markerSetId: "blacksmiths" + # The name of the blacksmith marker set. Change it if you want a cooler name + markerSetName: "Blacksmiths" + # Whether to hide the blacksmith icon layer by default + markersHiddenByDefault: false # Whether to display the state of blacksmiths' settings, such as fail chance and delays displayBlacksmithSettings: true # Settings for the sentinel trait sentinel: enabled: true # The priority of sentinel markers. Higher priority markers will display on top of lower priority ones - priority: 1 + markerSetPriority: 1 + # The id of the sentinel marker set. Change if it overlaps with an existing set id + markerSetId: "sentinels" + # The name of the sentinel marker set. Change it if you want a cooler name + markerSetName: "Sentinels" + # Whether to hide the sentinel icon layer by default + markersHiddenByDefault: false # Whether to display information about a sentinel's health, armor and damage in the marker description displaySentinelStrength: true # Settings for the minstrel trait minstrel: enabled: true # The priority of sentinel markers. Higher priority markers will display on top of lower priority ones - priority: 3 + markerSetPriority: 3 + # The id of the minstrel marker set. Change if it overlaps with an existing set id + markerSetId: "minstrels" + # The name of the minstrel marker set. Change it if you want a cooler name + markerSetName: "Minstrels" + # Whether to hide the minstrel icon layer by default + markersHiddenByDefault: false # Whether to display the list of songs a minstrel is playing displayMinstrelSongs: true \ No newline at end of file