Economy

Discussion in 'Spigot Plugin Development' started by ryu, Jun 11, 2016.

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

    ryu

    Hello, So I was wondering if anyone know how I would be able to fix this problem on plugin. I am trying to make a bank note plugin everything seems to be working except when I try to withdraw cents onto a note for example $1.50 and so on. I was wondering if anyone would be able help me out with this.
    Code (Text):
    package dev.ryujix.withdraw.Commands;

    import java.text.DecimalFormat;
    import java.util.Arrays;

    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;

    import dev.ryujix.withdraw.WithdrawAdvanced;

    public class MoneyWithdraw
    implements CommandExecutor
    {
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player)sender;
                if (args.length == 1) {
                    try {
                    DecimalFormat df = new DecimalFormat("#,###.##");
                    double amount = Integer.parseInt(args[0]);
                    double balance = WithdrawAdvanced.econ.getBalance(player.getName());
                        if (amount < 1) {
                            for(String WithdrawLess : WithdrawAdvanced.plugin.getConfig().getStringList("Messages.Withdraw Less")){
                                WithdrawLess = WithdrawLess.replaceAll("&", "§");
                               
                                player.sendMessage(WithdrawLess);
                                }
                            return true;
                        } else if (balance - amount < 0) {
                            for(String WithdrawNotEnough : WithdrawAdvanced.plugin.getConfig().getStringList("Messages.Withdraw Not Enough")){
                                WithdrawNotEnough = WithdrawNotEnough.replaceAll("&", "§");
                               
                                player.sendMessage(WithdrawNotEnough);
                                }
                            return true;
                        }
                    } catch(NumberFormatException e) {
                        for(String WithdrawNumber : WithdrawAdvanced.plugin.getConfig().getStringList("Messages.Withdraw Not a number")){
                            WithdrawNumber = WithdrawNumber.replaceAll("&", "§");
                           
                            player.sendMessage(WithdrawNumber);
                            }
                        return true;
                        }
                    DecimalFormat df = new DecimalFormat("#,###.##");
                   
                    double amount = Integer.parseInt(args[0]);
                   
                    WithdrawAdvanced.econ.withdrawPlayer(player.getName(), amount);
                    for(String WithdrawRemove : WithdrawAdvanced.plugin.getConfig().getStringList("Messages.Withdraw Remove")){
                        WithdrawRemove = WithdrawRemove.replaceAll("&", "§");
                        WithdrawRemove = WithdrawRemove.replaceAll("%amount%", df.format(amount));
                        player.sendMessage(WithdrawRemove);
                    }
                        ItemStack note = new ItemStack(Material.PAPER, 1);
                        ItemMeta meta = note.getItemMeta();
                        meta.setDisplayName("§b§lBank Note§7 (Right Click)");
                        meta.setLore(Arrays.asList(new String[]{
                                "§dValue§f $" + df.format(amount),
                                "§dSigner§7 " + player.getName()}));
                        note.setItemMeta(meta);
                        player.getInventory().addItem(note);
                       
                        return true;
                    }
                    else {
                        for(String WithdrawHelp : WithdrawAdvanced.plugin.getConfig().getStringList("Messages.Withdraw Help")){
                            WithdrawHelp = WithdrawHelp.replaceAll("&", "§");
                           
                            player.sendMessage(WithdrawHelp);
                        }
                }
            return true;
        }
    }
     
  2. if you want to withdraw money:

    Code (Text):
                Double moneyy = econ.getBalance(player);
                if (moneyy >= 500.00){
                    econ.withdrawPlayer(player, 500.00);
     
  3. ryu

    ryu

    As I've said it withdraws money and everything correctly my only issue is it won't allow me to with draw cents at all.
     
  4. maybe you didn't setup your economy well.
     
  5. Maybe it does not support doubles?
     
Thread Status:
Not open for further replies.