I've made a simple plugin that you can give/take/set players coins. It saves them into a config Now I don't understand why this simple method isn't working. For example, when a player types /coins it will get their amount of coins and display them. So far I'm getting this error: "Null". When a player types /coins it says [Coins]: null Code: Code:java @Overridepublic boolean onCommand(CommandSender cs, Command command, String s, String[] args) {if (command.getName().equalsIgnoreCase("coins")) {cs.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.GRAY + ": " + ChatColor.GREEN + EconManager.bal.get(cs));} Method: Code:java public static Double getBalance(String player) {return bal.get(player);} HashMap: Code:java public static HashMap<String, Double> bal = new HashMap<>();
Sabersamus Yeah there is, when a player joins the server it creates a account. Sabersamus I'm now using this line however it sending me this message "[Coins]: false"? Code: Code:java cs.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.GRAY + ": " + ChatColor.GREEN + EconManager.bal.containsKey(cs)); Anyone know how to fix this? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
You've strings as keys but you're getting a value with a player as a key? You should get the value using a string, I suppose you stored the player name.
Coopah what I meant by Map#contains was use it in an if statement.(I see it's been fixed, but for future reference) [/code] if(bal.contains(player.getName()){ //do stuff }[/code] If the players name isn't stored, and you try to use bal.get(player.getName()) its gonna have some problems