Command to teleport to coordinates

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

  1. Offline

    Yourleader15

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    plugin.yml

    Code:
    name: FireProtection
    version: 1
    main: me.Alex.FireProtection.Fpmain
    commands:
      tpcoord:
        description: Teleports players to specific coordinates
        usage: /tpc [x] [y] [z]
    Fpcmdexecutor class

    Code:
    package me.Alex.FireProtection;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class Fpcmdexecutor implements CommandExecutor {
    
        private final Fpmain plugin;
    
          public Fpcmdexecutor(Fpmain instance) {
            plugin = instance;
          }
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
                String[] args) {
     
            if(commandLabel.equalsIgnoreCase("tpcoord")){
    
                if ((sender instanceof Player)) {
                    Player player = (Player)sender;
                    World myworld = player.getWorld();
                    Location yourlocation = new Location(myworld, Double.parseDouble(args[0]), Double.parseDouble(args[1]), Double.parseDouble(args[2]));
                    player.teleport(yourlocation);
                    sender.sendMessage("Teleported to chosen coordinates... Maybe");
     
                 }
    
            }
         
                return false;
        }
    
    }
    
    and I also have registered the command in the main file with this...

    Code:
            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. Offline

    Taco

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Post the error you get here.
  3. Offline

    bleachisback

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    if you want to make both /tpc and /tpcoord to work, you need to do this:
    Code:
    name: FireProtection
    version: 1
    main: me.Alex.FireProtection.Fpmain
    commands:
        tpcoord:
            aliases: tpc
            description: Teleports players to specific coordinates
            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

    Yourleader15

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Taco
    "An internal error occurred when trying to perform this command" thats what I get

    @bleachisback
    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. Offline

    Taco

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I mean the error on the console, not in-game.
  6. Offline

    bleachisback

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    Yourleader15

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    17:55:17 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tpcoord' in plugin FireProtection v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:129)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:320)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:713)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:677)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:670)
    at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:85)
    at net.minecraft.server.NetworkListenThread.a(SourceFile:105)
    at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:451)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:361)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at me.Alex.FireProtection.Fpcmdexecutor.onCommand(Fpcmdexecutor.java:50)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
    ... 12 more
  8. Offline

    bleachisback

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    Yourleader15

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    don't I need to type in /tpc 1 2 3 since that was the usage I specified?
  10. Offline

    bleachisback

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    Zero9195

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

Share This Page