// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.adventure.npcobjectives.systems;

import com.hypixel.hytale.component.Component;
import java.util.List;
import com.hypixel.hytale.builtin.adventure.npcobjectives.transaction.KillTaskTransaction;
import com.hypixel.hytale.builtin.adventure.npcobjectives.resources.KillTrackerResource;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.Ref;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.server.core.modules.entity.damage.DeathSystems;

public class KillTrackerSystem extends DeathSystems.OnDeathSystem
{
    @Nullable
    @Override
    public Query<EntityStore> getQuery() {
        return NPCEntity.getComponentType();
    }
    
    @Override
    public void onComponentAdded(@Nonnull final Ref<EntityStore> ref, @Nonnull final DeathComponent component, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
        final NPCEntity entity = store.getComponent(ref, NPCEntity.getComponentType());
        final KillTrackerResource tracker = store.getResource(KillTrackerResource.getResourceType());
        final List<KillTaskTransaction> killTasks = tracker.getKillTasks();
        final int size = killTasks.size();
        for (int i = size - 1; i >= 0; --i) {
            final KillTaskTransaction entry = killTasks.get(i);
            entry.getTask().checkKilledEntity(store, ref, entry.getObjective(), entity, component.getDeathInfo());
        }
    }
}
