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
This commit is contained in:
Kristian Knarvik 2022-11-03 14:14:24 +01:00
parent 0f89c1c29f
commit 1906e593e3
15 changed files with 471 additions and 108 deletions

View File

@ -6,19 +6,16 @@ import net.knarcraft.dynmapcitizens.handler.trait.CitizensTraitHandler;
import net.knarcraft.dynmapcitizens.handler.trait.MinstrelHandler; import net.knarcraft.dynmapcitizens.handler.trait.MinstrelHandler;
import net.knarcraft.dynmapcitizens.handler.trait.SentinelHandler; import net.knarcraft.dynmapcitizens.handler.trait.SentinelHandler;
import net.knarcraft.dynmapcitizens.handler.trait.quests.QuestsHandler; 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.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.DynmapAPI; import org.dynmap.DynmapAPI;
import org.dynmap.markers.MarkerAPI;
import org.dynmap.markers.MarkerIcon;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -26,8 +23,9 @@ public final class DynmapCitizens extends JavaPlugin {
private static DynmapCitizens instance; private static DynmapCitizens instance;
private DynmapAPI dynmapAPI; private DynmapAPI dynmapAPI;
private Map<Icon, MarkerIcon> markerIcons;
private VaultHandler vaultHandler; private VaultHandler vaultHandler;
private GlobalSettings globalSettings;
private List<CitizensTraitHandler> traitHandlers;
@Override @Override
public void onEnable() { public void onEnable() {
@ -42,28 +40,24 @@ public final class DynmapCitizens extends JavaPlugin {
} }
this.dynmapAPI = dynmapAPI; this.dynmapAPI = dynmapAPI;
//Sets all icons used for displaying NPC locations globalSettings = new GlobalSettings();
loadMarkerIcons(); FileConfiguration configuration = this.getConfig();
this.saveDefaultConfig();
configuration.options().copyDefaults(true);
this.saveConfig();
globalSettings.load(configuration);
//Setup all trait handlers //Initialize all enabled traits
List<CitizensTraitHandler> handlers = new ArrayList<>(); initializeTraitHandlers(configuration);
handlers.add(new BlacksmithHandler());
handlers.add(new QuestsHandler());
handlers.add(new SentinelHandler());
handlers.add(new MinstrelHandler());
for (CitizensTraitHandler handler : handlers) {
handler.initialize();
handler.updateMarkers();
}
//Schedule handlers to run periodically //Schedule handlers to run periodically
Bukkit.getScheduler().runTaskTimer(this, () -> { Bukkit.getScheduler().runTaskTimer(this, () -> {
for (CitizensTraitHandler handler : handlers) { for (CitizensTraitHandler handler : traitHandlers) {
if (handler.isEnabled()) { if (handler.isEnabled()) {
handler.updateMarkers(); handler.updateMarkers();
} }
} }
}, 10 * 20, 300 * 20); }, 10 * 20, globalSettings.getUpdateAllMarkersDelay() * 20);
vaultHandler = new VaultHandler(this.getServer().getServicesManager()); vaultHandler = new VaultHandler(this.getServer().getServicesManager());
} }
@ -73,6 +67,15 @@ public final class DynmapCitizens extends JavaPlugin {
} }
/**
* Gets the global settings for this plugin
*
* @return <p>The global settings for this plugin</p>
*/
public GlobalSettings getGlobalSettings() {
return globalSettings;
}
/** /**
* Gets the Vault handler to use for anything Vault-related * Gets the Vault handler to use for anything Vault-related
* *
@ -91,15 +94,6 @@ public final class DynmapCitizens extends JavaPlugin {
return this.dynmapAPI; return this.dynmapAPI;
} }
/**
* Gets a map of loaded marker icons
*
* @return <p>All marker icons</p>
*/
public Map<Icon, MarkerIcon> getMarkerIcons() {
return new HashMap<>(this.markerIcons);
}
/** /**
* Gets an instance of this plugin * 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 <p>The configuration to read settings from</p>
*/ */
private void loadMarkerIcons() { private void initializeTraitHandlers(FileConfiguration configuration) {
//TODO: Make every icon configurable //Register all trait handlers
MarkerAPI markerAPI = dynmapAPI.getMarkerAPI(); traitHandlers = new ArrayList<>();
Map<Icon, MarkerIcon> markerIcons = new HashMap<>(); traitHandlers.add(new BlacksmithHandler());
markerIcons.put(Icon.QUEST_GIVER, markerAPI.getMarkerIcon("exclamation")); traitHandlers.add(new QuestsHandler());
markerIcons.put(Icon.QUEST_DELIVER, markerAPI.getMarkerIcon("basket")); traitHandlers.add(new SentinelHandler());
markerIcons.put(Icon.QUEST_KILL, markerAPI.getMarkerIcon("skull")); traitHandlers.add(new MinstrelHandler());
markerIcons.put(Icon.QUEST_INTERACT, markerAPI.getMarkerIcon("comment"));
markerIcons.put(Icon.BLACKSMITH, markerAPI.getMarkerIcon("hammer")); //Load and initialize all enabled trait handlers
markerIcons.put(Icon.SENTINEL, markerAPI.getMarkerIcon("shield")); for (CitizensTraitHandler handler : traitHandlers) {
markerIcons.put(Icon.QUEST_CHAIN, markerAPI.getMarkerIcon("caution")); //Load configuration values from the config file
markerIcons.put(Icon.MINSTREL, markerAPI.getMarkerIcon("theater")); handler.getSettings().load(configuration);
this.markerIcons = markerIcons; //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();
}
}
} }
} }

