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

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

import com.hypixel.hytale.component.RemoveReason;
import java.util.UUID;
import com.hypixel.hytale.builtin.adventure.objectives.ObjectivePlugin;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.AddReason;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.Holder;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.spawning.beacons.LegacySpawnBeaconEntity;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.HolderSystem;

public class SpawnBeaconCheckRemovalSystem extends HolderSystem<EntityStore>
{
    @Nullable
    @Override
    public Query<EntityStore> getQuery() {
        return LegacySpawnBeaconEntity.getComponentType();
    }
    
    @Override
    public void onEntityAdd(@Nonnull final Holder<EntityStore> holder, @Nonnull final AddReason reason, @Nonnull final Store<EntityStore> store) {
        final LegacySpawnBeaconEntity spawnBeaconComponent = holder.getComponent(LegacySpawnBeaconEntity.getComponentType());
        assert spawnBeaconComponent != null;
        final UUID objectiveUUID = spawnBeaconComponent.getObjectiveUUID();
        if (objectiveUUID != null && ObjectivePlugin.get().getObjectiveDataStore().getObjective(objectiveUUID) == null) {
            spawnBeaconComponent.remove();
        }
    }
    
    @Override
    public void onEntityRemoved(@Nonnull final Holder<EntityStore> holder, @Nonnull final RemoveReason reason, @Nonnull final Store<EntityStore> store) {
    }
}
