001 package org.bukkit; 002 003 import java.util.Map; 004 005 import com.google.common.collect.Maps; 006 007 /** 008 * Represents the various difficulty levels that are available. 009 */ 010 public enum Difficulty { 011 /** 012 * Players regain health over time, hostile mobs don't spawn, the hunger 013 * bar does not deplete. 014 */ 015 PEACEFUL(0), 016 017 /** 018 * Hostile mobs spawn, enemies deal less damage than on normal difficulty, 019 * the hunger bar does deplete and starving deals up to 5 hearts of 020 * damage. (Default value) 021 */ 022 EASY(1), 023 024 /** 025 * Hostile mobs spawn, enemies deal normal amounts of damage, the hunger 026 * bar does deplete and starving deals up to 9.5 hearts of damage. 027 */ 028 NORMAL(2), 029 030 /** 031 * Hostile mobs spawn, enemies deal greater damage than on normal 032 * difficulty, the hunger bar does deplete and starving can kill players. 033 */ 034 HARD(3); 035 036 private final int value; 037 private final static Map<Integer, Difficulty> BY_ID = Maps.newHashMap(); 038 039 private Difficulty(final int value) { 040 this.value = value; 041 } 042 043 /** 044 * Gets the difficulty value associated with this Difficulty. 045 * 046 * @return An integer value of this difficulty 047 * @deprecated Magic value 048 */ 049 @Deprecated 050 public int getValue() { 051 return value; 052 } 053 054 /** 055 * Gets the Difficulty represented by the specified value 056 * 057 * @param value Value to check 058 * @return Associative {@link Difficulty} with the given value, or null if 059 * it doesn't exist 060 * @deprecated Magic value 061 */ 062 @Deprecated 063 public static Difficulty getByValue(final int value) { 064 return BY_ID.get(value); 065 } 066 067 static { 068 for (Difficulty diff : values()) { 069 BY_ID.put(diff.value, diff); 070 } 071 } 072 }