Solved econ.depositplayer(); is deprecated

Discussion in 'Plugin Development' started by JaySN, Oct 20, 2017.

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

    JaySN

    So I implemented Vault in my plugin because when my players kill a player, they killer will get some money. I have used the econ.depositplayer(); and I noticed its deprecated. From my past experience, when I see that, I quickly think of a try and catch method to fix it.
    So I came here to to say if I have done it right or not.
    If no, could you please care to correct me.
    Code:
    @EventHandler
         public void killcounter(PlayerDeathEvent event) {
            Player p = event.getEntity();
            if(p.isDead()) {
                 p.getKiller();
                 if (p.getKiller() instanceof Player) {
    
                     try {
    
                         econ.bankDeposit(p.getName(), 10);
    
                     } catch(NoSuchMethodError e){
    
                         econ.depositPlayer(p.getName(), 10);
    
                     }
                    
                     p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&e&lMaze&6&lRunner&8&l>>&eYou've killed&f ") + p.getName() + " &e!. You are rewarded &610 coins&e!");
                }
             }
         }
     
  2. Offline

    Zombie_Striker

    @JaySN
    The reason it is deprecated is because they (the creators of vault) want you to provide an OfflinePlayer instance instead of a string. Remove getName and just provide the player's instance.
     
  3. Offline

    catman2014_

    Surrounding a deprecated message with a try, catch statement isn't always going to help.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @catman2014_ The try catch is to provide compatibility to plugins that don't offer bank support.
     
  5. Offline

    JaySN

    - Issue solved
    Also @catman2014_ , like timtower said, its so that no errors will occur when there is a compatibility issue.
     
Thread Status:
Not open for further replies.

Share This Page