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