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,65 +37,87 @@ public class QuestStagesInfoGenerator {
StringBuilder questInfo = new StringBuilder();
NPCRegistry registry = CitizensAPI.getNPCRegistry();
int stageCounter = 1;
questInfo.append("<b>Stages:</b><ul>");
for (IStage stage : quest.getStages()) {
questInfo.append("<li><b>Stage ").append(stageCounter).append(" tasks:</b><ul>");
int mobTypes = stage.getMobsToKill().size();
for (int i = 0; i < mobTypes; i++) {
questInfo.append("<li>Kill ").append(QuestsHelper.normalizeName(stage.getMobsToKill().get(i).name()));
questInfo.append(" x ").append(stage.getMobNumToKill().get(i)).append("</li>");
}
int reachLocations = stage.getLocationsToReach().size();
for (int i = 0; i < reachLocations; i++) {
questInfo.append("<li>Reach ").append(stage.getLocationNames().get(i)).append(", within ");
questInfo.append(stage.getRadiiToReachWithin().get(i)).append(" blocks of ");
questInfo.append(getLocationString(stage.getLocationsToReach().get(i))).append("</li>");
}
int deliveries = stage.getItemDeliveryTargets().size();
for (int i = 0; i < deliveries; i++) {
NPC npc = registry.getByUniqueId(stage.getItemDeliveryTargets().get(i));
questInfo.append("<li>Deliver ").append(QuestsHelper.getItemStackString(stage.getItemsToDeliver().get(i))).append(
" to ").append(npc.getName()).append("</li>");
}
if (stage.getFishToCatch() != null) {
questInfo.append("<li>Catch ").append(stage.getFishToCatch()).append(" fish").append("</li>");
}
for (UUID npcId : stage.getNpcsToKill()) {
questInfo.append("<li>Kill NPC ").append(registry.getByUniqueId(npcId).getName()).append("</li>");
}
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>");
for (IStage stage : quest.getStages()) {
questInfo.append("<li><b>Stage ").append(stageCounter).append(" tasks:</b><ul>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToBreak(), "<li>Break ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToCut(), "<li>Cut ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToDamage(), "<li>Damage ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToUse(), "<li>Use ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToPlace(), "<li>Place ")).append("</li>");
questInfo.append(getStageInfo(stage, registry));
questInfo.append(getQuestItemsTaskString(stage.getItemsToBrew(), "<li>Brew ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToConsume(), "<li>Consume ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToCraft(), "<li>Craft ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToEnchant(), "<li>Enchant ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToSmelt(), "<li>Smelt ")).append("</li>");
int sheepTypes = stage.getSheepToShear().size();
for (int i = 0; i < sheepTypes; i++) {
questInfo.append("<li>Shear ").append(stage.getSheepNumToShear().get(i)).append(" ").append(
QuestsHelper.normalizeName(stage.getSheepToShear().get(i).name())).append(" sheep").append("</li>");
questInfo.append("</ul></li>");
stageCounter++;
}
if (stage.getCowsToMilk() != null) {
questInfo.append("<li>Milk ").append(stage.getCowsToMilk()).append(" cows").append("</li>");
}
int mobTamingEntries = stage.getMobsToTame().size();
for (int i = 0; i < mobTamingEntries; i++) {
questInfo.append("<li>Tame ").append(stage.getMobNumToTame().get(i)).append(" ").append(
QuestsHelper.normalizeName(stage.getMobsToTame().get(i).name())).append("</li>");
}
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();
for (int i = 0; i < mobTypes; i++) {
questInfo.append("<li>Kill ").append(QuestsHelper.normalizeName(stage.getMobsToKill().get(i).name()));
questInfo.append(" x ").append(stage.getMobNumToKill().get(i)).append("</li>");
}
int reachLocations = stage.getLocationsToReach().size();
for (int i = 0; i < reachLocations; i++) {
questInfo.append("<li>Reach ").append(stage.getLocationNames().get(i)).append(", within ");
questInfo.append(stage.getRadiiToReachWithin().get(i)).append(" blocks of ");
questInfo.append(getLocationString(stage.getLocationsToReach().get(i))).append("</li>");
}
int deliveries = stage.getItemDeliveryTargets().size();
for (int i = 0; i < deliveries; i++) {
NPC npc = registry.getByUniqueId(stage.getItemDeliveryTargets().get(i));
questInfo.append("<li>Deliver ").append(QuestsHelper.getItemStackString(stage.getItemsToDeliver().get(i))).append(
" to ").append(npc.getName()).append("</li>");
}
if (stage.getFishToCatch() != null) {
questInfo.append("<li>Catch ").append(stage.getFishToCatch()).append(" fish").append("</li>");
}
for (UUID npcId : stage.getNpcsToKill()) {
questInfo.append("<li>Kill NPC ").append(registry.getByUniqueId(npcId).getName()).append("</li>");
}
questInfo.append(getQuestItemsTaskString(stage.getBlocksToBreak(), "<li>Break ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToCut(), "<li>Cut ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToDamage(), "<li>Damage ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToUse(), "<li>Use ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getBlocksToPlace(), "<li>Place ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToBrew(), "<li>Brew ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToConsume(), "<li>Consume ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToCraft(), "<li>Craft ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToEnchant(), "<li>Enchant ")).append("</li>");
questInfo.append(getQuestItemsTaskString(stage.getItemsToSmelt(), "<li>Smelt ")).append("</li>");
int sheepTypes = stage.getSheepToShear().size();
for (int i = 0; i < sheepTypes; i++) {
questInfo.append("<li>Shear ").append(stage.getSheepNumToShear().get(i)).append(" ").append(
QuestsHelper.normalizeName(stage.getSheepToShear().get(i).name())).append(" sheep").append("</li>");
}
if (stage.getCowsToMilk() != null) {
questInfo.append("<li>Milk ").append(stage.getCowsToMilk()).append(" cows").append("</li>");
}
int mobTamingEntries = stage.getMobsToTame().size();
for (int i = 0; i < mobTamingEntries; i++) {
questInfo.append("<li>Tame ").append(stage.getMobNumToTame().get(i)).append(" ").append(
QuestsHelper.normalizeName(stage.getMobsToTame().get(i).name())).append("</li>");
}
return questInfo.toString();
}