Added GameMode command.
This commit is contained in:
parent
742847c63f
commit
879fc912f4
@ -1,5 +1,8 @@
|
|||||||
package org.bukkit;
|
package org.bukkit;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
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 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 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ public class SimpleCommandMap implements CommandMap {
|
|||||||
fallbackCommands.add(new TellCommand());
|
fallbackCommands.add(new TellCommand());
|
||||||
fallbackCommands.add(new MeCommand());
|
fallbackCommands.add(new MeCommand());
|
||||||
fallbackCommands.add(new KillCommand());
|
fallbackCommands.add(new KillCommand());
|
||||||
|
fallbackCommands.add(new GameModeCommand());
|
||||||
fallbackCommands.add(new HelpCommand());
|
fallbackCommands.add(new HelpCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 ");
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ public class HelpCommand extends VanillaCommand {
|
|||||||
sender.sendMessage("list lists all currently connected players");
|
sender.sendMessage("list lists all currently connected players");
|
||||||
sender.sendMessage("say <message> broadcasts a message to all 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("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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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 + "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 + "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 + "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();
|
commands.recalculatePermissibles();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user