Command to teleport to coordinates

Discussion in 'Plugin Development' started by Yourleader15, Jul 21, 2011.

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


    Hi everyone,

    I just need to know how to make a command that will teleport the user to certain coordinates because mine isn't working


    Code (Text):
    1. name: FireProtection
    2. version: 1
    3. main: me.Alex.FireProtection.Fpmain
    4. commands:
    5.   tpcoord:
    6.     description: Teleports players to specific coordinates
    7.     usage: /tpc [x] [y] [z]
    Fpcmdexecutor class

    Code (Text):
    1. package me.Alex.FireProtection;
    2. import org.bukkit.Location;
    3. import org.bukkit.World;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandExecutor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    9. public class Fpcmdexecutor implements CommandExecutor {
    11.     private final Fpmain plugin;
    13.       public Fpcmdexecutor(Fpmain instance) {
    14.         plugin = instance;
    15.       }
    17.     @Override
    18.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
    19.             String[] args) {
    21.         if(commandLabel.equalsIgnoreCase("tpcoord")){
    23.             if ((sender instanceof Player)) {
    24.                 Player player = (Player)sender;
    25.                 World myworld = player.getWorld();
    26.                 Location yourlocation = new Location(myworld, Double.parseDouble(args[0]), Double.parseDouble(args[1]), Double.parseDouble(args[2]));
    27.                 player.teleport(yourlocation);
    28.                 sender.sendMessage("Teleported to chosen coordinates... Maybe");
    30.              }
    32.         }
    34.             return false;
    35.     }
    37. }
    and I also have registered the command in the main file with this...

    Code (Text):
    1.         getCommand("tpcoord").setExecutor(new Fpcmdexecutor(this));
    in the onEnable() method.

    When I type /tpc nothing happens.

    If I type /tpcoord it says there was an internal error or something
  2. Post the error you get here.
  3. if you want to make both /tpc and /tpcoord to work, you need to do this:
    Code (Text):
    2. name: FireProtection
    3. version: 1
    4. main: me.Alex.FireProtection.Fpmain
    5. commands:
    6.     tpcoord:
    7.         aliases: tpc
    8.         description: Teleports players to specific coordinates
    9.         usage: /tpc [x] [y] [z]

    You also have to check if args.length>2

    And just to make sure, may you post the error that's in the console?
  4. Offline


    "An internal error occurred when trying to perform this command" thats what I get

    I added the aliases thing haven't tried it out yet, also don't you mean check if the length is equal to 2 so we can make sure that the user passed 3 arguments?
  5. I mean the error on the console, not in-game.
  6. In that case, you want to check for it being less than 3, because how you have it, if the length were 1 it would still work and then give you the error
    And we need it in the server console, not in-game
  7. Offline


    17:55:17 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tpcoord' in plugin FireProtection v1
    at org.bukkit.command.PluginCommand.execute(
    at org.bukkit.command.SimpleCommandMap.dispatch(
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(
    at net.minecraft.server.NetServerHandler.handleCommand(
    at net.minecraft.server.NetServerHandler.a(
    at net.minecraft.server.Packet3Chat.a(
    at net.minecraft.server.NetworkManager.b(
    at net.minecraft.server.NetServerHandler.a(
    at net.minecraft.server.NetworkListenThread.a(SourceFile:105)
    at net.minecraft.server.MinecraftServer.h(
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at me.Alex.FireProtection.Fpcmdexecutor.onCommand(
    at org.bukkit.command.PluginCommand.execute(
    ... 12 more
  8. yeah, you need to make it only execute when args.length>2
    and then you need to make sure that you actually type in /tpcoords 1 2 3 and not just /tpcoords
  9. Offline


    don't I need to type in /tpc 1 2 3 since that was the usage I specified?
  10. I'm not entirely sure that bukkit takes usage that far, but if it does, that isn't true because you used square brackets instead of greater than and less than
  11. Offline


    If you just want a plugin which teleports you to coordinates, you can use mine ;)
    Else, do what the others said. I have no Idea what else could be wrong
Thread Status:
Not open for further replies.

Share This Page