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

package com.hypixel.hytale.server.core.asset.common;

import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
import javax.annotation.Nullable;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import com.hypixel.hytale.protocol.Asset;
import javax.annotation.Nonnull;
import java.util.Map;

public class PlayerCommonAssets
{
    @Nonnull
    private final Map<String, String> assetMissing;
    @Nonnull
    private final Map<String, String> assetSent;
    
    public PlayerCommonAssets(@Nonnull final Asset[] requiredAssets) {
        this.assetMissing = new Object2ObjectOpenHashMap<String, String>();
        for (final Asset requiredAsset : requiredAssets) {
            this.assetMissing.put(requiredAsset.hash, requiredAsset.name);
        }
        this.assetSent = new Object2ObjectOpenHashMap<String, String>();
    }
    
    public void sent(@Nullable final Asset[] hashes) {
        final Set<String> set = new HashSet<String>();
        if (hashes != null) {
            for (final Asset hash : hashes) {
                set.add(hash.hash);
            }
        }
        final Iterator<String> iterator = this.assetMissing.keySet().iterator();
        while (iterator.hasNext()) {
            final String hash2 = iterator.next();
            if (set.contains(hash2)) {
                iterator.remove();
                set.remove(hash2);
            }
        }
        if (!set.isEmpty()) {
            throw new RuntimeException("Still had hashes: " + String.valueOf(set));
        }
        this.assetSent.putAll(this.assetMissing);
        this.assetMissing.clear();
    }
}
