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

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

import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.system.RefSystem;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.RemoveReason;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.AddReason;
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.query.Query;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.entity.entities.player.movement.MovementManager;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.HolderSystem;

public class PlayerMovementManagerSystems
{
    public static class AssignmentSystem extends HolderSystem<EntityStore>
    {
        @Nonnull
        private static final ComponentType<EntityStore, MovementManager> MOVEMENT_MANAGER_COMPONENT_TYPE;
        @Nonnull
        private static final Query<EntityStore> QUERY;
        
        @Nonnull
        @Override
        public Query<EntityStore> getQuery() {
            return AssignmentSystem.QUERY;
        }
        
        @Override
        public void onEntityAdd(@Nonnull final Holder<EntityStore> holder, @Nonnull final AddReason reason, @Nonnull final Store<EntityStore> store) {
            holder.ensureComponent(AssignmentSystem.MOVEMENT_MANAGER_COMPONENT_TYPE);
        }
        
        @Override
        public void onEntityRemoved(@Nonnull final Holder<EntityStore> holder, @Nonnull final RemoveReason reason, @Nonnull final Store<EntityStore> store) {
        }
        
        static {
            MOVEMENT_MANAGER_COMPONENT_TYPE = MovementManager.getComponentType();
            QUERY = Query.and(PlayerRef.getComponentType(), Query.not((Query<Object>)AssignmentSystem.MOVEMENT_MANAGER_COMPONENT_TYPE));
        }
    }
    
    public static class PostAssignmentSystem extends RefSystem<EntityStore>
    {
        @Nonnull
        private static final ComponentType<EntityStore, MovementManager> MOVEMENT_MANAGER_COMPONENT_TYPE;
        @Nonnull
        private static final Query<EntityStore> QUERY;
        
        @Nonnull
        @Override
        public Query<EntityStore> getQuery() {
            return PostAssignmentSystem.QUERY;
        }
        
        @Override
        public void onEntityAdded(@Nonnull final Ref<EntityStore> ref, @Nonnull final AddReason reason, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
            final MovementManager movementManagerComponent = commandBuffer.getComponent(ref, PostAssignmentSystem.MOVEMENT_MANAGER_COMPONENT_TYPE);
            assert movementManagerComponent != null;
            movementManagerComponent.resetDefaultsAndUpdate(ref, commandBuffer);
        }
        
        @Override
        public void onEntityRemove(@Nonnull final Ref<EntityStore> ref, @Nonnull final RemoveReason reason, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
        }
        
        static {
            MOVEMENT_MANAGER_COMPONENT_TYPE = MovementManager.getComponentType();
            QUERY = Query.and(PostAssignmentSystem.MOVEMENT_MANAGER_COMPONENT_TYPE, PlayerRef.getComponentType());
        }
    }
}
