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

@@ -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());
}

View File

@@ -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 ");
}
}

View File

@@ -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;
}