Search in sources :

Example 1 with IQuestDatabase

use of betterquesting.api.questing.IQuestDatabase in project BetterQuesting by Funwayguy.

the class GuiImporters method setValues.

@Override
public void setValues(File[] files) {
    if (selected != null) {
        IQuestDatabase questDB = new ImportedQuests();
        IQuestLineDatabase lineDB = new ImportedQuestLines();
        selected.loadFiles(questDB, lineDB, files);
        if (questDB.size() > 0 || lineDB.size() > 0) {
            NBTTagCompound jsonBase = new NBTTagCompound();
            jsonBase.setTag("quests", questDB.writeToNBT(new NBTTagList(), EnumSaveType.CONFIG));
            jsonBase.setTag("lines", lineDB.writeToNBT(new NBTTagList(), EnumSaveType.CONFIG));
            NBTTagCompound tag = new NBTTagCompound();
            tag.setTag("data", jsonBase);
            PacketSender.INSTANCE.sendToServer(new QuestingPacket(PacketTypeNative.IMPORT.GetLocation(), tag));
            mc.displayGuiScreen(parent);
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IQuestDatabase(betterquesting.api.questing.IQuestDatabase) IQuestLineDatabase(betterquesting.api.questing.IQuestLineDatabase) ImportedQuestLines(betterquesting.client.importers.ImportedQuestLines) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ImportedQuests(betterquesting.client.importers.ImportedQuests) QuestingPacket(betterquesting.api.network.QuestingPacket)

Example 2 with IQuestDatabase

use of betterquesting.api.questing.IQuestDatabase in project BetterQuesting by Funwayguy.

the class PktHandlerImport method handleServer.

@Override
public void handleServer(NBTTagCompound tag, EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
    if (!isOP) {
        BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to import quests without OP permissions!");
        sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
        // Player is not operator. Do nothing
        return;
    }
    NBTTagCompound jsonBase = tag.getCompoundTag("data");
    IQuestDatabase impQuestDB = new ImportedQuests();
    IQuestLineDatabase impQuestLineDB = new ImportedQuestLines();
    impQuestDB.readFromNBT(jsonBase.getTagList("quests", 10), EnumSaveType.CONFIG);
    impQuestLineDB.readFromNBT(jsonBase.getTagList("lines", 10), EnumSaveType.CONFIG);
    BetterQuesting.logger.log(Level.INFO, "Importing " + impQuestDB.size() + " quest(s) and " + impQuestLineDB.size() + " quest line(s) from " + sender.getGameProfile().getName());
    HashMap<Integer, Integer> remapped = getRemappedIDs(impQuestDB.getAllKeys());
    for (Entry<Integer, Integer> entry : remapped.entrySet()) {
        QuestDatabase.INSTANCE.add(impQuestDB.getValue(entry.getKey()), entry.getValue());
    }
    for (IQuestLine questLine : impQuestLineDB.getAllValues()) {
        for (IQuestLineEntry qle : questLine.getAllValues()) {
            int oldID = questLine.getKey(qle);
            questLine.removeKey(oldID);
            questLine.add(qle, remapped.get(oldID));
        }
        QuestLineDatabase.INSTANCE.add(questLine, QuestLineDatabase.INSTANCE.nextKey());
    }
    PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
    PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ImportedQuestLines(betterquesting.client.importers.ImportedQuestLines) IQuestLineEntry(betterquesting.api.questing.IQuestLineEntry) ImportedQuests(betterquesting.client.importers.ImportedQuests) TextComponentString(net.minecraft.util.text.TextComponentString) IQuestDatabase(betterquesting.api.questing.IQuestDatabase) IQuestLine(betterquesting.api.questing.IQuestLine) IQuestLineDatabase(betterquesting.api.questing.IQuestLineDatabase)

Example 3 with IQuestDatabase

use of betterquesting.api.questing.IQuestDatabase in project BetterQuesting by Funwayguy.

the class QuestCache method updateCache.

public void updateCache(EntityPlayer player) {
    if (player == null) {
        return;
    }
    UUID uuid = QuestingAPI.getQuestingUUID(player);
    HashMap<Integer, List<Integer>> pCache = new HashMap<Integer, List<Integer>>();
    IQuestDatabase questDB = QuestingAPI.getAPI(ApiReference.QUEST_DB);
    List<Integer> idList = questDB.getAllKeys();
    for (int qID : idList) {
        IQuest quest = questDB.getValue(qID);
        if (quest == null || (!quest.isUnlocked(uuid) && !quest.getProperties().getProperty(NativeProps.LOCKED_PROGRESS))) {
            // Invalid or locked
            continue;
        } else if (quest.canSubmit(player) || quest.getProperties().getProperty(NativeProps.REPEAT_TIME).intValue() >= 0) {
        // Active quest or pending repeat reset
        } else if (quest.getProperties().getProperty(NativeProps.AUTO_CLAIM) && !quest.hasClaimed(uuid)) {
        // Pending auto-claim
        } else {
            continue;
        }
        List<Integer> tList = new ArrayList<Integer>();
        for (int tID : quest.getTasks().getAllKeys()) {
            ITask task = quest.getTasks().getValue(tID);
            if (task != null && !task.isComplete(uuid)) {
                tList.add(tID);
            }
        }
        pCache.put(qID, tList);
    }
    rawCache.put(uuid, pCache);
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) HashMap(java.util.HashMap) IQuestDatabase(betterquesting.api.questing.IQuestDatabase) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Aggregations

IQuestDatabase (betterquesting.api.questing.IQuestDatabase)3 IQuestLineDatabase (betterquesting.api.questing.IQuestLineDatabase)2 ImportedQuestLines (betterquesting.client.importers.ImportedQuestLines)2 ImportedQuests (betterquesting.client.importers.ImportedQuests)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 QuestingPacket (betterquesting.api.network.QuestingPacket)1 IQuest (betterquesting.api.questing.IQuest)1 IQuestLine (betterquesting.api.questing.IQuestLine)1 IQuestLineEntry (betterquesting.api.questing.IQuestLineEntry)1 ITask (betterquesting.api.questing.tasks.ITask)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TextComponentString (net.minecraft.util.text.TextComponentString)1