View File

@ -3,6 +3,7 @@ package net.knarcraft.dynmapcitizens.handler.trait;
import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.settings.TraitSettings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -20,12 +21,27 @@ import java.util.logging.Level;
public abstract class AbstractTraitHandler implements CitizensTraitHandler { public abstract class AbstractTraitHandler implements CitizensTraitHandler {
protected boolean isEnabled = false; protected boolean isEnabled = false;
protected MarkerSet markerSet;
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
return 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) * 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)) { if (marker != null && isMoving(npc)) {
Bukkit.getScheduler().scheduleSyncRepeatingTask(DynmapCitizens.getInstance(), Bukkit.getScheduler().scheduleSyncRepeatingTask(DynmapCitizens.getInstance(),
() -> marker.setLocation(npcLocation.getWorld().getName(), npc.getStoredLocation().getX(), () -> marker.setLocation(npcLocation.getWorld().getName(), npc.getStoredLocation().getX(),
npc.getStoredLocation().getY(), npc.getStoredLocation().getZ()), 20, 10 * 20); npc.getStoredLocation().getY(), npc.getStoredLocation().getZ()), 20,
//TODO: Make the update rate configurable DynmapCitizens.getInstance().getGlobalSettings().getUpdateMovingNPCDelay() * 20);
} }
} }

View File

@ -8,11 +8,11 @@ import net.knarcraft.blacksmith.config.NPCSettings;
import net.knarcraft.blacksmith.trait.BlacksmithTrait; import net.knarcraft.blacksmith.trait.BlacksmithTrait;
import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.property.Icon; 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.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.GenericMarker; import org.dynmap.markers.GenericMarker;
import org.dynmap.markers.MarkerSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -23,28 +23,27 @@ import java.util.logging.Level;
*/ */
public class BlacksmithHandler extends AbstractTraitHandler { public class BlacksmithHandler extends AbstractTraitHandler {
private MarkerSet blacksmithSet; private final BlacksmithSettings settings = new BlacksmithSettings();
@Override @Override
public void initialize() { public void initialize() {
BlacksmithPlugin blacksmithPlugin = (BlacksmithPlugin) Bukkit.getServer().getPluginManager().getPlugin("Blacksmith"); BlacksmithPlugin blacksmithPlugin = (BlacksmithPlugin) Bukkit.getServer().getPluginManager().getPlugin("Blacksmith");
DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI();
if (blacksmithPlugin != null) { if (blacksmithPlugin != null) {
blacksmithSet = getMarkerSet(dynmapAPI, "blacksmiths", "Blacksmiths"); super.initializeMarkerSet();
if (blacksmithSet != null) { } else {
blacksmithSet.setHideByDefault(false); super.isEnabled = false;
blacksmithSet.setLayerPriority(3);
isEnabled = true;
return;
}
} }
isEnabled = false; }
@Override
public TraitSettings getSettings() {
return this.settings;
} }
@Override @Override
public void updateMarkers() { public void updateMarkers() {
//Remove existing markers //Remove existing markers
blacksmithSet.getMarkers().forEach(GenericMarker::deleteMarker); super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
Class<? extends Trait> blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith"); Class<? extends Trait> blacksmithTrait = CitizensAPI.getTraitFactory().getTraitClass("blacksmith");
for (NPC npc : CitizensAPI.getNPCRegistry()) { for (NPC npc : CitizensAPI.getNPCRegistry()) {
@ -58,7 +57,7 @@ public class BlacksmithHandler extends AbstractTraitHandler {
description = getDetailedBlacksmithInfo(npc, trait.getSettings()); description = getDetailedBlacksmithInfo(npc, trait.getSettings());
} }
addNPCMarker(npc.getUniqueId(), "Blacksmith NPC: ", description, addNPCMarker(npc.getUniqueId(), "Blacksmith NPC: ", description,
DynmapCitizens.getInstance().getMarkerIcons().get(Icon.BLACKSMITH), blacksmithSet); DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.BLACKSMITH), super.markerSet);
} }
} }
} }

