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;
}
}
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;
}
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));
}
}
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());
}
}
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());
}
Aggregations