Teleport Command Not Working

Discussion in 'Plugin Development' started by krazytraynz, Sep 27, 2012.

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

    krazytraynz

    I've written a command, that in theory, should send players to different worlds/areas based on what the player types. However, whenever I try the command, it always returns false.

    Code: http://pastebin.com/AZauk7VP
     
  2. Offline

    gregthegeek

    Are the config values that are being used set correctly? And did you set the CommandExecutor of the command to the one yours?
     
  3. Offline

    krazytraynz

    The config values are set correctly, and if by setting the CommandExecutor you mean doing this:
    Code:
    banish = new BanishExecutor(this);
    getCommand("banish").setExecutor(banish);
    
    then I did that too.
     
  4. Offline

    krazytraynz

  5. Offline

    JayzaSapphire

    If you've registered your executor then there is no need to check for a command in the executor class, have you registered the command in your plugin.yml?
     
  6. Offline

    MrFigg

    The way you're testing which area to send them to is wrong. Instead of
    Code:
    area == ("void")
    use
    Code:
    area.equalsIgnoreCase("void")
     
  7. Offline

    krazytraynz

    Yes, the command is registered, and I double checked to make sure it was registered correctly.

    I changed it to that, I should've thought of it earlier... The command always returns false as well, I should've included it in the main topic.
     
  8. Offline

    MrFigg

    Hmm, your onCommand declaration doesn't seem to be written correctly. You have String args[] instead of String[] args. And if that doesn't work, it's hard to tell which return falseis being triggered without more debug messages. I've rewritten your class with more debug messages as well as cleaning it up a bit. Try it out and see what happens.
    Code:
    public class BanishExecutor implements CommandExecutor {
        private KrazyBukkit krazy;
       
        public BanishExecutor(KrazyBukkit krazy) {
            this.krazy = krazy;
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("banish") {
                if(args.length>2) {
                    sender.sendMessage("Too many arguments!");
                    return false;
                }
               
                if(args.length<1) {
                    sender.sendMessage("Who do you want to banish??");
                    return false;
                }
                Player banishPlayer = Bukkit.getServer().getPlayer(args[0]);
                if(banishPlayer == null) {
                    sender.sendMessage(ChatColor.RED + args[0] + " is not online, but I'm sure you'll get them next time!");
                    return false;
                }
               
                if(args.length<2) {
                    sender.sendMessage("You need to specify a place to banish them! (Nether, End, or Void)");
                    return false;
                }
                String worldName = null;
                Stirng worldDisplay = null;
                if(args[1].equalsIgnoreCase("void")) {
                    worldName = krazy.getConfig().getString("Banish.WorldName.Normal");
                    worldDisplay = "the Void";
                } else if(args[1].equalsIgnoreCase("nether")) {
                    worldName = krazy.getConfig().getString("Banish.WorldName.Nether");
                    worldDisplay = "the Nether";
                } else if(args[1].equalsIgnoreCase("end")) {
                    worldName = krazy.getConfig().getString("Banish.WorldName.End");
                    worldDisplay = "the End";
                } else {
                    sender.sendMessage("Invalid world name! Nether, End, or Void");
                    return false;
                }
               
                World world = Bukkit.getServer().getWorld(worldName);
                if(world==null) {
                    sender.sendMessage("Selected world was not found on this server!");
                    return false;
                }
               
                Location banishLocation = world.getSpawnLocation();
                if(args[1].equalsIgnoreCase("void")) {
                    banishLocation = new Location(world, banishPlayer.getLocation().getBlockX(), 0.0, banishPlayer.getLocation().getBlockZ());
                }
               
                sender.sendMessage(banishPlayer.getName() + " has been banished to " + worldDisplay + "!");
                banishPlayer.sendMessage("You have been banished to " + worldDisplay + "!");
                return banishPlayer.teleport(banishLocation);
            }
            sender.sendMessage("Command not recognized.");
            return false;
        }
    }
     
  9. Offline

    CorrieKay

    MrFigg technically it doesnt really matter. Though, String[] args looks nicer, it can technically still be String args[]
     
  10. Offline

    MrFigg

    CorrieKay Really? Huh, learn something new every day.
     
  11. Offline

    krazytraynz

    MrFigg
    Actually, I added some debug messages to the
    Code:
    if(World__ == null)
    and now the command works. I must've done something else, because there's no way that could have been the problem... Could it?
     
  12. Offline

    MrFigg

    Just adding debug messages rarely fixes anything itself, so you probably did do something else while changing your code. But anyway, it works now. If you posted your new code I might be able to tell what's different, but that's up to you if you're really curious.
     
  13. Offline

    krazytraynz

    I am, actually :p Here it is: http://pastebin.com/VWUkUBg3
     
Thread Status:
Not open for further replies.

Share This Page