summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit/Achievement.java
blob: 98dbcd17a519a370be09160dc3915af30b9b7b27 (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
package org.bukkit;

import java.util.Map;

import com.google.common.collect.Maps;

/**
 * Represents an achievement, which may be given to players
 */
public enum Achievement {
    OPEN_INVENTORY(0),
    MINE_WOOD(1),
    BUILD_WORKBENCH(2),
    BUILD_PICKAXE(3),
    BUILD_FURNACE(4),
    ACQUIRE_IRON(5),
    BUILD_HOE(6),
    MAKE_BREAD(7),
    BAKE_CAKE(8),
    BUILD_BETTER_PICKAXE(9),
    COOK_FISH(10),
    ON_A_RAIL(11),
    BUILD_SWORD(12),
    KILL_ENEMY(13),
    KILL_COW(14),
    FLY_PIG(15),
    SNIPE_SKELETON(16),
    GET_DIAMONDS(17),
    NETHER_PORTAL(18),
    GHAST_RETURN(19),
    GET_BLAZE_ROD(20),
    BREW_POTION(21),
    END_PORTAL(22),
    THE_END(23),
    ENCHANTMENTS(24),
    OVERKILL(25),
    BOOKCASE(26);

    /**
     * The offset used to distinguish Achievements and Statistics
     */
    public final static int STATISTIC_OFFSET = 0x500000;
    private final static Map<Integer, Achievement> BY_ID = Maps.newHashMap();
    private final int id;

    private Achievement(int id) {
        this.id = STATISTIC_OFFSET + id;
    }

    /**
     * Gets the ID for this achievement.
     * <p>
     * Note that this is offset using {@link #STATISTIC_OFFSET}
     *
     * @return ID of this achievement
     */
    public int getId() {
        return id;
    }

    /**
     * Gets the achievement associated with the given ID.
     * <p>
     * Note that the ID must already be offset using {@link #STATISTIC_OFFSET}
     *
     * @param id ID of the achievement to return
     * @return Achievement with the given ID
     */
    public static Achievement getById(int id) {
        return BY_ID.get(id);
    }

    static {
        for (Achievement achievement : values()) {
            BY_ID.put(achievement.id, achievement);
        }
    }
}