Search in sources :

Example 1 with ITickableTask

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);
        }
    }
}
Also used : ITask(betterquesting.api.questing.tasks.ITask) IQuest(betterquesting.api.questing.IQuest) QuestInstance(betterquesting.questing.QuestInstance) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ITickableTask(betterquesting.api.questing.tasks.ITickableTask) UUID(java.util.UUID) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IQuest (betterquesting.api.questing.IQuest)1 ITask (betterquesting.api.questing.tasks.ITask)1 ITickableTask (betterquesting.api.questing.tasks.ITickableTask)1 QuestInstance (betterquesting.questing.QuestInstance)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1