Search in sources :

Example 1 with ImportedQuests

use of betterquesting.client.importers.ImportedQuests 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 ImportedQuests

use of betterquesting.client.importers.ImportedQuests 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)

Aggregations

IQuestDatabase (betterquesting.api.questing.IQuestDatabase)2 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 IQuestLine (betterquesting.api.questing.IQuestLine)1 IQuestLineEntry (betterquesting.api.questing.IQuestLineEntry)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 TextComponentString (net.minecraft.util.text.TextComponentString)1