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

package com.hypixel.hytale.builtin.mounts;

import com.hypixel.hytale.component.ComponentType;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.Ref;
import java.util.List;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class MountedByComponent implements Component<EntityStore>
{
    @Nonnull
    private final List<Ref<EntityStore>> passengers;
    
    public MountedByComponent() {
        this.passengers = new ObjectArrayList<Ref<EntityStore>>();
    }
    
    public static ComponentType<EntityStore, MountedByComponent> getComponentType() {
        return MountPlugin.getInstance().getMountedByComponentType();
    }
    
    public void removeInvalid() {
        this.passengers.removeIf(v -> !v.isValid());
    }
    
    @Nonnull
    public List<Ref<EntityStore>> getPassengers() {
        this.removeInvalid();
        return this.passengers;
    }
    
    public void addPassenger(final Ref<EntityStore> passenger) {
        this.passengers.add(passenger);
    }
    
    public void removePassenger(final Ref<EntityStore> ref) {
        this.passengers.remove(ref);
    }
    
    @Nonnull
    public MountedByComponent withPassenger(final Ref<EntityStore> passenger) {
        this.passengers.add(passenger);
        return this;
    }
    
    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        return new MountedByComponent();
    }
}
