Multiverse-Core/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java

92 lines
3.9 KiB
Java
Raw Normal View History

/******************************************************************************
* Multiverse 2 Copyright (c) the Multiverse Team 2011. *
* Multiverse 2 is licensed under the BSD License. *
* For more information please check the README.md file included *
* with this project. *
******************************************************************************/
2011-07-20 16:48:46 +02:00
package com.onarandombox.MultiverseCore.commands;
2011-09-17 17:59:38 +02:00
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.utils.PlayerFinder;
2011-07-20 16:48:46 +02:00
import org.bukkit.ChatColor;
import org.bukkit.Location;
2011-07-20 16:48:46 +02:00
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2011-07-27 00:58:20 +02:00
import org.bukkit.permissions.Permission;
2011-07-20 16:48:46 +02:00
import org.bukkit.permissions.PermissionDefault;
2011-09-17 17:59:38 +02:00
import java.util.List;
2011-07-20 16:48:46 +02:00
/**
* Teleports a player to the spawn.
*/
2011-07-20 16:48:46 +02:00
public class SpawnCommand extends MultiverseCommand {
public SpawnCommand(MultiverseCore plugin) {
super(plugin);
Permission otherPerm = new Permission("multiverse.core.spawn.other",
"Teleports another player to the spawn of the world they are in.", PermissionDefault.OP);
2011-07-20 16:48:46 +02:00
this.setName("Spawn");
2011-07-30 08:53:55 +02:00
this.setCommandUsage("/mv spawn" + ChatColor.GOLD + " [PLAYER]");
2011-07-20 16:48:46 +02:00
this.setArgRange(0, 1);
this.addKey("mvspawn");
this.addKey("mv spawn");
this.addKey("mvs");
2011-07-27 00:58:20 +02:00
this.setPermission("multiverse.core.spawn.self", "Teleports you to the Spawn Point of the world you are in.", PermissionDefault.OP);
this.addAdditonalPermission(otherPerm);
2011-07-20 16:48:46 +02:00
}
@Override
public void runCommand(CommandSender sender, List<String> args) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
}
// If a persons name was passed in, you must be A. the console, or B have permissions
if (args.size() == 1) {
2011-10-08 18:14:52 +02:00
if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.other", true)) {
2011-07-27 02:47:33 +02:00
sender.sendMessage("You don't have permission to teleport another player to spawn. (multiverse.core.spawn.other)");
2011-07-20 16:48:46 +02:00
return;
}
Player target = PlayerFinder.get(args.get(0), sender);
2011-07-20 16:48:46 +02:00
if (target != null) {
target.sendMessage("Teleporting to this world's spawn...");
spawnAccurately(target);
2011-07-20 16:48:46 +02:00
if (player != null) {
target.sendMessage("You were teleported by: " + ChatColor.YELLOW + player.getName());
} else {
target.sendMessage("You were teleported by: " + ChatColor.LIGHT_PURPLE + "the console");
}
} else {
sender.sendMessage(args.get(0) + " is not logged on right now!");
}
} else {
2011-10-08 18:14:52 +02:00
if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.self", true)) {
2011-07-27 02:47:33 +02:00
sender.sendMessage("You don't have permission to teleport yourself to spawn. (multiverse.core.spawn.self)");
2011-07-20 16:48:46 +02:00
return;
}
if (player != null) {
player.sendMessage("Teleporting to this world's spawn...");
spawnAccurately(player);
2011-07-20 16:48:46 +02:00
} else {
sender.sendMessage("From the console, you must provide a PLAYER.");
}
}
}
private void spawnAccurately(Player player) {
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld().getName());
Location spawnLocation;
if (world != null) {
spawnLocation = world.getSpawnLocation();
} else {
spawnLocation = player.getWorld().getSpawnLocation();
}
this.plugin.getSafeTTeleporter().safelyTeleport(player, player, spawnLocation, false);
}
2011-07-20 16:48:46 +02:00
}