Ok so i have a coins.yml file that keeps track of all my players coins. Now i have a command somthing like /coinsadd [playername] [amount] it works perfectly fine. Now i have a command like /coinstake [playername] [amount] And if i do the command and i put the 10 for the ammount it makes the coins negative. So say that i had 10010 coins. and i try to take 10 coins away it make the amount -10000 It takes the 10 coins away but for some reason it makes the coins negitive. here is the command Code: if (cmd.getName().equalsIgnoreCase("coinstake")) { if (p.hasPermission("coins.coinsatake")) { if (args.length > 2) { p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " /coinstake [player] [amount]"); return true; } if (args.length == 0) { p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " /coinstake [player] [amount]"); return true; } if (args.length == 1) { p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " /coinstake [player] [amount]"); return true; } if (args.length == 2) { String a = (String)config.get(args[0]); if (a == null) p.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.YELLOW + " That player does not exist"); else config.load(configFile); int coinns = Integer.parseInt(args[1]) - Integer.parseInt((String)config.get(args[0])); config.set(args[0], String.valueOf(coinns)); config.save(configFile); p.sendMessage(ChatColor.RED + "[Coins]" + "I think you have had coins taken but idk ;)"); return true; } } Help?
int coinns = Integer.parseInt(args[1]) - Integer.parseInt((String)config.get(args[0])); Should be the other way around.
Craftiii4 Like this? int coinns = Integer.parseInt((String)config.get(args[0]) - Integer.parseInt(args[1])); If i do that it says its undefinable String, int
Go Hard You have to use an else if statement when you distinguish between the different amount of arguments. Code: if(args.length == 0){ } else if(args.length == 1){ } So on and so on...
BajanAmerican No you don't? I would never do that as well, just makes it look messy. Go Hard The reason why it is failing at the moment is because you are getting the amount they want, then taking away the amount in the config. For example, say in the config file I ave 50, and you use /coinstake Craftiii4 10 It will do 10 - 50 Which will equal -40, instead you want to do 50-10 to get 40. So use this: Code:java int coinns = Integer.parseInt((String)config.get(args[0])) - Integer.parseInt(args[1]);