Represents an achievement, which may be given to players
| 7 | * Represents an achievement, which may be given to players |
| 8 | */ |
| 9 | public enum Achievement { |
| 10 | OPEN_INVENTORY(0), |
| 11 | MINE_WOOD(1), |
| 12 | BUILD_WORKBENCH(2), |
| 13 | BUILD_PICKAXE(3), |
| 14 | BUILD_FURNACE(4), |
| 15 | ACQUIRE_IRON(5), |
| 16 | BUILD_HOE(6), |
| 17 | MAKE_BREAD(7), |
| 18 | BAKE_CAKE(8), |
| 19 | BUILD_BETTER_PICKAXE(9), |
| 20 | COOK_FISH(10), |
| 21 | ON_A_RAIL(11), |
| 22 | BUILD_SWORD(12), |
| 23 | KILL_ENEMY(13), |
| 24 | KILL_COW(14), |
| 25 | FLY_PIG(15); |
| 26 | |
| 27 | /** |
| 28 | * The offset used to distinguish Achievements and Statistics |
| 29 | */ |
| 30 | public final static int STATISTIC_OFFSET = 5242880; |
| 31 | private final static Map<Integer, Achievement> achievements = new HashMap<Integer, Achievement>(); |
| 32 | private final int id; |
| 33 | |
| 34 | private Achievement(int id) { |
| 35 | this.id = STATISTIC_OFFSET + id; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Gets the ID for this achievement. |
| 40 | * |
| 41 | * Note that this is offset using {@link #STATISTIC_OFFSET} |
| 42 | * |
| 43 | * @return ID of this achievement |
| 44 | */ |
| 45 | public int getId() { |
| 46 | return id; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Gets the achievement associated with the given ID. |
| 51 | * |
| 52 | * Note that the ID must already be offset using {@link #STATISTIC_OFFSET} |
| 53 | * |
| 54 | * @param id ID of the achievement to return |
| 55 | * @return Achievement with the given ID |
| 56 | */ |
| 57 | public static Achievement getAchievement(int id) { |
| 58 | return achievements.get(id); |
| 59 | } |
| 60 | |
| 61 | static { |
| 62 | for (Achievement ach : values()) { |
| 63 | achievements.put(ach.getId(), ach); |
| 64 | } |
| 65 | } |
| 66 | } |