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

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

import com.hypixel.hytale.component.RemoveReason;
import com.hypixel.hytale.server.core.io.PacketHandler;
import com.hypixel.hytale.server.core.entity.entities.player.hud.HudManager;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.AddReason;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.server.core.entity.entities.Player;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.RefSystem;

public class PlayerHudManagerSystems
{
    public static class InitializeSystem extends RefSystem<EntityStore>
    {
        @Nonnull
        private static final ComponentType<EntityStore, PlayerRef> PLAYER_REF_COMPONENT_TYPE;
        @Nonnull
        private static final ComponentType<EntityStore, Player> PLAYER_COMPONENT_TYPE;
        @Nonnull
        private static final Query<EntityStore> QUERY;
        
        @Nonnull
        @Override
        public Query<EntityStore> getQuery() {
            return InitializeSystem.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 Player playerComponent = commandBuffer.getComponent(ref, InitializeSystem.PLAYER_COMPONENT_TYPE);
            assert playerComponent != null;
            final PlayerRef playerRefComponent = commandBuffer.getComponent(ref, InitializeSystem.PLAYER_REF_COMPONENT_TYPE);
            assert playerRefComponent != null;
            final HudManager hudManager = playerComponent.getHudManager();
            final PacketHandler packetHandler = playerRefComponent.getPacketHandler();
            hudManager.sendVisibleHudComponents(packetHandler);
        }
        
        @Override
        public void onEntityRemove(@Nonnull final Ref<EntityStore> ref, @Nonnull final RemoveReason reason, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
        }
        
        static {
            PLAYER_REF_COMPONENT_TYPE = PlayerRef.getComponentType();
            PLAYER_COMPONENT_TYPE = Player.getComponentType();
            QUERY = Query.and(InitializeSystem.PLAYER_REF_COMPONENT_TYPE, InitializeSystem.PLAYER_COMPONENT_TYPE);
        }
    }
}
