Search in sources :

Example 1 with QuestLine

use of betterquesting.questing.QuestLine 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 2 with QuestLine

use of betterquesting.questing.QuestLine in project BetterQuesting by Funwayguy.

the class ImportedQuestLines method createNew.

@Override
public IQuestLine createNew() {
    QuestLine ql = new QuestLine();
    ql.setParentDatabase(this);
    return ql;
}
Also used : QuestLine(betterquesting.questing.QuestLine) IQuestLine(betterquesting.api.questing.IQuestLine)

Example 3 with QuestLine

use of betterquesting.questing.QuestLine in project BetterQuesting by Funwayguy.

the class ImportedQuestLines method readFromNBT.

@Override
public void readFromNBT(NBTTagList json, EnumSaveType saveType) {
    if (saveType != EnumSaveType.CONFIG) {
        return;
    }
    questLines.clear();
    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);
        }
        if (order >= 0) {
            orderMap.put(order, id);
        }
    }
    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) HashMap(java.util.HashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) QuestLine(betterquesting.questing.QuestLine) IQuestLine(betterquesting.api.questing.IQuestLine)

Example 4 with QuestLine

use of betterquesting.questing.QuestLine in project BetterQuesting by Funwayguy.

the class LegacyLoader_v0 method readLineDatabase.

public void readLineDatabase(JsonArray jAry) {
    QuestLineDatabase.INSTANCE.reset();
    for (JsonElement je : jAry) {
        if (je == null || !je.isJsonObject()) {
            continue;
        }
        IQuestLine qLine = new QuestLine();
        readLine(qLine, je.getAsJsonObject());
        QuestLineDatabase.INSTANCE.add(qLine, QuestLineDatabase.INSTANCE.nextKey());
    }
}
Also used : JsonElement(com.google.gson.JsonElement) IQuestLine(betterquesting.api.questing.IQuestLine) QuestLine(betterquesting.questing.QuestLine) IQuestLine(betterquesting.api.questing.IQuestLine)

Example 5 with QuestLine

use of betterquesting.questing.QuestLine in project BetterQuesting by Funwayguy.

the class PktHandlerLineSync method handleClient.

@Override
public void handleClient(NBTTagCompound tag) {
    int id = !tag.hasKey("lineID") ? -1 : tag.getInteger("lineID");
    IQuestLine questLine = QuestLineDatabase.INSTANCE.getValue(id);
    if (questLine == null) {
        questLine = new QuestLine();
        QuestLineDatabase.INSTANCE.add(questLine, id);
    }
    questLine.readPacket(tag);
    MinecraftForge.EVENT_BUS.post(new DatabaseEvent.Update());
}
Also used : IQuestLine(betterquesting.api.questing.IQuestLine) QuestLine(betterquesting.questing.QuestLine) IQuestLine(betterquesting.api.questing.IQuestLine) DatabaseEvent(betterquesting.api.events.DatabaseEvent)

Aggregations

IQuestLine (betterquesting.api.questing.IQuestLine)5 QuestLine (betterquesting.questing.QuestLine)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumPacketAction (betterquesting.api.enums.EnumPacketAction)1 DatabaseEvent (betterquesting.api.events.DatabaseEvent)1 JsonElement (com.google.gson.JsonElement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NBTBase (net.minecraft.nbt.NBTBase)1 TextComponentString (net.minecraft.util.text.TextComponentString)1