Need help getting a player from a command

Discussion in 'Plugin Development' started by Rza1337, Nov 15, 2011.

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

    Rza1337

    In the plugin tutorials http://wiki.bukkit.org/Plugin_Tutorial
    It gives the code
    Code:
        if(cmd.getName().equalsIgnoreCase("KillPlayer")){
            Player player = (Player)sender;
            Player target = player.getWorld().getPlayer(args[0]);
            target.setHealth(0);
        }
        return false;
    }
    however, the part
    Code:
    Player target = player.getWorld().getPlayer(args[0]);
    returns an error. Any suggestions of what is wrong or another way of doing this? Thanks.
     
  2. Offline

    Randy Schouten

    It is capital sensitive.
    Might that be the problem?
     
  3. Offline

    NuclearW

    What error specifically is it giving you?
     
  4. Code:java
    1.  
    2. if(cmd.getName().equalsIgnoreCase("KillPlayer")){
    3. Player target = Bukkit.getServer().getPlayer(args[0]);
    4. if (target != null) {
    5. target.setHealth(0);
    6. } else {
    7. sender.sendMessage(ChatColor.RED + args[0] + " is not online!");
    8. }
    9. return true;
    10. } return false; }
    11.  

    Doesn't require the sender to be a player... And fixes the error you get
     
  5. Offline

    Rza1337

    Doesn't require the sender to be a player... And fixes the error you get[/quote]
    Thank you very much, this code works compared to the code on the tutorial. [diamond] for you :)
     
Thread Status:
Not open for further replies.

Share This Page