Solved Teleport the Player

Discussion in 'Plugin Development' started by williamtdr, Oct 3, 2012.

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

    williamtdr

    Hello,
    I've been working on this for days and it still eludes me. I want to move the player to the spawn of the world battles when they type /tpbattleworld, then say in yellow text "You will now be teleported to the battles world. The battle will start in " green "28" yellow "seconds." It compiles without errors, but fails to run in-game. The text displays, but an error comes up and the player does not teleport. Below is my code:
    Code:
    package com.cboos.BattlesPlugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.Player;
     
    public class main extends JavaPlugin {
        @Override
            public void onEnable(){
            getLogger().info("Bringing out Rex the Test Dog...");
            getLogger().info("feeding him...");
            getLogger().info("reasurring him...");
            getLogger().info("sending Rex the Test Dog...");
            getLogger().info("Ouch...");
            getLogger().info("Buying new Rex...");
            getLogger().info("sending...");
            getLogger().info("Plugin initialization complete.");
            }
       
            @Override
            public void onDisable() {
                getLogger().info("BattlePlugin is being terminated... it hurts...");
            }
     
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(cmd.getName().equalsIgnoreCase("tpbattleworld")){ // If the player typed /tpbattleworld then do the following...
                    Player player = (Player) sender;
                    player.sendMessage(ChatColor.YELLOW + "You will now be telported to the battles world. The battle will start in " + ChatColor.DARK_GREEN + "28" + ChatColor.YELLOW + "seconds.");
                    Location location = null;
                    location.setWorld(battles);
                    location.setX(0);
                    location.setY(69);
                    location.setZ(0);
                    player.teleport(location);
                    return true;
                } //If this has happened the function will return true.
                    // If this hasn't happened the a value of false will be returned.
                return false;
            }
    }
    
     
  2. Offline

    krazytraynz

    I'm guessing that error is a NullPointerException? You should never declare a variable as null, unless you're using it to check something. Try defining location this way:
    Code:
    Location location = player.getLocation();
    
     
  3. Offline

    Jnorr44

    Location location = new Location(world, x, y, z);
    player.teleport(location);
     
  4. Offline

    williamtdr

    Thanks, but now I'm getting a "battles cannot be resolved" its the name of the world.

    Here's the output if it helps:
    Code:
     16:44:23 [INFO] tntloverlol issued server command: /tpbattleworld
    16:44:23 [SEVERE] Could not pass event PlayerTeleportEvent to Multiverse-Core
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at org.bukkit.craftbukkit.entity.CraftPlayer.teleport(CraftPlayer.java:356)
    at org.bukkit.craftbukkit.entity.CraftEntity.teleport(CraftEntity.java:162)
    at com.cboos.BattlesPlugin.main.onCommand(main.java:36)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:498)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:880)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:826)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:808)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:577)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:473)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:405)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at com.onarandombox.MultiverseCore.listeners.MVPlayerListener.playerTeleport(MVPlayerListener.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
    ... 22 more
    16:44:23 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tpbattleworld' in plugin BattlesPlugin v0.0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:498)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:880)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:826)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:808)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:577)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:473)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:405)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at org.bukkit.craftbukkit.entity.CraftPlayer.teleport(CraftPlayer.java:367)
    at org.bukkit.craftbukkit.entity.CraftEntity.teleport(CraftEntity.java:162)
    at com.cboos.BattlesPlugin.main.onCommand(main.java:36)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 15 more
    Bump. I need an answer to this soon, I don't have forever.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  5. Offline

    Loogeh

    Does the world exist? You might need to put quotations around the world name. Not sure.
     
  6. Offline

    JjPwN1

    williamtdr
    Code:
    package com.cboos.BattlesPlugin;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.Player;
     
    public class main extends JavaPlugin {
        @Override
            public void onEnable(){
            getLogger().info("Bringing out Rex the Test Dog...");
            getLogger().info("feeding him...");
            getLogger().info("reasurring him...");
            getLogger().info("sending Rex the Test Dog...");
            getLogger().info("Ouch...");
            getLogger().info("Buying new Rex...");
            getLogger().info("sending...");
            getLogger().info("Plugin initialization complete.");
            }
     
            @Override
            public void onDisable() {
                getLogger().info("BattlePlugin is being terminated... it hurts...");
            }
     
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(cmd.getName().equalsIgnoreCase("tpbattleworld")){ // If the player typed /tpbattleworld then do the following...
                    Player player = (Player) sender;
                    player.sendMessage(ChatColor.YELLOW + "You will now be telported to the battles world. The battle will start in " + ChatColor.DARK_GREEN + "28" + ChatColor.YELLOW + "seconds.");
                    player.teleport(new Location(Bukkit.getWorld("battles"), 0, 69, 0));
                    return true;
                } //If this has happened the function will return true.
                    // If this hasn't happened the a value of false will be returned.
                return false;
            }
    }
    So, instead of all those variables, we're just doing "Teleport the player to this new location in the world "battles", at the coordinates X: 0, Y: 69, and Z: 0." all in one line
     
  7. Offline

    williamtdr

    Thanks so very much! Couldn't have asked for a better answer.
     
  8. Offline

    JimsHD

    Code:java
    1. getLogger().info("Bringing out Rex the Test Dog...");
    2. getLogger().info("feeding him...");
    3. getLogger().info("reasurring him...");
    4. getLogger().info("sending Rex the Test Dog...");
    5. getLogger().info("Ouch...");
    6. getLogger().info("Buying new Rex...");
    7. getLogger().info("sending...");
    8. getLogger().info("Plugin initialization complete.");
    9. }

    Lol...
     
    tylerthecreeper1 and JPG2000 like this.
  9. Offline

    malandrix_bunny

    JimsHD
    Why are you bringing this back from the dead?
     
  10. Offline

    JPG2000

    williamtdr Omg. Could I please copy that? Thats hilarious. Im going to use it in all of my plugins xD
     
  11. Offline

    TheMintyMate

  12. Offline

    Geekhellmc

Thread Status:
Not open for further replies.

Share This Page