mirror of
https://github.com/PikaMug/Quests.git
synced 2024-09-09 14:08:02 +02:00
Use quest IDs instead of names for YAML implementation of quester data
This commit is contained in:
parent
e2da327cdf
commit
325522d9db
@ -3167,13 +3167,13 @@ public class Quester implements Comparable<Quester> {
|
||||
public FileConfiguration getBaseData() {
|
||||
final FileConfiguration data = new YamlConfiguration();
|
||||
if (currentQuests.isEmpty() == false) {
|
||||
final ArrayList<String> questNames = new ArrayList<String>();
|
||||
final ArrayList<String> questIds = new ArrayList<String>();
|
||||
final ArrayList<Integer> questStages = new ArrayList<Integer>();
|
||||
for (final Quest quest : currentQuests.keySet()) {
|
||||
questNames.add(quest.getName());
|
||||
questIds.add(quest.getId());
|
||||
questStages.add(currentQuests.get(quest));
|
||||
}
|
||||
data.set("currentQuests", questNames);
|
||||
data.set("currentQuests", questIds);
|
||||
data.set("currentStages", questStages);
|
||||
data.set("quest-points", questPoints);
|
||||
final ConfigurationSection dataSec = data.createSection("questData");
|
||||
@ -3437,41 +3437,27 @@ public class Quester implements Comparable<Quester> {
|
||||
if (completedQuests.isEmpty()) {
|
||||
data.set("completed-Quests", "none");
|
||||
} else {
|
||||
final List<String> noDupe = new ArrayList<String>();
|
||||
for (final Quest q : completedQuests) {
|
||||
// TODO use quest IDs instead
|
||||
if (!noDupe.contains(q.getName())) {
|
||||
noDupe.add(q.getName());
|
||||
}
|
||||
}
|
||||
final String[] completed = new String[noDupe.size()];
|
||||
int index = 0;
|
||||
for (final String s : noDupe) {
|
||||
completed[index] = s;
|
||||
index++;
|
||||
}
|
||||
data.set("completed-Quests", completed);
|
||||
final List<String> questIds = completedQuests.stream().map(Quest::getId).collect(Collectors.toList());
|
||||
data.set("completed-Quests", questIds);
|
||||
}
|
||||
if (completedTimes.isEmpty() == false) {
|
||||
final List<String> questNames = new LinkedList<String>();
|
||||
final List<String> questIds = new LinkedList<String>();
|
||||
final List<Long> questTimes = new LinkedList<Long>();
|
||||
for (final Entry<Quest, Long> entry : completedTimes.entrySet()) {
|
||||
// TODO use quest IDs instead
|
||||
questNames.add(entry.getKey().getName());
|
||||
questIds.add(entry.getKey().getId());
|
||||
questTimes.add(entry.getValue());
|
||||
}
|
||||
data.set("completedRedoableQuests", questNames);
|
||||
data.set("completedRedoableQuests", questIds);
|
||||
data.set("completedQuestTimes", questTimes);
|
||||
}
|
||||
if (amountsCompleted.isEmpty() == false) {
|
||||
final List<String> questNames = new LinkedList<String>();
|
||||
final List<String> questIds = new LinkedList<String>();
|
||||
final List<Integer> questAmts = new LinkedList<Integer>();
|
||||
for (final Entry<Quest, Integer> entry : amountsCompleted.entrySet()) {
|
||||
// TODO use quest IDs instead
|
||||
questNames.add(entry.getKey().getName());
|
||||
questIds.add(entry.getKey().getId());
|
||||
questAmts.add(entry.getValue());
|
||||
}
|
||||
data.set("amountsCompletedQuests", questNames);
|
||||
data.set("amountsCompletedQuests", questIds);
|
||||
data.set("amountsCompleted", questAmts);
|
||||
}
|
||||
// #getPlayer is faster
|
||||
|
@ -95,23 +95,29 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
return null;
|
||||
}
|
||||
if (data.contains("completedRedoableQuests")) {
|
||||
final List<String> questNames = data.getStringList("completedRedoableQuests");
|
||||
final List<String> questIds = data.getStringList("completedRedoableQuests");
|
||||
final List<Long> questTimes = data.getLongList("completedQuestTimes");
|
||||
final ConcurrentHashMap<Quest, Long> completedTimes = quester.getCompletedTimes();
|
||||
for (int i = 0; i < questNames.size(); i++) {
|
||||
if (plugin.getQuest(questNames.get(i)) != null) {
|
||||
completedTimes.put(plugin.getQuest(questNames.get(i)), questTimes.get(i));
|
||||
for (int i = 0; i < questIds.size(); i++) {
|
||||
if (plugin.getQuestById(questIds.get(i)) != null) {
|
||||
completedTimes.put(plugin.getQuestById(questIds.get(i)), questTimes.get(i));
|
||||
} else if (plugin.getQuest(questIds.get(i)) != null) {
|
||||
// Legacy
|
||||
completedTimes.put(plugin.getQuest(questIds.get(i)), questTimes.get(i));
|
||||
}
|
||||
}
|
||||
quester.setCompletedTimes(completedTimes);
|
||||
}
|
||||
if (data.contains("amountsCompletedQuests")) {
|
||||
final List<String> questNames = data.getStringList("amountsCompletedQuests");
|
||||
final List<String> questIds = data.getStringList("amountsCompletedQuests");
|
||||
final List<Integer> questAmts = data.getIntegerList("amountsCompleted");
|
||||
final ConcurrentHashMap<Quest, Integer> amountsCompleted = quester.getAmountsCompleted();
|
||||
for (int i = 0; i < questNames.size(); i++) {
|
||||
if (plugin.getQuest(questNames.get(i)) != null) {
|
||||
amountsCompleted.put(plugin.getQuest(questNames.get(i)), questAmts.get(i));
|
||||
for (int i = 0; i < questIds.size(); i++) {
|
||||
if (plugin.getQuestById(questIds.get(i)) != null) {
|
||||
amountsCompleted.put(plugin.getQuestById(questIds.get(i)), questAmts.get(i));
|
||||
} else if (plugin.getQuest(questIds.get(i)) != null) {
|
||||
// Legacy
|
||||
amountsCompleted.put(plugin.getQuest(questIds.get(i)), questAmts.get(i));
|
||||
}
|
||||
}
|
||||
quester.setAmountsCompleted(amountsCompleted);
|
||||
@ -122,7 +128,13 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
if (data.isList("completed-Quests")) {
|
||||
for (final String s : data.getStringList("completed-Quests")) {
|
||||
for (final Quest q : plugin.getQuests()) {
|
||||
if (q.getName().equalsIgnoreCase(s)) {
|
||||
if (q.getId().equals(s)) {
|
||||
if (!quester.getCompletedQuests().contains(q)) {
|
||||
completedQuests.add(q);
|
||||
}
|
||||
break;
|
||||
} else if (q.getName().equalsIgnoreCase(s)) {
|
||||
// Legacy
|
||||
if (!quester.getCompletedQuests().contains(q)) {
|
||||
completedQuests.add(q);
|
||||
}
|
||||
@ -133,14 +145,16 @@ public class SeparatedYamlStorage implements StorageImplementation {
|
||||
}
|
||||
quester.setCompletedQuests(completedQuests);
|
||||
if (data.isString("currentQuests") == false) {
|
||||
final List<String> questNames = data.getStringList("currentQuests");
|
||||
final List<String> questIds = data.getStringList("currentQuests");
|
||||
final List<Integer> questStages = data.getIntegerList("currentStages");
|
||||
// These appear to differ sometimes? That seems bad.
|
||||
final int maxSize = Math.min(questNames.size(), questStages.size());
|
||||
final int maxSize = Math.min(questIds.size(), questStages.size());
|
||||
final ConcurrentHashMap<Quest, Integer> currentQuests = quester.getCurrentQuests();
|
||||
for (int i = 0; i < maxSize; i++) {
|
||||
if (plugin.getQuest(questNames.get(i)) != null) {
|
||||
currentQuests.put(plugin.getQuest(questNames.get(i)), questStages.get(i));
|
||||
if (plugin.getQuestById(questIds.get(i)) != null) {
|
||||
currentQuests.put(plugin.getQuestById(questIds.get(i)), questStages.get(i));
|
||||
} else if (plugin.getQuest(questIds.get(i)) != null) {
|
||||
// Legacy
|
||||
currentQuests.put(plugin.getQuest(questIds.get(i)), questStages.get(i));
|
||||
}
|
||||
}
|
||||
quester.setCurrentQuests(currentQuests);
|
||||
|
Loading…
Reference in New Issue
Block a user