package net.minecraft.stats;

import net.minecraft.world.entity.player.Player;
import it.unimi.dsi.fastutil.objects.Object2IntMaps;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;

public class StatsCounter {
    protected final Object2IntMap<Stat<?>> stats;
    
    public StatsCounter() {
        (this.stats = (Object2IntMap<Stat<?>>)Object2IntMaps.synchronize((Object2IntMap)new Object2IntOpenHashMap())).defaultReturnValue(0);
    }
    
    public void increment(final Player bec, final Stat<?> acr, final int integer) {
        final int integer2 = (int)Math.min(this.getValue(acr) + (long)integer, 2147483647L);
        this.setValue(bec, acr, integer2);
    }
    
    public void setValue(final Player bec, final Stat<?> acr, final int integer) {
        this.stats.put(acr, integer);
    }
    
    public <T> int getValue(final StatType<T> act, final T object) {
        return act.contains(object) ? this.getValue(act.get(object)) : 0;
    }
    
    public int getValue(final Stat<?> acr) {
        return this.stats.getInt(acr);
    }
}
