Fix loss of custom obj progress after logout

This commit is contained in:
PikaMug 2021-09-07 16:27:57 -04:00
parent a7a03eca5b
commit 2383bafc98
2 changed files with 13 additions and 8 deletions

View File

@ -162,18 +162,24 @@ public abstract class CustomObjective implements Listener {
if (quester != null) {
if (quester.hasCustomObjective(quest, obj.getName())) {
int index = -1;
final LinkedList<Integer> customObjCounts = quester.getQuestData(quest).customObjectiveCounts;
for (final CustomObjective co : quester.getCurrentStage(quest).customObjectives) {
index++;
if (co.getName().equals(this.getName())) {
final int old = quester.getQuestData(quest).customObjectiveCounts.get(index);
if (index >= customObjCounts.size()) {
plugin.getLogger().severe("Index was larger than count for " + obj.getName() + " by "
+ obj.getAuthor());
continue;
}
final int old = customObjCounts.get(index);
plugin.getQuester(player.getUniqueId()).getQuestData(quest).customObjectiveCounts
.set(index, old + count);
break;
}
}
if (index > -1) {
final int progress = quester.getQuestData(quest).customObjectiveCounts.get(index);
final int goal = quester.getCurrentStage(quest).customObjectiveCounts.get(index);
final int progress = customObjCounts.get(index);
final int goal = customObjCounts.get(index);
final ObjectiveType type = ObjectiveType.CUSTOM;
final QuesterPreUpdateObjectiveEvent preEvent

View File

@ -161,11 +161,10 @@ public class SeparatedYamlStorage implements StorageImplementation {
for (final String key : dataSec.getKeys(false)) {
final ConfigurationSection questSec = dataSec.getConfigurationSection(key);
final Quest quest = plugin.getQuestById(key) != null ? plugin.getQuestById(key) : plugin.getQuest(key);
Stage stage;
if (quest == null || !quester.getCurrentQuests().containsKey(quest)) {
continue;
}
stage = quester.getCurrentStage(quest);
final Stage stage = quester.getCurrentStage(quest);
if (stage == null) {
quest.completeQuest(quester);
plugin.getLogger().severe("[Quests] Invalid stage number for player: \"" + uniqueId + "\" on Quest \""
@ -376,9 +375,9 @@ public class SeparatedYamlStorage implements StorageImplementation {
final List<Boolean> passAmounts = questSec.getBooleanList("passwords-said");
quester.getQuestData(quest).setPasswordsSaid(new LinkedList<Boolean>(passAmounts));
}
if (questSec.contains("custom-objectives")) {
final List<Integer> customObjCount = questSec.getIntegerList("custom-objective-counts");
quester.getQuestData(quest).setCustomObjectiveCounts(new LinkedList<Integer>(customObjCount));
if (questSec.contains("custom-objective-counts")) {
final List<Integer> customObjCounts = questSec.getIntegerList("custom-objective-counts");
quester.getQuestData(quest).setCustomObjectiveCounts(new LinkedList<Integer>(customObjCounts));
}
if (questSec.contains("stage-delay")) {
quester.getQuestData(quest).setDelayTimeLeft(questSec.getLong("stage-delay"));