summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/GameMode.java41
-rw-r--r--src/main/java/org/bukkit/command/SimpleCommandMap.java1
-rw-r--r--src/main/java/org/bukkit/command/defaults/GameModeCommand.java59
-rw-r--r--src/main/java/org/bukkit/command/defaults/HelpCommand.java1
-rw-r--r--src/main/java/org/bukkit/util/permissions/CommandPermissions.java1
5 files changed, 100 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/GameMode.java b/src/main/java/org/bukkit/GameMode.java
index 173acf8a..2c516750 100644
--- a/src/main/java/org/bukkit/GameMode.java
+++ b/src/main/java/org/bukkit/GameMode.java
@@ -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);
+ }
+ }
}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index 2abd87e5..0e88405f 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -38,6 +38,7 @@ public class SimpleCommandMap implements CommandMap {
fallbackCommands.add(new TellCommand());
fallbackCommands.add(new MeCommand());
fallbackCommands.add(new KillCommand());
+ fallbackCommands.add(new GameModeCommand());
fallbackCommands.add(new HelpCommand());
}
diff --git a/src/main/java/org/bukkit/command/defaults/GameModeCommand.java b/src/main/java/org/bukkit/command/defaults/GameModeCommand.java
new file mode 100644
index 00000000..9962dc6a
--- /dev/null
+++ b/src/main/java/org/bukkit/command/defaults/GameModeCommand.java
@@ -0,0 +1,59 @@
+package org.bukkit.command.defaults;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.GameMode;
+
+public class GameModeCommand extends VanillaCommand {
+ public GameModeCommand() {
+ super("gamemode");
+ this.description = "Changes the player to a specific game mode";
+ this.usageMessage = "/gamemode <player> <gamemode>";
+ this.setPermission("bukkit.command.gamemode");
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
+ if (!testPermission(sender)) return true;
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
+ return false;
+ }
+
+ Player player = Bukkit.getPlayerExact(args[0]);
+
+ if (player != null) {
+ int value = -1;
+
+ try {
+ value = Integer.parseInt(args[1]);
+ } catch (NumberFormatException ex) {}
+
+ GameMode mode = GameMode.getByValue(value);
+
+ if (mode != null) {
+ if (mode != player.getGameMode()) {
+ Command.broadcastCommandMessage(sender, "Setting " + player.getName() + " to game mode " + mode.getValue());
+
+ player.setGameMode(mode);
+ } else {
+ sender.sendMessage(player.getName() + " already has game mode" + mode.getValue());
+ }
+ } else {
+ sender.sendMessage("There is no game mode with id " + args[1]);
+ }
+ } else {
+ sender.sendMessage("Can't find user " + args[0]);
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean matches(String input) {
+ return input.startsWith("gamemode ");
+ }
+}
diff --git a/src/main/java/org/bukkit/command/defaults/HelpCommand.java b/src/main/java/org/bukkit/command/defaults/HelpCommand.java
index 7fd39934..42b3579e 100644
--- a/src/main/java/org/bukkit/command/defaults/HelpCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/HelpCommand.java
@@ -32,6 +32,7 @@ public class HelpCommand extends VanillaCommand {
sender.sendMessage("list lists all currently connected players");
sender.sendMessage("say <message> broadcasts a message to all players");
sender.sendMessage("time <add|set> <amount> adds to or sets the world time (0-24000)");
+ sender.sendMessage("gamemode <player> <mode> sets player\'s game mode (0 or 1)");
return true;
}
diff --git a/src/main/java/org/bukkit/util/permissions/CommandPermissions.java b/src/main/java/org/bukkit/util/permissions/CommandPermissions.java
index ab835553..82537577 100644
--- a/src/main/java/org/bukkit/util/permissions/CommandPermissions.java
+++ b/src/main/java/org/bukkit/util/permissions/CommandPermissions.java
@@ -103,6 +103,7 @@ public final class CommandPermissions {
DefaultPermissions.registerPermission(PREFIX + "plugins", "Allows the user to view the list of plugins running on this server", PermissionDefault.TRUE, commands);
DefaultPermissions.registerPermission(PREFIX + "reload", "Allows the user to reload the server settings", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(PREFIX + "version", "Allows the user to view the version of the server", PermissionDefault.TRUE, commands);
+ DefaultPermissions.registerPermission(PREFIX + "gamemode", "Allows the user to change the gamemode of another player", PermissionDefault.TRUE, commands);
commands.recalculatePermissibles();