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

package com.hypixel.hytale.server.core.modules.entity.player;

import com.hypixel.hytale.component.dependency.RootDependency;
import com.hypixel.hytale.component.system.ISystem;
import com.hypixel.hytale.component.dependency.SystemDependency;
import com.hypixel.hytale.component.dependency.OrderPriority;
import com.hypixel.hytale.component.dependency.SystemGroupDependency;
import com.hypixel.hytale.component.dependency.Order;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.component.system.tick.ArchetypeTickingSystem;
import com.hypixel.hytale.server.core.Constants;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.query.Query;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.component.dependency.Dependency;
import java.util.Set;
import com.hypixel.hytale.component.system.tick.RunWhenPausedSystem;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;

public class PlayerConnectionFlushSystem extends EntityTickingSystem<EntityStore> implements RunWhenPausedSystem<EntityStore>
{
    public static final Set<Dependency<EntityStore>> DEPENDENCIES;
    private final ComponentType<EntityStore, PlayerRef> componentType;
    
    public PlayerConnectionFlushSystem(final ComponentType<EntityStore, PlayerRef> componentType) {
        this.componentType = componentType;
    }
    
    @Nonnull
    @Override
    public Set<Dependency<EntityStore>> getDependencies() {
        return PlayerConnectionFlushSystem.DEPENDENCIES;
    }
    
    @Override
    public Query<EntityStore> getQuery() {
        return this.componentType;
    }
    
    @Override
    public boolean isParallel(final int archetypeChunkSize, final int taskCount) {
        return EntityTickingSystem.maybeUseParallel(archetypeChunkSize, taskCount);
    }
    
    @Override
    public void tick(final float dt, final int systemIndex, @Nonnull final Store<EntityStore> store) {
        if (Constants.FORCE_NETWORK_FLUSH) {
            store.tick(this, dt, systemIndex);
        }
    }
    
    @Override
    public void tick(final float dt, final int index, @Nonnull final ArchetypeChunk<EntityStore> archetypeChunk, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
        archetypeChunk.getComponent(index, this.componentType).getPacketHandler().tryFlush();
    }
    
    static {
        DEPENDENCIES = Set.of(new SystemGroupDependency<EntityStore>(Order.AFTER, EntityStore.SEND_PACKET_GROUP), new SystemDependency(Order.AFTER, (Class<ISystem>)PlayerPingSystem.class, OrderPriority.CLOSEST), RootDependency.last());
    }
}
