Makes sure to only display stages as list if necessary

This commit is contained in:
Kristian Knarvik 2022-11-03 18:21:12 +01:00
parent ac5b82b3f1
commit cd35bdc334

View File

@ -37,9 +37,35 @@ public class QuestStagesInfoGenerator {
StringBuilder questInfo = new StringBuilder(); StringBuilder questInfo = new StringBuilder();
NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPCRegistry registry = CitizensAPI.getNPCRegistry();
int stageCounter = 1; int stageCounter = 1;
if (quest.getStages().size() == 1) {
questInfo.append("<b>Tasks</b><ul>");
questInfo.append(getStageInfo(quest.getStage(0), registry));
} else {
questInfo.append("<b>Stages:</b><ul>"); questInfo.append("<b>Stages:</b><ul>");
for (IStage stage : quest.getStages()) { for (IStage stage : quest.getStages()) {
questInfo.append("<li><b>Stage ").append(stageCounter).append(" tasks:</b><ul>"); questInfo.append("<li><b>Stage ").append(stageCounter).append(" tasks:</b><ul>");
questInfo.append(getStageInfo(stage, registry));
questInfo.append("</ul></li>");
stageCounter++;
}
}
questInfo.append("</ul>");
return questInfo.toString();
}
/**
* Gets information about the given stage
*
* @param stage <p>The stage to get information about</p>
* @param registry <p>The registry to get NPC info from</p>
* @return <p>Information about the stage's tasks</p>
*/
private String getStageInfo(IStage stage, NPCRegistry registry) {
StringBuilder questInfo = new StringBuilder();
int mobTypes = stage.getMobsToKill().size(); int mobTypes = stage.getMobsToKill().size();
for (int i = 0; i < mobTypes; i++) { for (int i = 0; i < mobTypes; i++) {
questInfo.append("<li>Kill ").append(QuestsHelper.normalizeName(stage.getMobsToKill().get(i).name())); questInfo.append("<li>Kill ").append(QuestsHelper.normalizeName(stage.getMobsToKill().get(i).name()));
@ -92,10 +118,6 @@ public class QuestStagesInfoGenerator {
QuestsHelper.normalizeName(stage.getMobsToTame().get(i).name())).append("</li>"); QuestsHelper.normalizeName(stage.getMobsToTame().get(i).name())).append("</li>");
} }
questInfo.append("</ul></li>");
stageCounter++;
}
questInfo.append("</ul>");
return questInfo.toString(); return questInfo.toString();
} }