mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 03:43:40 +01:00
Add default SpawnpointCommand. Partially fixes BUKKIT-2671
By: EvilSeph <evilseph@gmail.com>
This commit is contained in:
parent
78183f63cf
commit
4c6c68d5fc
2 changed files with 84 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue