Get the player using a command

Discussion in 'Plugin Development' started by lilkoopa, Jul 3, 2011.

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

    lilkoopa

    How would I be able to get the player who is using a command? Because with CommandSender I can't get the location or blocks and whatnot.
     
  2. Offline

    Haias

    Have you tried this?

    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
    Player player = (Player) sender;
    return true;
    }
    
    I'm pretty sure that would work, but I'm just a beginner, so you can't be too sure. Try it out, though.
     
  3. Offline

    lilkoopa

    Ha, thank you but I was able to figure it out before you replied. And it works just fine.
     
  4. Offline

    Everdras

    It does indeed work. Player is a child of CommandSender (i.e. Player extends CommandSender). So, in this case, we can assume the command sender is a Player, so the cast is safe to make.
     
Thread Status:
Not open for further replies.

Share This Page