mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-03 15:08:10 +01:00
step toward bigger refactor
- replace 'continue' w/a try/catch/throw to skip loop iterations (enables "extract method" refactors later)
This commit is contained in:
parent
b3fc2a432e
commit
3b49c461f1
@ -145,6 +145,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
@SuppressWarnings("serial")
|
||||
class StageFailedException extends Exception { }
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class SkipQuest extends Exception { }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
@ -2246,6 +2249,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
}
|
||||
|
||||
private boolean needsSaving = false;
|
||||
private String questName = "";
|
||||
private Quest quest;
|
||||
|
||||
public void loadQuests() {
|
||||
|
||||
@ -2274,9 +2279,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
needsSaving = true;
|
||||
}
|
||||
|
||||
for (String questName : questsSection.getKeys(false)) {
|
||||
for (String key : questsSection.getKeys(false)) {
|
||||
|
||||
Quest quest = new Quest();
|
||||
try { // main "skip quest" try/catch block
|
||||
|
||||
questName = key;
|
||||
|
||||
quest = new Quest();
|
||||
failedToLoad = false;
|
||||
|
||||
if (config.contains("quests." + questName + ".name")) {
|
||||
@ -2284,11 +2293,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.name = parseString(config.getString("quests." + questName + ".name"), quest);
|
||||
} else {
|
||||
printSevere("[Quests] Quest block \'" + questName + "\' is missing " + RED + "name:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".npc-giver-id")) {
|
||||
|
||||
if (CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questName + ".npc-giver-id")) != null) {
|
||||
|
||||
quest.npcStart = CitizensAPI.getNPCRegistry().getById(config.getInt("quests." + questName + ".npc-giver-id"));
|
||||
@ -2296,9 +2304,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] npc-giver-id: for Quest " + quest.name + " is not a valid NPC id!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".block-start")) {
|
||||
@ -2309,7 +2316,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
} else {
|
||||
printSevere("[Quests] block-start: for Quest " + quest.name + " is not in proper location format!");
|
||||
printSevere("[Quests] Proper location format is: \"WorldName x y z\"");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2321,7 +2328,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
if (!exists) {
|
||||
printSevere("[Quests] region: for Quest " + quest.name + " is not a valid WorldGuard region!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2339,7 +2346,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.redoDelay = config.getInt("quests." + questName + ".redo-delay");
|
||||
} else {
|
||||
printSevere("[Quests] redo-delay: for Quest " + quest.name + " is not a number!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2348,14 +2355,14 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.finished = parseString(config.getString("quests." + questName + ".finish-message"), quest);
|
||||
} else {
|
||||
printSevere("[Quests] Quest " + quest.name + " is missing finish-message:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".ask-message")) {
|
||||
quest.description = parseString(config.getString("quests." + questName + ".ask-message"), quest);
|
||||
} else {
|
||||
printSevere("[Quests] Quest " + quest.name + " is missing ask-message:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".event")) {
|
||||
@ -2366,7 +2373,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.initialEvent = evt;
|
||||
} else {
|
||||
printSevere("[Quests] Initial Event in Quest " + quest.name + " failed to load.");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2377,7 +2384,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.failRequirements = parseString(config.getString("quests." + questName + ".requirements.fail-requirement-message"), quest);
|
||||
} else {
|
||||
printSevere("[Quests] Requirements for Quest " + quest.name + " is missing fail-requirement-message:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".requirements.items")) {
|
||||
@ -2399,12 +2406,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
if (failed == true) {
|
||||
printSevere("[Quests] items: Requirement for Quest " + quest.name + " is not formatted correctly!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] items: Requirement for Quest " + quest.name + " is not formatted correctly!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".requirements.remove-items")) {
|
||||
@ -2414,12 +2421,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.removeItems.addAll(config.getBooleanList("quests." + questName + ".requirements.remove-items"));
|
||||
} else {
|
||||
printSevere("[Quests] remove-items: Requirement for Quest " + quest.name + " is not a list of true/false values!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] Requirements for Quest " + quest.name + " is missing remove-items:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2429,7 +2436,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.moneyReq = config.getInt("quests." + questName + ".requirements.money");
|
||||
} else {
|
||||
printSevere("[Quests] money: Requirement for Quest " + quest.name + " is not a number!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2440,7 +2447,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.questPointsReq = config.getInt("quests." + questName + ".requirements.quest-points");
|
||||
} else {
|
||||
printSevere("[Quests] quest-points: Requirement for Quest " + quest.name + " is not a number!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2478,12 +2485,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
if (failed) {
|
||||
printSevere("[Quests] " + PINK + failedQuest + " inside quests: Requirement for Quest " + quest.name + " is not a valid Quest name!");
|
||||
printSevere("Make sure you are using the Quest name: value, and not the block name.");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] quest-blocks: Requirement for Quest " + quest.name + " is not a list of Quest names!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2521,12 +2528,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
if (failed) {
|
||||
printSevere("[Quests] " + failedQuest + " inside quests: Requirement for Quest " + quest.name + " is not a valid Quest name!");
|
||||
printSevere("Make sure you are using the Quest name: value, and not the block name.");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] quests: Requirement for Quest " + quest.name + " is not a list of Quest names!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2538,7 +2545,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.permissionReqs.addAll(config.getStringList("quests." + questName + ".requirements.permissions"));
|
||||
} else {
|
||||
printSevere("[Quests] permissions: Requirement for Quest " + quest.name + " is not a list of permissions!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2556,7 +2563,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
if (skills.size() != amounts.size()) {
|
||||
printSevere("[Quests] mcmmo-skills: and mcmmo-amounts: in requirements: for Quest " + quest.name + " are not the same size!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
quest.mcMMOSkillReqs.addAll(skills);
|
||||
@ -2564,17 +2571,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] mcmmo-amounts: Requirement for Quest " + quest.name + " is not a list of numbers!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] Requirements for Quest " + quest.name + " is missing mcmmo-amounts:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] mcmmo-skills: Requirement for Quest " + quest.name + " is not a list of skills!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2587,10 +2594,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.heroesPrimaryClassReq = hc.getName();
|
||||
} else if (hc != null) {
|
||||
printSevere("[Quests] heroes-primary-class: Requirement for Quest " + quest.name + " is not a primary Heroes class!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
} else {
|
||||
printSevere("[Quests] heroes-primary-class: Requirement for Quest " + quest.name + " is not a valid Heroes class!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2603,10 +2610,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.heroesSecondaryClassReq = hc.getName();
|
||||
} else if (hc != null) {
|
||||
printSevere("[Quests] heroes-secondary-class: Requirement for Quest " + quest.name + " is not a secondary Heroes class!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
} else {
|
||||
printSevere("[Quests] heroes-secondary-class: Requirement for Quest " + quest.name + " is not a valid Heroes class!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2628,7 +2635,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
if (!found) {
|
||||
printWarning("[Quests] Custom requirement \"" + name + "\" for Quest \"" + quest.name + "\" could not be found!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
@ -2649,13 +2656,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
quest.plugin = this;
|
||||
|
||||
try {
|
||||
processStages(quest, config, questName);
|
||||
// needsSaving may be modified as a side-effect
|
||||
}
|
||||
catch (StageFailedException ex) {
|
||||
continue;
|
||||
}
|
||||
processStages(quest, config, questName); // needsSaving may be modified as a side-effect
|
||||
|
||||
//Load rewards
|
||||
if (config.contains("quests." + questName + ".rewards.items")) {
|
||||
@ -2679,12 +2680,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] items: Reward in Quest " + quest.name + " is not a list of strings!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2706,7 +2707,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.exp = config.getInt("quests." + questName + ".rewards.exp");
|
||||
} else {
|
||||
printSevere("[Quests] exp: Reward in Quest " + quest.name + " is not a number!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2718,7 +2719,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.commands.addAll(config.getStringList("quests." + questName + ".rewards.commands"));
|
||||
} else {
|
||||
printSevere("[Quests] commands: Reward in Quest " + quest.name + " is not a list of commands!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2730,7 +2731,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
quest.permissions.addAll(config.getStringList("quests." + questName + ".rewards.permissions"));
|
||||
} else {
|
||||
printSevere("[Quests] permissions: Reward in Quest " + quest.name + " is not a list of permissions!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2742,7 +2743,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
totalQuestPoints += quest.questPoints;
|
||||
} else {
|
||||
printSevere("[Quests] quest-points: Reward in Quest " + quest.name + " is not a number!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2766,7 +2767,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
}
|
||||
if (failed) {
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
quest.mcmmoSkills.clear();
|
||||
@ -2777,17 +2778,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] mcmmo-levels: Reward in Quest " + quest.name + " is not a list of numbers!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] Rewards for Quest " + quest.name + " is missing mcmmo-levels:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] mcmmo-skills: Reward in Quest " + quest.name + " is not a list of mcMMO skill names!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2810,7 +2811,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
}
|
||||
if (failed) {
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
quest.heroesClasses.clear();
|
||||
@ -2821,17 +2822,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] heroes-exp-amounts: Reward in Quest " + quest.name + " is not a list of experience amounts (decimal numbers)!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] Rewards for Quest " + quest.name + " is missing heroes-exp-amounts:");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] heroes-exp-classes: Reward in Quest " + quest.name + " is not a list of Heroes classes!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2850,7 +2851,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
}
|
||||
if (failed) {
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
|
||||
quest.phatLootRewards.clear();
|
||||
@ -2858,12 +2859,50 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
|
||||
} else {
|
||||
printSevere("[Quests] phat-loots: Reward in Quest " + quest.name + " is not a list of PhatLoots!");
|
||||
continue;
|
||||
skipQuestProcess();
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questName + ".rewards.custom-rewards")) {
|
||||
populateCustomRewards(config);
|
||||
}
|
||||
|
||||
quests.add(quest);
|
||||
|
||||
if (needsSaving) {
|
||||
try {
|
||||
config.save(file);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
if (debug == false) {
|
||||
log.log(Level.SEVERE, "[Quests] Failed to load Quest \"" + questName + "\". Skipping.");
|
||||
} else {
|
||||
log.log(Level.SEVERE, "[Quests] Failed to load Quest \"" + questName + "\". Error log:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (failedToLoad == true) {
|
||||
log.log(Level.SEVERE, "[Quests] Failed to load Quest \"" + questName + "\". Skipping.");
|
||||
}
|
||||
}
|
||||
catch (SkipQuest ex) {
|
||||
continue;
|
||||
}
|
||||
catch (StageFailedException ex) {
|
||||
continue;
|
||||
}
|
||||
} // for()
|
||||
}
|
||||
|
||||
private void skipQuestProcess() throws SkipQuest {
|
||||
throw new SkipQuest();
|
||||
}
|
||||
|
||||
private void populateCustomRewards(FileConfiguration config) {
|
||||
ConfigurationSection sec = config.getConfigurationSection("quests." + questName + ".rewards.custom-rewards");
|
||||
for (String path : sec.getKeys(false)) {
|
||||
|
||||
@ -2891,33 +2930,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
||||
}
|
||||
|
||||
quest.customRewards.put(name, data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
quests.add(quest);
|
||||
|
||||
if (needsSaving) {
|
||||
try {
|
||||
config.save(file);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
if (debug == false) {
|
||||
log.log(Level.SEVERE, "[Quests] Failed to load Quest \"" + questName + "\". Skipping.");
|
||||
} else {
|
||||
log.log(Level.SEVERE, "[Quests] Failed to load Quest \"" + questName + "\". Error log:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (failedToLoad == true) {
|
||||
log.log(Level.SEVERE, "[Quests] Failed to load Quest \"" + questName + "\". Skipping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user