Added GameMode command.

By: EvilSeph <evilseph@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-09-14 17:22:50 -04:00
parent a3154f3ffc
commit 453084c971
5 changed files with 100 additions and 3 deletions

View File

@@ -1,5 +1,8 @@
package org.bukkit;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.HumanEntity;
/**
@@ -9,10 +12,42 @@ public enum GameMode {
/**
* Creative mode may fly, build instantly, become invulnerable and create free items
*/
CREATIVE,
CREATIVE(1),
/**
* Survival mode is the "normal" gameplay type, with no special features.
*/
SURVIVAL;
SURVIVAL(0);
private final int value;
private final static Map<Integer, GameMode> modes = new HashMap<Integer, GameMode>();
private GameMode(final int value) {
this.value = value;
}
/**
* Gets the mode value associated with this GameMode
*
* @return An integer value of this gamemode
*/
public int getValue() {
return value;
}
/**
* Gets the GameMode represented by the specified value
*
* @param value Value to check
* @return Associative {@link GameMode} with the given value, or null if it doesn't exist
*/
public static GameMode getByValue(final int value) {
return modes.get(value);
}
static {
for (GameMode mode : GameMode.values()) {
modes.put(mode.getValue(), mode);
}
}
}