Refresh Quest objects on reload, fixes #811

This commit is contained in:
PikaMug 2019-09-16 00:37:09 -04:00
parent ba6cf5f620
commit aaecb130f2
3 changed files with 34 additions and 18 deletions

View File

@ -49,6 +49,7 @@ import net.citizensnpcs.api.npc.NPC;
public class Quest { public class Quest {
protected Quests plugin; protected Quests plugin;
protected String id;
private String name; private String name;
protected String description; protected String description;
protected String finished; protected String finished;
@ -63,20 +64,8 @@ public class Quest {
private Rewards rews = new Rewards(); private Rewards rews = new Rewards();
private Options opts = new Options(); private Options opts = new Options();
public Requirements getRequirements() { public String getId() {
return reqs; return id;
}
public Planner getPlanner() {
return pln;
}
public Rewards getRewards() {
return rews;
}
public Options getOptions() {
return opts;
} }
public String getName() { public String getName() {
@ -155,6 +144,22 @@ public class Quest {
this.initialAction = initialAction; this.initialAction = initialAction;
} }
public Requirements getRequirements() {
return reqs;
}
public Planner getPlanner() {
return pln;
}
public Rewards getRewards() {
return rews;
}
public Options getOptions() {
return opts;
}
/** /**
* Force player to proceed to the next ordered stage * Force player to proceed to the next ordered stage
* *

View File

@ -1339,9 +1339,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
/** /**
* Reload quests, player data, actions, config settings, lang and modules, in that order * Reload quests, actions, config settings, lang and modules, and player data
*/ */
public void reloadQuests() { public void reloadQuests() {
for (Quester quester : questers) {
quester.saveData();
}
quests.clear(); quests.clear();
events.clear(); events.clear();
@ -1360,6 +1363,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
loadModules(); loadModules();
for (Quester quester : questers) { for (Quester quester : questers) {
quester.loadData();
for (Quest q : quester.currentQuests.keySet()) { for (Quest q : quester.currentQuests.keySet()) {
quester.checkQuest(q); quester.checkQuest(q);
} }
@ -1465,6 +1469,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
try { // main "skip quest" try/catch block try { // main "skip quest" try/catch block
Quest quest = new Quest(); Quest quest = new Quest();
failedToLoad = false; failedToLoad = false;
quest.id = questKey;
if (config.contains("quests." + questKey + ".name")) { if (config.contains("quests." + questKey + ".name")) {
quest.setName(parseString(config.getString("quests." + questKey + ".name"), quest)); quest.setName(parseString(config.getString("quests." + questKey + ".name"), quest));
} else { } else {

View File

@ -673,10 +673,16 @@ public class CmdExecutor implements CommandExecutor {
if (args.length == 1) { if (args.length == 1) {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE")); player.sendMessage(ChatColor.YELLOW + Lang.get(player, "COMMAND_TAKE_USAGE"));
} else { } else {
Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' ')); final Quest questToFind = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
final Quester quester = plugin.getQuester(player.getUniqueId());
if (questToFind != null) { if (questToFind != null) {
final Quest q = questToFind; for (Quest q : quester.getCurrentQuests().keySet()) {
plugin.getQuester(player.getUniqueId()).offerQuest(q, true); if (q.getId().equals(questToFind.getId())) {
player.sendMessage(ChatColor.RED + Lang.get(player, "questAlreadyOn"));
return;
}
}
quester.offerQuest(questToFind, true);
} else { } else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questNotFound")); player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questNotFound"));
} }