Solved need help

Discussion in 'Plugin Development' started by MattTheBeast, Feb 11, 2017.

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

    MattTheBeast

    ok so I'v been trying to make a on kill message with a deposit and its not giving the player money or showing the message! I need help

    And yes I did register it

    Code

    Code:
      private String p = ChatColor.DARK_RED + "" + ChatColor.BOLD + "Kill" + ChatColor.DARK_GRAY + ChatColor.BOLD + ">";
        public static Economy econ = null;
      
        @EventHandler
        public void onKill(PlayerDeathEvent e)
        {
            Player pl = e.getEntity();
            Player killer = e.getEntity().getKiller();
          
            if(killer instanceof Player)
            {
                EconomyResponse r = econ.depositPlayer(killer, 50);
                killer.sendMessage(p + ChatColor.GREEN + "You have killed" + ChatColor.DARK_GREEN + pl.getName() + ChatColor.GREEN + "and earned 50$.");
                if(r.transactionSuccess()){
                    System.out.println(p + "has killed" + killer + "and earned 50$");  
                }
            }
        }
     
    Last edited by a moderator: Feb 11, 2017
  2. Offline

    Zombie_Striker

    @MattTheBeast
    Killer can be null, and you are automatically casting it to a player when you create the killer variable. Check before you create the variable and make sure it is not null.

    Have you set up the econ instance? Currently, it is null.
     
  3. Offline

    mine-care

    A Player object will always be an instance of Player, this statement is invalid remove it and replace it with a null check as @Zombie_Striker pointed out ;)
     
  4. Offline

    MaxFireIce

    @MattTheBeast also, I'm not the best with Vault API but I would also consider checking the imports as well as the function you are using to give the player money ;).
     
  5. Offline

    MattTheBeast


    Oops forgot to flag this as solved.
    Thanks anyways! Il take it into consideration :p
     
Thread Status:
Not open for further replies.

Share This Page