Plugin Help Adding two integers together.

Discussion in 'Plugin Help/Development/Requests' started by HCMatt, Apr 4, 2015.

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

    HCMatt

    I am making a balance plugin that saves a players money into a config file. I have a /cash command that shows the player their balance, a /setcash command that sets the players balance and a /addcash command that adds to the players balance. The /cash and /setcash commands work perfectly. However, when i try to add to the players balance it wont work. Here is what i have for my /addcash command:
    Code:
    } else if (cmd.getName().equalsIgnoreCase("addcash")) {
                if (!(sender instanceof Player)) {
                    sender.sendMessage(tag + ChatColor.RED + "You must be a player!");
                    return true;
                } else {
                    Player p = (Player) sender;
                    if (args.length == 0) {
                        sender.sendMessage(tag + ChatColor.RED + " Usage: /addcash <amount>");
                        return true;
                    } else {
                        String amount = args[0];
                        if (args.length == 1) {
                            String bal = getConfig().getString("Balance." + p.getName());
                            if (isInt(amount)) {
                                int num = Integer.parseInt(amount);
                                getConfig().set(bal, bal+num);
                                saveConfig();
                                p.sendMessage(ChatColor.DARK_AQUA + "You added" + ChatColor.AQUA + " $" + num + ChatColor.DARK_AQUA + " to your balance.");
                                return true;
                            }else if (isDouble(amount)) {
                                double num = Double.parseDouble(amount);
                                getConfig().set(bal, bal+num);
                                saveConfig();
                                p.sendMessage(ChatColor.DARK_AQUA + "You added" + ChatColor.AQUA + " $" + num + ChatColor.DARK_AQUA + " to your balance.");
                                return true;                       
                            }else {
                                p.sendMessage(tag + ChatColor.RED + " '" + amount + "' is not a number.");
                                return true;
                            }
                        }else {
                            p.sendMessage(tag + ChatColor.RED + " Usage: /addcash <amount>");
                            return true;
                        }
                    }
                }
            }
    Am i trying to add the numbers together wrong? I need help with this asap please.
    Thanks

    Matty
     
  2. Offline

    schwabfl

    You're trying to add a string and an int together
    bal is a String and num is an int
    instead of using getConfig.getString(), use getConfig.getInt() for bal, also change bal to an int
     
Thread Status:
Not open for further replies.

Share This Page