package net.supernoobs.SimpleSpawn;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public final class SimpleSpawn extends JavaPlugin {
	@Override
	public void onEnable() {
		
	}
	
	@Override
	public void onDisable() {
	
	}
	
	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		Player targetPlayer = null;
		//If we have a player as an argument, check if the player exists, and attempt too send them to spawn
		//otherwise, check if the sender is a player, and send them to spawn.
		if(args.length == 1)
		{
			if(sender.hasPermission("simplespawn.other"))
			{			
				targetPlayer = Bukkit.getPlayer(args[0]);
				if(targetPlayer == null)
				{
					sender.sendMessage("aPlayer was not found");
					return true;
				}
				teleportPlayerToSpawn(targetPlayer);
				return true;
			}
			else
			{
				sender.sendMessage("4You lack the permission to send another player to spawn. Try just /spawn");
			}
		}
		else
		{
			
			if(sender instanceof Player)
			{
				if(sender.hasPermission("simplespawn.self"))
				{
					targetPlayer = (Player) sender;
				}
				else
				{
					sender.sendMessage("aThis command cannot be run in the console without a valid player");
					return true;
				}
				teleportPlayerToSpawn(targetPlayer);
			}
			else
			{
				sender.sendMessage("4You lack permission");
			}
		}
		return true;
	}
	
	private void teleportPlayerToSpawn(Player player)
	{
		Location spawn = Bukkit.getWorld("world").getSpawnLocation();
		player.teleport(spawn);
		player.sendMessage("aNow teleporting you to the world's spawn!");
		player.playSound(spawn, Sound.SUCCESSFUL_HIT, 1, 1);
	}
}

@@ -1385,73 +1385,42 @@
 ge(%22
-aThis command cannot be run in the console without a valid player
+4You lack permission to use /spawn
 %22);%0D
@@ -1533,36 +1533,93 @@
 essage(%22
-4You lack permission
+aThis command can not be run via the console. Specify a player to spawn them.
 %22);%0D%0A%09%09%09

Fix error messages