All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minecraft.server.StatisticManager Maven / Gradle / Ivy

package net.minecraft.server;

import com.google.common.collect.Maps;

import java.util.Map;

public class StatisticManager {

  protected final Map a = Maps.newConcurrentMap();

  public StatisticManager() {
  }

  public boolean hasAchievement(Achievement achievement) {
    return this.getStatisticValue(achievement) > 0;
  }

  public boolean b(Achievement achievement) {
    return achievement.c == null || this.hasAchievement(achievement.c);
  }

  public void b(EntityHuman entityhuman, Statistic statistic, int i) {
    if (!statistic.d() || this.b((Achievement) statistic)) {
      // CraftBukkit start - fire Statistic events
      org.bukkit.event.Cancellable cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.handleStatisticsIncrease(entityhuman, statistic, this.getStatisticValue(statistic), i);
      if (cancellable != null && cancellable.isCancelled()) {
        return;
      }
      // CraftBukkit end
      this.setStatistic(entityhuman, statistic, this.getStatisticValue(statistic) + i);
    }
  }

  public void setStatistic(EntityHuman entityhuman, Statistic statistic, int i) {
    StatisticWrapper statisticwrapper = this.a.get(statistic);

    if (statisticwrapper == null) {
      statisticwrapper = new StatisticWrapper();
      this.a.put(statistic, statisticwrapper);
    }

    statisticwrapper.a(i);
  }

  public int getStatisticValue(Statistic statistic) {
    StatisticWrapper statisticwrapper = this.a.get(statistic);

    return statisticwrapper == null ? 0 : statisticwrapper.a();
  }

  public  T b(Statistic statistic) {
    StatisticWrapper statisticwrapper = this.a.get(statistic);

    return statisticwrapper != null ? (T) statisticwrapper.b() : null; // CraftBukkit - fix decompile error
  }

  public  T a(Statistic statistic, T t0) {
    StatisticWrapper statisticwrapper = this.a.get(statistic);

    if (statisticwrapper == null) {
      statisticwrapper = new StatisticWrapper();
      this.a.put(statistic, statisticwrapper);
    }

    statisticwrapper.a(t0);
    return t0;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy