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

package com.hypixel.hytale.builtin.portals.systems.curse;

import com.hypixel.hytale.component.Component;
import javax.annotation.Nullable;
import com.hypixel.hytale.component.query.Query;
import java.util.UUID;
import com.hypixel.hytale.builtin.portals.utils.CursedItems;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
import com.hypixel.hytale.builtin.portals.resources.PortalWorld;
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.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.modules.entity.damage.DeathSystems;

public class DiedInPortalSystem extends DeathSystems.OnDeathSystem
{
    @Override
    public void onComponentAdded(@Nonnull final Ref<EntityStore> ref, @Nonnull final DeathComponent component, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
        final PortalWorld portalWorld = commandBuffer.getResource(PortalWorld.getResourceType());
        if (!portalWorld.exists()) {
            return;
        }
        final UUID playerId = commandBuffer.getComponent(ref, UUIDComponent.getComponentType()).getUuid();
        portalWorld.getDiedInWorld().add(playerId);
        final Player player = store.getComponent(ref, Player.getComponentType());
        CursedItems.deleteAll(player);
    }
    
    @Nullable
    @Override
    public Query<EntityStore> getQuery() {
        return (Query<EntityStore>)Query.and(Player.getComponentType(), UUIDComponent.getComponentType());
    }
}
