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