Checking Player balance

Discussion in 'Plugin Development' started by Takedown, Feb 8, 2015.

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

    Takedown

    Im currently making a Lottery plugin and it works great and all but Im not quite sure how to check peoples balance (using essentials eco) to make sure they have enough money to buy the ticket. If soemone could help me out that would be great! Code is below.
    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.earth2me.essentials.Essentials;
    public class lottery extends JavaPlugin{
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        Player p = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("Lottery"));
                if(args.length == 0) {
                    p.sendMessage(ChatColor.DARK_RED + "Use /Lottery Buy");
                }
                if(args.length == 1){
                  Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "eco take " + p.getName() + " 5");
                  double choice = Math.random();
                  if(choice < .5) {
                      p.sendMessage(ChatColor.RED + "Sorry but you lost! Try again!");
                  }else {
                      p.sendMessage(ChatColor.GREEN + "You won!! Enjoy your prize!");
                      Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "eco give " + p.getName() + " 100");
                      Bukkit.broadcastMessage(ChatColor.GOLD + p.getName() + ChatColor.GREEN + " has won the lotto!");
    
                  }
                }
                return false;
        }
    }
     
  2. Offline

    nj2miami

    Implement Vault, no? Are you avoiding this for some reason?

    public static Economy econ = null;

    Code:
           
    RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
           
    if (rsp != null) econ = rsp.getProvider();
    
    // I would do some Log outputs here if you fail to hook since it seems like it is required.
    
    Then simple checks would be done by referencing 'econ' like:

    econ.getBalance(PlayerName);
    econ.withdrawPlayer(PlayerName, Double) <- Double = amount to withdraw (ie: 102.0)
     
Thread Status:
Not open for further replies.

Share This Page