use of betterquesting.api.questing.tasks.ITickableTask in project BetterQuesting by Funwayguy.
the class EventHandler method onLivingUpdate.
@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
if (event.getEntityLiving().world.isRemote) {
return;
}
if (event.getEntityLiving() instanceof EntityPlayer) {
if (QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
return;
}
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
UUID uuid = QuestingAPI.getQuestingUUID(player);
List<IQuest> syncList = new ArrayList<IQuest>();
List<QuestInstance> updateList = new ArrayList<QuestInstance>();
for (Entry<ITask, IQuest> entry : QuestCache.INSTANCE.getActiveTasks(uuid).entrySet()) {
ITask task = entry.getKey();
IQuest quest = entry.getValue();
if (!task.isComplete(uuid)) {
if (task instanceof ITickableTask) {
((ITickableTask) task).updateTask(player, quest);
}
if (task.isComplete(uuid)) {
if (!syncList.contains(quest)) {
syncList.add(quest);
}
if (!updateList.contains(quest) && quest instanceof QuestInstance) {
updateList.add((QuestInstance) quest);
}
}
}
}
if (player.ticksExisted % 20 == 0) {
for (IQuest quest : QuestCache.INSTANCE.getActiveQuests(uuid)) {
quest.update(player);
if (quest.isComplete(uuid) && !syncList.contains(quest)) {
syncList.add(quest);
updateList.remove(quest);
}
}
QuestCache.INSTANCE.updateCache(player);
} else {
Iterator<IQuest> iterator = syncList.iterator();
while (iterator.hasNext()) {
IQuest quest = iterator.next();
quest.update(player);
if (quest.isComplete(uuid) && !quest.canSubmit(player)) {
iterator.remove();
updateList.remove(quest);
}
}
}
for (IQuest quest : syncList) {
PacketSender.INSTANCE.sendToAll(quest.getSyncPacket());
}
for (QuestInstance quest : updateList) {
quest.postPresetNotice(player, 1);
}
}
}
Aggregations