@Override public QuestSet read(JsonReader in) throws IOException { String name = null, description = null; requirementMapping.clear(); optionMapping.clear(); List<Quest> quests = new ArrayList<Quest>(); in.beginObject(); while (in.hasNext()) { String next = in.nextName(); if (next.equalsIgnoreCase(NAME)) { name = in.nextString(); } else if (next.equalsIgnoreCase(DESCRIPTION)) { description = in.nextString(); } else if (next.equalsIgnoreCase(QUESTS)) { in.beginArray(); QUEST_ID = Quest.size(); while (in.hasNext()) { Quest quest = QUEST_ADAPTER.read(in); if (quest != null) { quests.add(quest); } } in.endArray(); } } in.endObject(); for (QuestSet set : Quest.getQuestSets()) { if (set.getName().equals(name)) { return removeQuests(quests); } } if (name != null && description != null) { QuestSet set = new QuestSet(name, description); Quest.getQuestSets().add(set); SaveHelper.add(SaveHelper.EditType.SET_CREATE); for (Quest quest : quests) { quest.setQuestSet(set); } for (Map.Entry<Quest, List<Integer>> entry : requirementMapping.entrySet()) { for (int i : entry.getValue()) entry.getKey().addRequirement(i); } for (Map.Entry<Quest, List<Integer>> entry : optionMapping.entrySet()) { for (int i : entry.getValue()) entry.getKey().addOptionLink(i); } return set; } return removeQuests(quests); }
@Override public Quest read(JsonReader in) throws IOException { int ID_OFFSET = Quest.size(); QUEST = new Quest(ID_OFFSET, "", "", 0, 0, false); List<Integer> requirement = new ArrayList<>(), options = new ArrayList<>(); in.beginObject(); while (in.hasNext()) { switch (in.nextName()) { case NAME: QUEST.setName(in.nextString()); break; case DESCRIPTION: QUEST.setDescription(in.nextString()); break; case X: ReflectionHelper.setPrivateValue(Quest.class, QUEST, in.nextInt(), X); break; case Y: ReflectionHelper.setPrivateValue(Quest.class, QUEST, in.nextInt(), Y); break; case TRIGGER_TASKS: QUEST.setTriggerTasks(in.nextInt()); break; case PARENT_REQUIREMENT: QUEST.setParentRequirementCount(in.nextInt()); break; case BIG_ICON: QUEST.setBigIcon(in.nextBoolean()); break; case ICON: QUEST.setIcon(MinecraftAdapter.ITEM_STACK.read(in)); break; case REQUIREMENTS: in.beginArray(); while (in.hasNext()) { requirement.add(in.nextInt() + QUEST_ID); } in.endArray(); break; case OPTIONS: in.beginArray(); while (in.hasNext()) { options.add(in.nextInt() + QUEST_ID); } in.endArray(); break; case REPEAT: QUEST.setRepeatInfo(REPEAT_INFO_ADAPTER.read(in)); break; case TRIGGER: QUEST.setTriggerType(TriggerType.valueOf(in.nextString())); break; case TASKS: in.beginArray(); while (in.hasNext()) { QuestTask task = TASK_ADAPTER.read(in); if (task != null) { QUEST.getTasks().add(task); } } in.endArray(); break; case REWARDS: ReflectionHelper.setPrivateValue( Quest.class, QUEST, readItemStackArray(in), REWARDS); break; case REWARDS_CHOICE: ReflectionHelper.setPrivateValue( Quest.class, QUEST, readItemStackArray(in), REWARDS_CHOICE); break; case REWARDS_REPUTATION: in.beginArray(); List<Quest.ReputationReward> reputationRewards = new ArrayList<>(); while (in.hasNext()) { Quest.ReputationReward reward = REPUTATION_REWARD_ADAPTER.read(in); if (reward != null) reputationRewards.add(reward); } QUEST.setReputationRewards(reputationRewards); in.endArray(); break; } } in.endObject(); if (!QUEST.getName().isEmpty()) { requirementMapping.put(QUEST, requirement); optionMapping.put(QUEST, options); return QUEST; } QuestLine.getActiveQuestLine().quests.remove(QUEST.getId()); return null; }