Search in sources :

Example 1 with IQuestLine

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

the class QuestLineDatabase method getAllKeys.

@Override
public List<Integer> getAllKeys() {
    List<Integer> list = new ArrayList<Integer>(((Map<Integer, IQuestLine>) questLines).keySet());
    Collections.sort(list, new QuestLineSortByKey(this));
    return list;
}
Also used : IQuestLine(betterquesting.api.questing.IQuestLine) ArrayList(java.util.ArrayList) QuestLineSortByKey(betterquesting.misc.QuestLineSortByKey)

Example 2 with IQuestLine

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

the class QuestLineDatabase method readFromNBT.

@Override
public void readFromNBT(NBTTagList json, EnumSaveType saveType) {
    if (saveType != EnumSaveType.CONFIG) {
        return;
    }
    questLines.clear();
    ArrayList<IQuestLine> unassigned = new ArrayList<IQuestLine>();
    HashMap<Integer, Integer> orderMap = new HashMap<Integer, Integer>();
    for (int i = 0; i < json.tagCount(); i++) {
        NBTBase entry = json.get(i);
        if (entry == null || entry.getId() != 10) {
            continue;
        }
        NBTTagCompound jql = (NBTTagCompound) entry;
        int id = jql.hasKey("lineID", 99) ? jql.getInteger("lineID") : -1;
        int order = jql.hasKey("order", 99) ? jql.getInteger("order") : -1;
        QuestLine line = new QuestLine();
        line.readFromNBT(jql, saveType);
        if (id >= 0) {
            questLines.put(id, line);
        } else {
            unassigned.add(line);
        }
        if (order >= 0) {
            orderMap.put(order, id);
        }
    }
    // Legacy support ONLY
    for (IQuestLine q : unassigned) {
        questLines.put(this.nextKey(), q);
    }
    List<Integer> orderKeys = new ArrayList<Integer>(orderMap.keySet());
    Collections.sort(orderKeys);
    lineOrder.clear();
    for (int o : orderKeys) {
        lineOrder.add(orderMap.get(o));
    }
}
Also used : NBTBase(net.minecraft.nbt.NBTBase) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IQuestLine(betterquesting.api.questing.IQuestLine) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IQuestLine(betterquesting.api.questing.IQuestLine)

Example 3 with IQuestLine

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

the class QuestLineDatabase method writeToNBT.

@Override
public NBTTagList writeToNBT(NBTTagList json, EnumSaveType saveType) {
    if (saveType != EnumSaveType.CONFIG) {
        return json;
    }
    for (Entry<Integer, IQuestLine> entry : questLines.entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }
        int id = entry.getKey();
        NBTTagCompound jObj = entry.getValue().writeToNBT(new NBTTagCompound(), saveType);
        jObj.setInteger("lineID", id);
        jObj.setInteger("order", getOrderIndex(id));
        json.appendTag(jObj);
    }
    return json;
}
Also used : IQuestLine(betterquesting.api.questing.IQuestLine) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 4 with IQuestLine

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

the class PktHandlerLineEdit method handleServer.

@Override
public void handleServer(NBTTagCompound data, 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 edit quest lines 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;
    }
    int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
    int lID = !data.hasKey("lineID") ? -1 : data.getInteger("lineID");
    int idx = !data.hasKey("order") ? -1 : data.getInteger("order");
    IQuestLine questLine = QuestLineDatabase.INSTANCE.getValue(lID);
    if (aID < 0 || aID >= EnumPacketAction.values().length) {
        return;
    }
    EnumPacketAction action = EnumPacketAction.values()[aID];
    if (action == EnumPacketAction.ADD) {
        IQuestLine nq = new QuestLine();
        int nID = QuestLineDatabase.INSTANCE.nextKey();
        if (data.hasKey("data") && lID >= 0) {
            nID = lID;
            NBTTagCompound base = data.getCompoundTag("data");
            nq.readFromNBT(base.getCompoundTag("line"), EnumSaveType.CONFIG);
        }
        QuestLineDatabase.INSTANCE.add(nq, nID);
        PacketSender.INSTANCE.sendToAll(nq.getSyncPacket());
        return;
    } else if (// Edit quest lines
    action == EnumPacketAction.EDIT && questLine != null) {
        questLine.readPacket(data);
        if (idx >= 0 && QuestLineDatabase.INSTANCE.getOrderIndex(lID) != idx) {
            QuestLineDatabase.INSTANCE.setOrderIndex(lID, idx);
            PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
        } else {
            PacketSender.INSTANCE.sendToAll(questLine.getSyncPacket());
        }
        return;
    } else if (action == EnumPacketAction.REMOVE && questLine != null) {
        QuestLineDatabase.INSTANCE.removeKey(lID);
        PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
        return;
    }
}
Also used : IQuestLine(betterquesting.api.questing.IQuestLine) EnumPacketAction(betterquesting.api.enums.EnumPacketAction) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) QuestLine(betterquesting.questing.QuestLine) IQuestLine(betterquesting.api.questing.IQuestLine) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with IQuestLine

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

the class PktHandlerLineSync method handleServer.

@Override
public void handleServer(NBTTagCompound tag, EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    int id = !tag.hasKey("lineID") ? -1 : tag.getInteger("lineID");
    IQuestLine questLine = QuestLineDatabase.INSTANCE.getValue(id);
    if (questLine != null) {
        PacketSender.INSTANCE.sendToPlayer(questLine.getSyncPacket(), sender);
    }
}
Also used : IQuestLine(betterquesting.api.questing.IQuestLine)

Aggregations

IQuestLine (betterquesting.api.questing.IQuestLine)20 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)11 QuestingPacket (betterquesting.api.network.QuestingPacket)6 IQuest (betterquesting.api.questing.IQuest)4 QuestLine (betterquesting.questing.QuestLine)4 GuiButtonQuestInstance (betterquesting.api.client.gui.controls.GuiButtonQuestInstance)3 IQuestLineEntry (betterquesting.api.questing.IQuestLineEntry)3 ArrayList (java.util.ArrayList)3 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)2 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)2 QuestInstance (betterquesting.questing.QuestInstance)2 QuestLineEntry (betterquesting.questing.QuestLineEntry)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 GuiButtonThemed (betterquesting.api.client.gui.controls.GuiButtonThemed)1 EnumPacketAction (betterquesting.api.enums.EnumPacketAction)1 DatabaseEvent (betterquesting.api.events.DatabaseEvent)1 IQuestDatabase (betterquesting.api.questing.IQuestDatabase)1 IQuestLineDatabase (betterquesting.api.questing.IQuestLineDatabase)1 PanelButton (betterquesting.api2.client.gui.controls.PanelButton)1 CanvasTextured (betterquesting.api2.client.gui.panels.CanvasTextured)1