summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/StatisticManager.java
blob: d41dc4dd5ac7c1e045aa2915bd33bf2609cda56c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package net.minecraft.server;

import java.util.Map;

import net.minecraft.util.com.google.common.collect.Maps;

public class StatisticManager {

    protected final Map a = Maps.newConcurrentMap();

    public StatisticManager() {
    }

    public boolean hasAchievement(Achievement achievement) {
        return this.getStatisticValue((Statistic) 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 = (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 = (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;
    }
}