Problems

Discussion in 'Plugin Development' started by piggykiller100, Dec 24, 2013.

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

    piggykiller100

    I need help.I am coding a plugin that will state the person who killed you when you type /sk. Its not sending the message
    Java Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    if(commandLabel.equalsIgnoreCase("sk")){
    player.sendMessage(ChatColor.BLUE + "Your killer is" + player.getKiller());
    }

    returnfalse;
     
  2. Offline

    pokuit

    are you registering the command in your plugin .yml?
    Plus check for a stack trace as if the player hasn't been killed once then it will return null
     
  3. Offline

    mattrick

    piggykiller100
    Use cmd.getName().equalsIgnoreCase("sk") instead of commandLabel.equalsIgnoreCase("sk").
     
  4. Offline

    piggykiller100

    mattrick
    thanks I will go try that

    EDIT:It Works but it says your killer is Null
     
  5. Offline

    mattrick

    piggykiller100
    Add a null check:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
    if(commandLabel.equalsIgnoreCase("sk")){
    if (player.getKiller() != null){
    player.sendMessage(ChatColor.BLUE + "Your killer is" + player.getKiller());
    }
    }
     
    returnfalse;
     
  6. Offline

    piggykiller100

    mattrick
    Thx I will try that




    EDIT: Now it dosent show anything. I put it in a seprate class . And it worked before .
     
  7. Offline

    pope_on_dope

    it's showing up null because of the null check you added. #getKiller will return null unless you use it on an event (player death event). you need to store a player's killer in a hash map when they die, and when a player type's /sk, it fetches their killer from the hash map
     
Thread Status:
Not open for further replies.

Share This Page