Package net.citizensnpcs.questers.quests.Quest

Examples of net.citizensnpcs.questers.quests.Quest.QuestBuilder


            "location", "string", "optional", "finishhere", "materialid", "message");

    public static void instantiateQuests(ConfigurationHandler quests) {
        questLoop: for (Object questName : quests.getKeys(null)) {
            String path = questName.toString();
            QuestBuilder quest = new QuestBuilder(questName.toString());
            quest.description(quests.getString(path + ".texts.description"));
            quest.granter(new RewardGranter(quests.getString(path + ".texts.completion"), loadRewards(quests, path
                    + ".rewards")));
            quest.progressText(quests.getString(path + ".texts.status"));
            quest.acceptanceText(quests.getString(path + ".texts.acceptance"));
            quest.repeatLimit(quests.getInt(path + ".repeats"));
            quest.requirements(Lists.transform(loadRewards(quests, path + ".requirements"), transformer));
            quest.initialRewards(loadRewards(quests, path + ".initial"));
            quest.abortRewards(loadRewards(quests, path + ".abort"));
            quest.delay(quests.getLong(path + ".delay"));
            String tempPath = path;

            Objectives objectives = new Objectives();
            path = tempPath = questName + ".objectives";
            if (quests.pathExists(path)) {
                for (Object step : quests.getKeys(path)) {
                    if (!StringUtils.isNumber(step.toString()))
                        continue; // fix checking for objectives under rewards:
                                  // or messages:
                    tempPath = questName + ".objectives." + step;
                    List<Objective> tempStep = Lists.newArrayList();
                    for (Object objective : quests.getKeys(tempPath)) {
                        if (!StringUtils.isNumber(objective.toString()))
                            continue;
                        path = tempPath + "." + objective;
                        String type = quests.getString(path + ".type");
                        if (type == null || type.isEmpty() || QuestAPI.getObjective(type) == null) {
                            Messaging.log("Invalid quest objective - incorrect type specified. Quest '" + questName
                                    + "' not loaded.");
                            continue questLoop;
                        }
                        Objective.Builder obj = new Objective.Builder(type);
                        for (String key : quests.getKeys(path)) {
                            if (!usedKeys.contains(key)) {
                                obj.param(key, new RawYAMLObject(quests.getRaw(path + "." + key)));
                            }
                        }
                        if (quests.pathExists(path + ".status"))
                            obj.statusText(quests.getString(path + ".status"));
                        if (quests.pathExists(path + ".amount"))
                            obj.amount(quests.getInt(path + ".amount"));
                        if (quests.pathExists(path + ".npcdestination"))
                            obj.destination(quests.getInt(path + ".npcdestination"));
                        if (quests.pathExists(path + ".item")) {
                            int id = quests.getInt(path + ".item.id");
                            int amount = quests.getInt(path + ".item.amount");
                            short data = 0;
                            if (quests.pathExists(path + ".item.data"))
                                data = (short) quests.getInt(path + ".item.data");
                            obj.item(new ItemStack(id, amount, data));
                        }
                        if (quests.pathExists(path + ".location")) {
                            obj.location(LocationUtils.loadLocation(quests, path, false));
                        }
                        obj.string(quests.getString(path + ".string"));
                        obj.optional(quests.getBoolean(path + ".optional"));
                        obj.completeHere(quests.getBoolean(path + ".finishhere"));
                        obj.granter(new RewardGranter(quests.getString(path + ".message"), loadRewards(quests, path
                                + ".rewards")));

                        if (quests.pathExists(path + ".materialid")) {
                            if (quests.getInt(path + ".materialid") != 0)
                                obj.material(Material.getMaterial(quests.getInt(path + ".materialid")));
                        }
                        tempStep.add(obj.build());
                    }
                    RewardGranter granter = new RewardGranter(quests.getString(tempPath + ".message"), loadRewards(
                            quests, tempPath + ".rewards"));
                    objectives.add(new QuestStep(tempStep, granter, quests.getBoolean(tempPath + ".finishhere")));
                }
            }
            if (objectives.steps().size() == 0) {
                quest = null;
                Messaging.log("Quest " + questName + " is invalid - no objectives set.");
                continue;
            }
            quest.objectives(objectives);
            QuestManager.addQuest(quest.create());
        }
    }
View Full Code Here

TOP

Related Classes of net.citizensnpcs.questers.quests.Quest.QuestBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.