Paper/src/main/java/net/minecraft/server/StatisticManager.java

69 Zeilen
2.3 KiB
Java

package net.minecraft.server;
2014-03-21 05:26:30 +01:00
import java.util.Map;
2014-03-21 05:26:30 +01:00
import net.minecraft.util.com.google.common.collect.Maps;
public class StatisticManager {
2014-03-21 05:26:30 +01:00
protected final Map a = Maps.newConcurrentMap();
public StatisticManager() {
}
public boolean a(Achievement achievement) {
2014-03-21 05:26:30 +01:00
return this.getStatisticValue((Statistic) achievement) > 0;
}
public boolean b(Achievement achievement) {
return achievement.c == null || this.a(achievement.c);
}
public void b(EntityHuman entityhuman, Statistic statistic, int i) {
if (!statistic.d() || this.b((Achievement) statistic)) {
2014-03-21 05:26:30 +01:00
// 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
2014-03-21 05:26:30 +01:00
this.setStatistic(entityhuman, statistic, this.getStatisticValue(statistic) + i);
}
}
2014-03-21 05:26:30 +01:00
public void setStatistic(EntityHuman entityhuman, Statistic statistic, int i) {
StatisticWrapper statisticwrapper = (StatisticWrapper) this.a.get(statistic);
if (statisticwrapper == null) {
statisticwrapper = new StatisticWrapper();
this.a.put(statistic, statisticwrapper);
}
statisticwrapper.a(i);
}
2014-03-21 05:26:30 +01:00
public int getStatisticValue(Statistic statistic) {
StatisticWrapper statisticwrapper = (StatisticWrapper) this.a.get(statistic);
return statisticwrapper == null ? 0 : statisticwrapper.a();
}
public IJsonStatistic b(Statistic statistic) {
StatisticWrapper statisticwrapper = (StatisticWrapper) this.a.get(statistic);
return statisticwrapper != null ? statisticwrapper.b() : null;
}
public IJsonStatistic a(Statistic statistic, IJsonStatistic ijsonstatistic) {
StatisticWrapper statisticwrapper = (StatisticWrapper) this.a.get(statistic);
if (statisticwrapper == null) {
statisticwrapper = new StatisticWrapper();
this.a.put(statistic, statisticwrapper);
}
statisticwrapper.a(ijsonstatistic);
return ijsonstatistic;
}
}