Solved Coins

Discussion in 'Plugin Development' started by Coopah, Jun 27, 2014.

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

    Coopah

    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
    1. @Override
    2. public boolean onCommand(CommandSender cs, Command command, String s, String[] args) {
    3. if (command.getName().equalsIgnoreCase("coins")) {
    4. cs.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.GRAY + ": " + ChatColor.GREEN + EconManager.bal.get(cs));
    5. }

    Method:
    Code:java
    1. public static Double getBalance(String player) {
    2. return bal.get(player);
    3. }

    HashMap:
    Code:java
    1. public static HashMap<String, Double> bal = new HashMap<>();
    2.  
     
  2. Offline

    Sabersamus

    Make sure there is actually a stored key and value for the player?

    Map#contains() ?
     
  3. Offline

    Coopah

    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
    1. cs.sendMessage(ChatColor.RED + "[Coins]" + ChatColor.GRAY + ": " + ChatColor.GREEN + EconManager.bal.containsKey(cs));
    2.  

    Anyone know how to fix this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    SuppaTim

    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.
     
  5. Offline

    Coopah

    SuppaTim
    How would I do this? Do I need to make a new string?
     
  6. Offline

    SuppaTim

    bal.get(player.getName());?
     
  7. Offline

    Coopah

    SuppaTim
    Awhh, I'm so silly :3 I forgot to add the getName.
    Thanks man.
     
  8. Offline

    Sabersamus

    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
     
Thread Status:
Not open for further replies.

Share This Page