[HELP] Player teleporting not working...

Discussion in 'Plugin Development' started by ItsLeoFTW, Jan 26, 2014.

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

    ItsLeoFTW

    Hey!
    I'm having yet ANOTHER problem with my plugin.
    Problem:
    Well, I'm trying to make it so when you type '/war join' you get teleported to a different world, called 'medieval'. Then, doing '/war quit' teleports you back to the main world, which is called "world". Here's my code; could anyone tell me what's wrong?
    Code:java
    1. package war.commands;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.World;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10.  
    11. /**
    12. * the base for Leo's minigame
    13. */
    14. public class WarCommand implements CommandExecutor {
    15.  
    16. @Override
    17. public boolean onCommand (CommandSender sender, Command cmnd, String alias, String[] args) {
    18. // This command can only be executed by Players
    19. if(!(sender instanceof Player)) {
    20. return false;
    21. }
    22.  
    23.  
    24. //arguments
    25. if (alias.equalsIgnoreCase("war")){
    26. if (args.length == 0){//sender only typed '/war'
    27. sender.sendMessage(ChatColor.RED + "[War] USAGE: /war <join/quit>");
    28. } else {
    29. if (args[0].equalsIgnoreCase("join")){//sender typed '/war join'
    30. Player p = (Player) sender;
    31. World w = p.getWorld();
    32. World world = Bukkit.getServer().getWorld("medieval");
    33. p.teleport(world.getSpawnLocation());
    34. sender.sendMessage(ChatColor.RED + "[War] You joined the battle!");
    35. } else {
    36. if (args[0].equalsIgnoreCase("quit")){//sender typed '/war quit'
    37. Player p = (Player) sender;
    38. sender.sendMessage(ChatColor.RED + "[War] You left the battle!");
    39. World w = p.getWorld();
    40. World world = Bukkit.getServer().getWorld("world");
    41.  
    42. }
    43. }
    44. }
    45. }
    46. return true;
    47.  
    48.  
    49. }
    50.  
    51.  
    52. }
    53.  

    And in the main class with the onEnable method...
    Code:java
    1. package war.central;
    2.  
    3. import java.util.logging.Level;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.WorldCreator;
    7. import war.commands.WarCommand;
    8. import war.scoreboard.Teams;
    9.  
    10. public class Main extends JavaPlugin {
    11. @Override
    12. public void onEnable(){
    13. getServer().getPluginManager().registerEvents(new Explosions(), this);
    14. getCommand("war").setExecutor(new WarCommand());
    15.  
    16. Bukkit.getLogger().log(Level.INFO, "Loaded battle world successfully!");
    17.  
    18.  
    19. Teams gameTeams = new Teams(this);
    20. }
    21. }
    22.  

    Please help!
     
  2. ItsLeoFTW
    Did you try teleporting them to specific coordinates?

    Code:java
    1. player.teleport(new Location(world, x, y, z, yaw, pitch));


    Also, get rid of the else statement above the quit command. It's not necessary
     
  3. Offline

    ItsLeoFTW

  4. Offline

    MOMOTHEREAL

    The Gaming Grunts
    He already has: p.teleport(world.getSpawnLocation()); which returns a location.
    ItsLeoFTW
    Any errors in the console?
     
  5. Offline

    viper_monster

    ItsLeoFTW MOMOTHEREAL he has Player.teleport(Location) for the "join" argument, but not for the "quit" argument.
     
  6. Offline

    GreySwordz

    This answer is correct. You're missing the teleport command after you get the world.
     
Thread Status:
Not open for further replies.

Share This Page