2014-01-11 21:48:46 +01:00
|
|
|
package net.minecraft.server;
|
2014-03-21 05:26:30 +01:00
|
|
|
|
2014-01-11 21:48:46 +01:00
|
|
|
import java.util.Map;
|
2014-03-21 05:26:30 +01:00
|
|
|
|
|
|
|
import net.minecraft.util.com.google.common.collect.Maps;
|
|
|
|
|
2014-01-11 21:48:46 +01:00
|
|
|
public class StatisticManager {
|
|
|
|
|
2014-03-21 05:26:30 +01:00
|
|
|
protected final Map a = Maps.newConcurrentMap();
|
2014-01-11 21:48:46 +01:00
|
|
|
|
|
|
|
public StatisticManager() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(Achievement achievement) {
|
2014-03-21 05:26:30 +01:00
|
|
|
return this.getStatisticValue((Statistic) achievement) > 0;
|
2014-01-11 21:48:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-01-15 05:42:40 +01:00
|
|
|
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-01-11 21:48:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-21 05:26:30 +01:00
|
|
|
public void setStatistic(EntityHuman entityhuman, Statistic statistic, int i) {
|
2014-01-11 21:48:46 +01:00
|
|
|
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) {
|
2014-01-11 21:48:46 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|