2011-09-09 01:15:37 +01:00
|
|
|
package org.bukkit;
|
|
|
|
|
2011-09-14 17:22:50 -04:00
|
|
|
import java.util.Map;
|
|
|
|
|
2011-09-09 01:15:37 +01:00
|
|
|
import org.bukkit.entity.HumanEntity;
|
|
|
|
|
2012-01-29 11:10:40 +01:00
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
2011-09-09 01:15:37 +01:00
|
|
|
/**
|
2013-12-15 01:07:43 -05:00
|
|
|
* Represents the various type of game modes that {@link HumanEntity}s may
|
|
|
|
* have
|
2011-09-09 01:15:37 +01:00
|
|
|
*/
|
|
|
|
public enum GameMode {
|
|
|
|
/**
|
2013-12-15 01:07:43 -05:00
|
|
|
* Creative mode may fly, build instantly, become invulnerable and create
|
|
|
|
* free items.
|
2011-09-09 01:15:37 +01:00
|
|
|
*/
|
2011-09-14 17:22:50 -04:00
|
|
|
CREATIVE(1),
|
|
|
|
|
2011-09-09 01:15:37 +01:00
|
|
|
/**
|
|
|
|
* Survival mode is the "normal" gameplay type, with no special features.
|
|
|
|
*/
|
2012-07-29 02:34:09 -05:00
|
|
|
SURVIVAL(0),
|
|
|
|
|
|
|
|
/**
|
2014-07-08 23:56:15 -05:00
|
|
|
* Adventure mode cannot break blocks without the correct tools.
|
2012-07-29 02:34:09 -05:00
|
|
|
*/
|
|
|
|
ADVENTURE(2);
|
2011-09-14 17:22:50 -04:00
|
|
|
|
|
|
|
private final int value;
|
2012-01-29 11:10:40 +01:00
|
|
|
private final static Map<Integer, GameMode> BY_ID = Maps.newHashMap();
|
2011-09-14 17:22:50 -04:00
|
|
|
|
|
|
|
private GameMode(final int value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the mode value associated with this GameMode
|
|
|
|
*
|
|
|
|
* @return An integer value of this gamemode
|
2013-08-19 13:32:18 -05:00
|
|
|
* @deprecated Magic value
|
2011-09-14 17:22:50 -04:00
|
|
|
*/
|
2013-08-19 13:32:18 -05:00
|
|
|
@Deprecated
|
2011-09-14 17:22:50 -04:00
|
|
|
public int getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the GameMode represented by the specified value
|
|
|
|
*
|
|
|
|
* @param value Value to check
|
2013-12-15 01:07:43 -05:00
|
|
|
* @return Associative {@link GameMode} with the given value, or null if
|
|
|
|
* it doesn't exist
|
2013-08-19 13:32:18 -05:00
|
|
|
* @deprecated Magic value
|
2011-09-14 17:22:50 -04:00
|
|
|
*/
|
2013-08-19 13:32:18 -05:00
|
|
|
@Deprecated
|
2011-09-14 17:22:50 -04:00
|
|
|
public static GameMode getByValue(final int value) {
|
2012-01-29 11:10:40 +01:00
|
|
|
return BY_ID.get(value);
|
2011-09-14 17:22:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static {
|
2012-01-29 11:10:40 +01:00
|
|
|
for (GameMode mode : values()) {
|
|
|
|
BY_ID.put(mode.getValue(), mode);
|
2011-09-14 17:22:50 -04:00
|
|
|
}
|
|
|
|
}
|
2011-09-09 01:15:37 +01:00
|
|
|
}
|