Implements settings for limiting quest information

This commit is contained in:
Kristian Knarvik 2022-11-03 16:11:46 +01:00
parent be127d0733
commit 0cbc7ae1b2
4 changed files with 96 additions and 33 deletions

View File

@ -29,7 +29,7 @@ public final class DynmapCitizens extends JavaPlugin {
@Override
public void onEnable() {
instance = this;
DynmapCitizens.instance = this;
//Initialize quest and dynmap APIs
PluginManager pluginManager = Bukkit.getPluginManager();
Plugin dynmapPlugin = pluginManager.getPlugin("dynmap");
@ -40,31 +40,31 @@ public final class DynmapCitizens extends JavaPlugin {
}
this.dynmapAPI = dynmapAPI;
globalSettings = new GlobalSettings();
this.globalSettings = new GlobalSettings();
FileConfiguration configuration = this.getConfig();
this.saveDefaultConfig();
configuration.options().copyDefaults(true);
this.saveConfig();
globalSettings.load(configuration);
this.globalSettings.load(configuration);
//Initialize all enabled traits
initializeTraitHandlers(configuration);
//Schedule handlers to run periodically
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (CitizensTraitHandler handler : traitHandlers) {
for (CitizensTraitHandler handler : this.traitHandlers) {
if (handler.isEnabled()) {
handler.updateMarkers();
}
}
}, 10 * 20, globalSettings.getUpdateAllMarkersDelay() * 20);
}, 10 * 20, this.globalSettings.getUpdateAllMarkersDelay() * 20);
vaultHandler = new VaultHandler(this.getServer().getServicesManager());
this.vaultHandler = new VaultHandler(this.getServer().getServicesManager());
}
@Override
public void onDisable() {
//TODO: Perhaps remove icons, just in case?
}
/**
@ -73,7 +73,7 @@ public final class DynmapCitizens extends JavaPlugin {
* @return <p>The global settings for this plugin</p>
*/
public GlobalSettings getGlobalSettings() {
return globalSettings;
return this.globalSettings;
}
/**
@ -82,7 +82,7 @@ public final class DynmapCitizens extends JavaPlugin {
* @return <p>The Vault handler</p>
*/
public VaultHandler getVaultHandler() {
return vaultHandler;
return this.vaultHandler;
}
/**
@ -100,7 +100,7 @@ public final class DynmapCitizens extends JavaPlugin {
* @return <p>An instance of this plugin</p>
*/
public static DynmapCitizens getInstance() {
return instance;
return DynmapCitizens.instance;
}
/**
@ -110,14 +110,14 @@ public final class DynmapCitizens extends JavaPlugin {
*/
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());
this.traitHandlers = new ArrayList<>();
this.traitHandlers.add(new BlacksmithHandler());
this.traitHandlers.add(new QuestsHandler());
this.traitHandlers.add(new SentinelHandler());
this.traitHandlers.add(new MinstrelHandler());
//Load and initialize all enabled trait handlers
for (CitizensTraitHandler handler : traitHandlers) {
for (CitizensTraitHandler handler : this.traitHandlers) {
//Load configuration values from the config file
handler.getSettings().load(configuration);
//Check if the handler is enabled in the config before doing anything

View File

@ -61,7 +61,7 @@ public class QuestsHandler extends AbstractTraitHandler {
@Override
public TraitSettings getSettings() {
return settings;
return this.settings;
}
@Override
@ -121,22 +121,14 @@ public class QuestsHandler extends AbstractTraitHandler {
for (UUID npcId : questGiverInfo.keySet()) {
NPCQuestInfo info = questGiverInfo.get(npcId);
MarkerIcon icon = markerIcons.get(info.getNPCIcon());
List<IQuest> questStarts = info.getQuestStarts();
List<IQuest> offeredQuests = info.getQuestStarts();
StringBuilder markerDescription = new StringBuilder();
markerDescription.append("<h2>").append(registry.getByUniqueId(npcId).getName()).append("</h2>");
if (!questStarts.isEmpty()) {
markerDescription.append("<h3>Quests offered:</h3><ul>");
for (IQuest quest : questStarts) {
markerDescription.append("<li><h4><b>").append(quest.getName()).append("</b></h4><h5><b>- ");
markerDescription.append(quest.getDescription()).append("</b></h5>").append(
new QuestStagesInfoGenerator(quest).getQuestStagesInfo());
markerDescription.append(new QuestRewardsInfoGenerator(quest).getQuestRewardsInfo());
markerDescription.append(new QuestRequirementsInfoGenerator(quest).getQuestRequirementsInfo());
markerDescription.append(new QuestPlannerInfoGenerator(quest).getQuestPlannerInfo()).append("</li>");
}
markerDescription.append("</ul>");
//Print info about any offered quests
if (!offeredQuests.isEmpty()) {
appendOfferedQuestsInfo(markerDescription, offeredQuests);
}
markerDescription.append(getInvolvedInQuestsString(info));
@ -153,6 +145,34 @@ public class QuestsHandler extends AbstractTraitHandler {
}
}
/**
* Appends information about an NPC's offered quests to the given string builder
*
* @param stringBuilder <p>The string builder to append to</p>
* @param offeredQuests <p>The list of quests the NPC offers</p>
*/
private void appendOfferedQuestsInfo(StringBuilder stringBuilder, List<IQuest> offeredQuests) {
stringBuilder.append("<h3>Quests offered:</h3><ul>");
for (IQuest quest : offeredQuests) {
stringBuilder.append("<li><h4><b>").append(quest.getName()).append("</b></h4><h5><b>- ");
stringBuilder.append(quest.getDescription()).append("</b></h5>");
if (settings.displayStageInfo()) {
stringBuilder.append(new QuestStagesInfoGenerator(quest).getQuestStagesInfo());
}
if (settings.displayRewardInfo()) {
stringBuilder.append(new QuestRewardsInfoGenerator(quest).getQuestRewardsInfo());
}
if (settings.displayRequirementInfo()) {
stringBuilder.append(new QuestRequirementsInfoGenerator(quest).getQuestRequirementsInfo());
}
if (settings.displayPlannerInfo()) {
stringBuilder.append(new QuestPlannerInfoGenerator(quest).getQuestPlannerInfo());
}
stringBuilder.append("</li>");
}
stringBuilder.append("</ul>");
}
/**
* Gets information about the quests an NPC is involved in
*

View File

@ -7,9 +7,18 @@ import org.bukkit.configuration.file.FileConfiguration;
*/
public class QuestsSettings extends AbstractTraitSettings {
private boolean displayRewardInfo;
private boolean displayPlannerInfo;
private boolean displayStageInfo;
private boolean displayRequirementInfo;
@Override
public void load(FileConfiguration configuration) {
super.load(configuration);
this.displayRewardInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayRewardInfo", true);
this.displayPlannerInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayPlannerInfo", true);
this.displayStageInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayStageInfo", true);
this.displayRequirementInfo = configuration.getBoolean(getTraitConfigRoot() + ".displayRequirementInfo", true);
}
@Override
@ -17,4 +26,40 @@ public class QuestsSettings extends AbstractTraitSettings {
return "traits.quests";
}
/**
* Gets whether to display reward information as part of quest marker descriptions
*
* @return <p>True if reward information should be displayed</p>
*/
public boolean displayRewardInfo() {
return this.displayRewardInfo;
}
/**
* Gets whether to display planner information, such as cool-down, as part of quest marker descriptions
*
* @return <p>True if planner information should be displayed</p>
*/
public boolean displayPlannerInfo() {
return this.displayPlannerInfo;
}
/**
* Gets whether to display stage (task) information, as part of quest marker descriptions
*
* @return <p>True if stage information should be displayed</p>
*/
public boolean displayStageInfo() {
return this.displayStageInfo;
}
/**
* Gets whether to display requirement information, as part of quest marker descriptions
*
* @return <p>True if reward information should be displayed</p>
*/
public boolean displayRequirementInfo() {
return this.displayRequirementInfo;
}
}

View File

@ -37,10 +37,6 @@ traits:
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
showAreaMarkers: true
# Whether to add information about a quest's rewards to the marker description
displayRewardInfo: true
# Whether to add information about a quest's start date, stop date and cool-down to the marker description
@ -53,6 +49,7 @@ traits:
circleMarker:
# Settings for kill zone markers
killMarker:
enabled: true
# 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
@ -71,6 +68,7 @@ traits:
lineThickness: 2
# Settings for reach area markers
reachMarker:
enabled: true
# 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