diff options
author | EvilSeph <evilseph@gmail.com> | 2012-10-29 03:40:09 -0400 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-10-29 05:06:04 -0400 |
commit | 2c63001a782555ece2f182d60af6eb16af435f69 (patch) | |
tree | 391fbc69403619407aed5a999daec0167c7e9b82 /src/main/java/org | |
parent | 8d77e844f7558b013b368e4dbf91e063447ce9c0 (diff) | |
download | bukkit-2c63001a782555ece2f182d60af6eb16af435f69.tar bukkit-2c63001a782555ece2f182d60af6eb16af435f69.tar.gz bukkit-2c63001a782555ece2f182d60af6eb16af435f69.tar.lz bukkit-2c63001a782555ece2f182d60af6eb16af435f69.tar.xz bukkit-2c63001a782555ece2f182d60af6eb16af435f69.zip |
Add default SpawnpointCommand. Partially fixes BUKKIT-2671
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/command/SimpleCommandMap.java | 1 | ||||
-rw-r--r-- | src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java | 83 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index 8b28d906..292f7686 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -55,6 +55,7 @@ public class SimpleCommandMap implements CommandMap { fallbackCommands.add(new SeedCommand()); fallbackCommands.add(new DifficultyCommand()); fallbackCommands.add(new WeatherCommand()); + fallbackCommands.add(new SpawnpointCommand()); } public SimpleCommandMap(final Server server) { diff --git a/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java b/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java new file mode 100644 index 00000000..0f2abfa6 --- /dev/null +++ b/src/main/java/org/bukkit/command/defaults/SpawnpointCommand.java @@ -0,0 +1,83 @@ +package org.bukkit.command.defaults; + +import com.google.common.collect.ImmutableList; +import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; + +public class SpawnpointCommand extends VanillaCommand { + + public SpawnpointCommand() { + super("spawnpoint"); + this.description = "Sets a player's spawn point"; + this.usageMessage = "/spawnpoint OR /spawnpoint <player> OR /spawnpoint <player> <x> <y> <z>"; + this.setPermission("bukkit.command.spawnpoint"); + } + + @Override + public boolean execute(CommandSender sender, String currentAlias, String[] args) { + if (!testPermission(sender)) return true; + + Player player; + + if (args.length == 0) { + if (sender instanceof Player) { + player = (Player) sender; + } else { + sender.sendMessage("Please provide a player!"); + return true; + } + } else { + player = Bukkit.getPlayerExact(args[0]); + } + + World world = player.getWorld(); + + if (args.length == 4) { + if (world != null) { + int pos = 1; + int maxPos = 30000000; + int x = getInteger(sender, args[pos++], -maxPos, maxPos); + int y = getInteger(sender, args[pos++], 0, world.getMaxHeight()); + int z = getInteger(sender, args[pos], -maxPos, maxPos); + + player.setBedSpawnLocation(new Location(world, x, y, z), true); + sender.sendMessage("Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z); + } + } else if (args.length <= 1) { + Location location = player.getLocation(); + player.setBedSpawnLocation(location, true); + sender.sendMessage("Set " + player.getDisplayName() + "'s spawnpoint to " + location.getX() + ", " + location.getY() + ", " + location.getZ()); + } else { + sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); + return false; + } + + return true; + } + + @Override + public boolean matches(String input) { + return input.equalsIgnoreCase("spawnpoint"); + } + + @Override + public List<String> tabComplete(CommandSender sender, String alias, String[] args) { + Validate.notNull(sender, "Sender cannot be null"); + Validate.notNull(args, "Arguments cannot be null"); + Validate.notNull(alias, "Alias cannot be null"); + + if (args.length == 1) { + return super.tabComplete(sender, alias, args); + } + + return ImmutableList.of(); + } +} |