001 package org.bukkit; 002 003 import java.util.Map; 004 005 import org.bukkit.entity.HumanEntity; 006 007 import com.google.common.collect.Maps; 008 009 /** 010 * Represents the various type of game modes that {@link HumanEntity}s may 011 * have 012 */ 013 public enum GameMode { 014 /** 015 * Creative mode may fly, build instantly, become invulnerable and create 016 * free items. 017 */ 018 CREATIVE(1), 019 020 /** 021 * Survival mode is the "normal" gameplay type, with no special features. 022 */ 023 SURVIVAL(0), 024 025 /** 026 * Adventure mode cannot break blocks without the correct tools. 027 */ 028 ADVENTURE(2); 029 030 private final int value; 031 private final static Map<Integer, GameMode> BY_ID = Maps.newHashMap(); 032 033 private GameMode(final int value) { 034 this.value = value; 035 } 036 037 /** 038 * Gets the mode value associated with this GameMode 039 * 040 * @return An integer value of this gamemode 041 * @deprecated Magic value 042 */ 043 @Deprecated 044 public int getValue() { 045 return value; 046 } 047 048 /** 049 * Gets the GameMode represented by the specified value 050 * 051 * @param value Value to check 052 * @return Associative {@link GameMode} with the given value, or null if 053 * it doesn't exist 054 * @deprecated Magic value 055 */ 056 @Deprecated 057 public static GameMode getByValue(final int value) { 058 return BY_ID.get(value); 059 } 060 061 static { 062 for (GameMode mode : values()) { 063 BY_ID.put(mode.getValue(), mode); 064 } 065 } 066 }