View File

@ -1,5 +1,7 @@
package net.knarcraft.dynmapcitizens.handler.trait; package net.knarcraft.dynmapcitizens.handler.trait;
import net.knarcraft.dynmapcitizens.settings.TraitSettings;
/** /**
* A handler which takes care of everything for one citizen trait * A handler which takes care of everything for one citizen trait
*/ */
@ -17,6 +19,13 @@ public interface CitizensTraitHandler {
*/ */
boolean isEnabled(); boolean isEnabled();
/**
* Gets the settings set for this trait
*
* @return <p>The settings for this trait</p>
*/
TraitSettings getSettings();
/** /**
* Updates all markers used for this handler * Updates all markers used for this handler
*/ */

View File

@ -5,13 +5,13 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.property.Icon; 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.MinstrelPlugin;
import net.knarcraft.minstrel.music.Song; import net.knarcraft.minstrel.music.Song;
import net.knarcraft.minstrel.trait.MinstrelTrait; import net.knarcraft.minstrel.trait.MinstrelTrait;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.GenericMarker; import org.dynmap.markers.GenericMarker;
import org.dynmap.markers.MarkerSet;
import java.util.logging.Level; import java.util.logging.Level;
@ -20,28 +20,27 @@ import java.util.logging.Level;
*/ */
public class MinstrelHandler extends AbstractTraitHandler { public class MinstrelHandler extends AbstractTraitHandler {
private MarkerSet minstrelSet; private final MinstrelSettings settings = new MinstrelSettings();
@Override @Override
public void initialize() { public void initialize() {
MinstrelPlugin minstrelPlugin = (MinstrelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Minstrel"); MinstrelPlugin minstrelPlugin = (MinstrelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Minstrel");
DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI();
if (minstrelPlugin != null) { if (minstrelPlugin != null) {
minstrelSet = getMarkerSet(dynmapAPI, "minstrels", "Minstrels"); super.initializeMarkerSet();
if (minstrelSet != null) { } else {
minstrelSet.setHideByDefault(false); super.isEnabled = false;
minstrelSet.setLayerPriority(3);
isEnabled = true;
return;
}
} }
isEnabled = false; }
@Override
public TraitSettings getSettings() {
return this.settings;
} }
@Override @Override
public void updateMarkers() { public void updateMarkers() {
//Remove existing markers //Remove existing markers
minstrelSet.getMarkers().forEach(GenericMarker::deleteMarker); super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
Class<? extends Trait> minstrelTrait = CitizensAPI.getTraitFactory().getTraitClass("minstrel"); Class<? extends Trait> minstrelTrait = CitizensAPI.getTraitFactory().getTraitClass("minstrel");
for (NPC npc : CitizensAPI.getNPCRegistry()) { for (NPC npc : CitizensAPI.getNPCRegistry()) {
@ -54,7 +53,7 @@ public class MinstrelHandler extends AbstractTraitHandler {
description = getDetailedMinstrelInfo(npc, trait); description = getDetailedMinstrelInfo(npc, trait);
} }
addNPCMarker(npc.getUniqueId(), "Minstrel NPC: ", description, 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) { private String getDetailedMinstrelInfo(NPC npc, MinstrelTrait trait) {
StringBuilder info = new StringBuilder("<h2>" + npc.getName() + "</h2>"); StringBuilder info = new StringBuilder("<h2>" + npc.getName() + "</h2>");
info.append("<b>Songs:</b><ul>"); if (this.settings.displayMinstrelSongs()) {
for (Song song : trait.getPlaylist().getSongs()) { info.append("<b>Songs:</b><ul>");
info.append("<li>Category: ").append(song.getCategory()).append("<br>Sound: ").append(song.getSound()).append("</li>"); for (Song song : trait.getPlaylist().getSongs()) {
info.append("<li>Category: ").append(song.getCategory()).append("<br>Sound: ").append(song.getSound());
info.append("</li>");
}
info.append("</ul>");
} }
info.append("</ul>");
return info.toString(); return info.toString();
} }

View File

@ -5,10 +5,10 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.Trait;
import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.property.Icon; import net.knarcraft.dynmapcitizens.property.Icon;
import net.knarcraft.dynmapcitizens.settings.SentinelSettings;
import net.knarcraft.dynmapcitizens.settings.TraitSettings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.dynmap.DynmapAPI;
import org.dynmap.markers.GenericMarker; import org.dynmap.markers.GenericMarker;
import org.dynmap.markers.MarkerSet;
import org.mcmonkey.sentinel.SentinelPlugin; import org.mcmonkey.sentinel.SentinelPlugin;
import org.mcmonkey.sentinel.SentinelTrait; import org.mcmonkey.sentinel.SentinelTrait;
@ -17,27 +17,26 @@ import org.mcmonkey.sentinel.SentinelTrait;
*/ */
public class SentinelHandler extends AbstractTraitHandler { public class SentinelHandler extends AbstractTraitHandler {
private MarkerSet sentinelSet; protected final SentinelSettings settings = new SentinelSettings();
@Override @Override
public void initialize() { public void initialize() {
SentinelPlugin sentinelPlugin = (SentinelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Sentinel"); SentinelPlugin sentinelPlugin = (SentinelPlugin) Bukkit.getServer().getPluginManager().getPlugin("Sentinel");
DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI();
if (sentinelPlugin != null) { if (sentinelPlugin != null) {
sentinelSet = getMarkerSet(dynmapAPI, "sentinels", "Sentinels"); super.initializeMarkerSet();
if (sentinelSet != null) { } else {
sentinelSet.setHideByDefault(false); super.isEnabled = false;
sentinelSet.setLayerPriority(1);
isEnabled = true;
return;
}
} }
isEnabled = false; }
@Override
public TraitSettings getSettings() {
return this.settings;
} }
@Override @Override
public void updateMarkers() { public void updateMarkers() {
sentinelSet.getMarkers().forEach(GenericMarker::deleteMarker); super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
Class<? extends Trait> sentinelTrait = CitizensAPI.getTraitFactory().getTraitClass("sentinel"); Class<? extends Trait> sentinelTrait = CitizensAPI.getTraitFactory().getTraitClass("sentinel");
for (NPC npc : CitizensAPI.getNPCRegistry()) { for (NPC npc : CitizensAPI.getNPCRegistry()) {
@ -54,7 +53,7 @@ public class SentinelHandler extends AbstractTraitHandler {
description += "<br><b>Targets:</b> " + trait.allTargets.toAllInOneString() + "<br><b>Avoids:</b> " + description += "<br><b>Targets:</b> " + trait.allTargets.toAllInOneString() + "<br><b>Avoids:</b> " +
trait.allAvoids.toAllInOneString() + "<br><b>Ignores:</b> " + trait.allIgnores.toAllInOneString(); trait.allAvoids.toAllInOneString() + "<br><b>Ignores:</b> " + trait.allIgnores.toAllInOneString();
addNPCMarker(npc.getUniqueId(), "Sentinel NPC: ", description, addNPCMarker(npc.getUniqueId(), "Sentinel NPC: ", description,
DynmapCitizens.getInstance().getMarkerIcons().get(Icon.SENTINEL), sentinelSet); DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons().get(Icon.SENTINEL), super.markerSet);
} }
} }
} }

View File

@ -8,6 +8,8 @@ import net.citizensnpcs.api.npc.NPCRegistry;
import net.knarcraft.dynmapcitizens.DynmapCitizens; import net.knarcraft.dynmapcitizens.DynmapCitizens;
import net.knarcraft.dynmapcitizens.handler.trait.AbstractTraitHandler; import net.knarcraft.dynmapcitizens.handler.trait.AbstractTraitHandler;
import net.knarcraft.dynmapcitizens.property.Icon; 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 net.knarcraft.dynmapcitizens.util.QuestsHelper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -33,31 +35,33 @@ import java.util.logging.Level;
public class QuestsHandler extends AbstractTraitHandler { public class QuestsHandler extends AbstractTraitHandler {
private QuestsAPI questsAPI; private QuestsAPI questsAPI;
private MarkerSet questMarkerSet;
private MarkerSet questAreaMarkerSet; private MarkerSet questAreaMarkerSet;
private Map<Icon, MarkerIcon> markerIcons; private Map<Icon, MarkerIcon> markerIcons;
private Map<UUID, NPCQuestInfo> questGiverInfo; private Map<UUID, NPCQuestInfo> questGiverInfo;
private final QuestsSettings settings = new QuestsSettings();
@Override @Override
public void initialize() { public void initialize() {
questsAPI = (QuestsAPI) Bukkit.getServer().getPluginManager().getPlugin("Quests"); questsAPI = (QuestsAPI) Bukkit.getServer().getPluginManager().getPlugin("Quests");
DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI(); DynmapAPI dynmapAPI = DynmapCitizens.getInstance().getDynmapAPI();
markerIcons = DynmapCitizens.getInstance().getMarkerIcons(); markerIcons = DynmapCitizens.getInstance().getGlobalSettings().getMarkerIcons();
if (questsAPI != null) { if (questsAPI != null) {
questMarkerSet = getMarkerSet(dynmapAPI, "quests", "Quests"); super.initializeMarkerSet();
questAreaMarkerSet = getMarkerSet(dynmapAPI, "quest_areas", "Quest areas"); questAreaMarkerSet = getMarkerSet(dynmapAPI, "quest_areas", "Quest areas");
if (questMarkerSet != null && questAreaMarkerSet != null) { if (questAreaMarkerSet != null) {
questMarkerSet.setHideByDefault(false);
questAreaMarkerSet.setHideByDefault(true); questAreaMarkerSet.setHideByDefault(true);
questMarkerSet.setLayerPriority(3);
questAreaMarkerSet.setLayerPriority(2); questAreaMarkerSet.setLayerPriority(2);
isEnabled = true;
//Remove old quest markers //Remove old quest markers
questMarkerSet.getMarkers().forEach(GenericMarker::deleteMarker); super.markerSet.getMarkers().forEach(GenericMarker::deleteMarker);
return;
} }
} else {
isEnabled = false;
} }
isEnabled = false; }
@Override
public TraitSettings getSettings() {
return settings;
} }
@Override @Override
@ -73,7 +77,7 @@ public class QuestsHandler extends AbstractTraitHandler {
generateQuestNPCInfo(); generateQuestNPCInfo();
//Remove any markers for deleted quests //Remove any markers for deleted quests
for (Marker marker : questMarkerSet.getMarkers()) { for (Marker marker : super.markerSet.getMarkers()) {
if (!questGiverInfo.containsKey(UUID.fromString(marker.getMarkerID()))) { if (!questGiverInfo.containsKey(UUID.fromString(marker.getMarkerID()))) {
marker.deleteMarker(); marker.deleteMarker();
} }
@ -137,14 +141,14 @@ public class QuestsHandler extends AbstractTraitHandler {
markerDescription.append(getInvolvedInQuestsString(info)); markerDescription.append(getInvolvedInQuestsString(info));
Marker existingMarker = questMarkerSet.findMarker(npcId.toString()); Marker existingMarker = super.markerSet.findMarker(npcId.toString());
String newDescription = markerDescription.toString(); String newDescription = markerDescription.toString();
if (existingMarker != null) { if (existingMarker != null) {
if (!existingMarker.getDescription().equals(newDescription)) { if (!existingMarker.getDescription().equals(newDescription)) {
existingMarker.setDescription(newDescription); existingMarker.setDescription(newDescription);
} }
} else { } else {
addNPCMarker(npcId, QuestsHelper.getMarkerTitle(info.getQuestNPCType()), newDescription, icon, questMarkerSet); addNPCMarker(npcId, QuestsHelper.getMarkerTitle(info.getQuestNPCType()), newDescription, icon, super.markerSet);
} }
} }
} }

View File

@ -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 <p>The root config node for this trait's settings</p>
*/
protected abstract String getTraitConfigRoot();
}

View File

@ -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";
}
}

View File

@ -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<Icon, MarkerIcon> markerIcons = new HashMap<>();
private long updateMovingNPCDelay;
private long updateAllMarkersDelay;
/**
* Loads all global settings from the given configuration
*
* @param configuration <p>The configuration to load from</p>
*/
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 <p>The marker icons to use</p>
*/
public Map<Icon, MarkerIcon> getMarkerIcons() {
return new HashMap<>(markerIcons);
}
/**
* Gets the delay to wait between each time a moving NPC's marker is updated
*
* @return <p>The update delay for moving NPCs</p>
*/
public long getUpdateMovingNPCDelay() {
return updateMovingNPCDelay;
}
/**
* Gets the delay to wait between each time all markers are updated
*
* @return <p>The update delay for all markers</p>
*/
public long getUpdateAllMarkersDelay() {
return updateAllMarkersDelay;
}
/**
* Gets the default icon name for the given icon identifier
*
* @param icon <p>The icon identifier to get the icon for</p>
* @return <p>The default icon name</p>
*/
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";
};
}
}

View File

@ -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 <p>True if minstrel songs should be displayed</p>
*/
public boolean displayMinstrelSongs() {
return displayMinstrelSongs;
}
}

View File

@ -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";
}
}

View File

@ -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";
}
}

