summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/Statistic.java
blob: c3665013a7de267c20d2ff6ef4225b91f85f0bc3 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.bukkit;

import java.util.Map;

import com.google.common.collect.Maps;

/**
 * Represents a countable statistic, which is collected by the client
 */
public enum Statistic {
    DAMAGE_DEALT(2020),
    DAMAGE_TAKEN(2021),
    DEATHS(2022),
    MOB_KILLS(2023),
    PLAYER_KILLS(2024),
    FISH_CAUGHT(2025),
    MINE_BLOCK(16777216, true),
    USE_ITEM(6908288, false),
    BREAK_ITEM(16973824, true);

    private final static Map<Integer, Statistic> BY_ID = Maps.newHashMap();
    private final int id;
    private final boolean isSubstat;
    private final boolean isBlock;

    private Statistic(int id) {
        this(id, false, false);
    }

    private Statistic(int id, boolean isBlock) {
        this(id, true, isBlock);
    }

    private Statistic(int id, boolean isSubstat, boolean isBlock) {
        this.id = id;
        this.isSubstat = isSubstat;
        this.isBlock = isBlock;
    }

    /**
     * Gets the ID for this statistic.
     *
     * @return ID of this statistic
     */
    public int getId() {
        return id;
    }

    /**
     * Checks if this is a substatistic.
     * <p>
     * A substatistic exists in mass for each block or item, depending on {@link #isBlock()}
     *
     * @return true if this is a substatistic
     */
    public boolean isSubstatistic() {
        return isSubstat;
    }

    /**
     * Checks if this is a substatistic dealing with blocks (As opposed to items)
     *
     * @return true if this deals with blocks, false if with items
     */
    public boolean isBlock() {
        return isSubstat && isBlock;
    }

    /**
     * Gets the statistic associated with the given ID.
     *
     * @param id ID of the statistic to return
     * @return statistic with the given ID
     */
    public static Statistic getById(int id) {
        return BY_ID.get(id);
    }

    static {
        for (Statistic statistic : values()) {
            BY_ID.put(statistic.id, statistic);
        }
    }
}