Solved Error on player.teleport(location)

Discussion in 'Plugin Development' started by broswen, Feb 18, 2015.

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

    broswen

    I am getting an error when trying to teleport the player to a predefined location.

    I call the teleportToLobby method from another method.
    Code:
    public static void teleportToLobby(Player player){
            teleportToLocation(player, CubeWars.lobby);
            resetPlayer(player);
        }
    The teleportToLobby method uses a simple teleport method.
    Code:
    public static void teleportToLocation(Player player, Location location){
         player.teleport(location);
        }
    The location i used is defined when the plugin is enabled, as shown below
    Code:
    lobbyWorld = Bukkit.getWorld(getConfig().getString("lobbyworld"));
    lobby = new Location(lobbyWorld, getConfig().getDouble("lobby.x"), getConfig().getDouble("lobby.y"), getConfig().getDouble("lobby.z"));
    Whenever i try to teleport people i get this error. What am i doing wrong?

    Error (open)

    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'cw'
    in plugin CubeWars v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got.jar:git-Spigot-bf0ac55-3fc97ff]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:646) ~[spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got.jar:git-Spigot-bf0ac55-3fc97ff]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_25]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    96) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    34) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :537) [spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftPlaye
    r.java:464) ~[spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity.teleport(CraftEntit
    y.java:223) ~[spigot.jar:git-Spigot-bf0ac55-3fc97ff]
            at com.broswen.cubewars.API.teleportToLocation(API.java:148) ~[?:?]
            at com.broswen.cubewars.API.teleportToLobby(API.java:160) ~[?:?]
            at com.broswen.cubewars.API.addToGame(API.java:36) ~[?:?]
            at com.broswen.cubewars.commands.CubeWarsCommand.onCommand(CubeWarsComma
    nd.java:49) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got.jar:git-Spigot-bf0ac55-3fc97ff]
            ... 14 more
    >


    Notes:
    line 148 is "player.teleport(location);"
    line 160 is "teleportToLocation(player, CubeWars.lobby);"
    line 36 is "teleportToLobby(player);"
     
  2. Offline

    Zombie_Striker

    Have you done some Debugging? Is there a statement that makes sure that the Config contains all those paths?
     
  3. Offline

    broswen

    Yes I have, i know those paths all exist in the config file. I also have a statement to print out an error in the console if anything is null.
     
  4. Offline

    Zombie_Striker

    Can you do a Println(); that prints for the lobbyWorld's name, and the XYZ.
     
  5. Offline

    broswen

    Ok i did some digging in the server jar to look for the source of the error. The error says its at
    Code:
    org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftPlayer.java:464)
    which is this.
    Code:
    WorldServer toWorld = ((CraftWorld)to.getWorld()).getHandle();
    And then it also says its an error at
    Code:
    org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftEntity.java:223)
    which is this
    Code:
    return teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
    so is the error because my world is null or is it something else?

    i just tried to print out these values in onEnable()
    Code:
    Bukkit.getLogger().info(lobbyWorld.getName() + ", " + lobby.getX() + ", " + lobby.getBlockY() + ", " + lobby.getZ());
    And got an NPE, so one of those are null?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  6. Offline

    Zombie_Striker

    Yes, your world then is null. Try using an if statement that checks if the world == null, else it should send a message.

    (Ignore this)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  7. Offline

    broswen

    Yep, it's null alright. But why?
    I have a world loaded thats called "hub"
    getConfig().getString("lobbyworld") is "hub"

    and then i create it by doing this
    Code:
    lobbyWorld = Bukkit.getWorld(getConfig().getString("lobbyworld"));
     
  8. Offline

    Zombie_Striker

    Has "hub" been loaded, meaning has a player been in that world? in order for a player to teleport to that world, it must have already had a player in it before. Also, try Println the config to see if it does return "hub"
     
  9. Offline

    broswen

    THAT WAS IT. I did not know a player had load the world first. I am using multiverse and i thought that would load them.

    Thanks for your help i would never have figured that out.

    Edit: ill be adding a special weapon in your honor ;)
     
  10. Offline

    Zombie_Striker

    If that was it and it now works, put Solved in the title.
     
Thread Status:
Not open for further replies.

Share This Page