Teleporting to Spawn

Discussion in 'Plugin Development' started by herghost, Nov 13, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    herghost

    Hi all

    How do you move player to spawn? I have tried this:

    Code:
    package me.herghost.Fiery.commands;
    
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class spawnCommand implements CommandExecutor
    
    {
    
        private Location respawnLocation;
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("spawn")&& sender instanceof Player)
            {
                Player player = (Player) sender;
                Location loc = this.respawnLocation;
                player.teleport(loc);
            }
            return false;
        }
    
    }
        
    It compiles ok but the server reports an error:

    Am I going about this the right way?

    Thanks
     
  2. Offline

    zhuowei

    You never set respawnLocation to an actual location. Try
    Code:
    player.teleport(player.getWorld().getSpawnLocation());
     
  3. Offline

    herghost

    Thanks!

    Code:
    package me.herghost.Fiery.commands;
    
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class spawnCommand implements CommandExecutor
    
    {
    
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(cmd.getName().equalsIgnoreCase("spawn")&& sender instanceof Player)
            {
                Player player = (Player) sender;
                player.teleport(player.getWorld().getSpawnLocation());
                sender.sendMessage("You have been whisked back to spawn");
            }
            return false;
        }
    
    }
    
     
  4. Offline

    ItsHarry

    Btw. You should return true if the command succeeded, otherwise you will get a message saying the usage of the command
     
  5. Offline

    herghost

    Thanks, always forget the damn thing. No to try and understand how to implement mysql :(
     
Thread Status:
Not open for further replies.

Share This Page