View File

@ -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 <p>The configuration to load values from</p>
*/
void load(FileConfiguration configuration);
/**
* Gets whether this trait type is enabled in the config
*
* @return <p>True if this trait is enabled</p>
*/
boolean isEnabled();
/**
* Gets the id of the trait's marker set
*
* <p>This is mainly configurable in case of duplicate ids</p>
*
* @return <p>The id of the marker set</p>
*/
String getMarkerSetId();
/**
* Gets the name of this trait's marker set
*
* @return <p>The name of the marker set</p>
*/
String getMarkerSetName();
/**
* Gets the priority of the trait's marker set
*
* @return <p>The priority of the marker set</p>
*/
int getMarkerSetPriority();
/**
* Gets whether this trait's markers should be hidden by default
*
* @return <p>Whether markers should be hidden by default</p>
*/
boolean markersHiddenByDefault();
}

View File

@ -30,7 +30,13 @@ traits:
quests: quests:
enabled: true enabled: true
# The priority of quest markers. Higher priority markers will display on top of lower priority ones # 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 # The priority of quest area markers, such as kill areas
areaMarkerPriority: 2 areaMarkerPriority: 2
# Whether to mark kill areas and similar on the map # Whether to mark kill areas and similar on the map
@ -47,6 +53,12 @@ traits:
circleMarker: circleMarker:
# Settings for kill zone markers # Settings for kill zone markers
killMarker: 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 # The color used for the filled in area
fillColor: "EDAFA0" fillColor: "EDAFA0"
# The color used for the outer line # The color used for the outer line
@ -59,6 +71,12 @@ traits:
lineThickness: 2 lineThickness: 2
# Settings for reach area markers # Settings for reach area markers
reachMarker: 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 # The color used for the filled in area
fillColor: "FFFF99" fillColor: "FFFF99"
# The color used for the outer line # The color used for the outer line
@ -73,20 +91,38 @@ traits:
blacksmith: blacksmith:
enabled: true enabled: true
# The priority of blacksmith markers. Higher priority markers will display on top of lower priority ones # 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 # Whether to display the state of blacksmiths' settings, such as fail chance and delays
displayBlacksmithSettings: true displayBlacksmithSettings: true
# Settings for the sentinel trait # Settings for the sentinel trait
sentinel: sentinel:
enabled: true enabled: true
# The priority of sentinel markers. Higher priority markers will display on top of lower priority ones # 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 # Whether to display information about a sentinel's health, armor and damage in the marker description
displaySentinelStrength: true displaySentinelStrength: true
# Settings for the minstrel trait # Settings for the minstrel trait
minstrel: minstrel:
enabled: true enabled: true
# The priority of sentinel markers. Higher priority markers will display on top of lower priority ones # 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 # Whether to display the list of songs a minstrel is playing
displayMinstrelSongs: true displayMinstrelSongs: true