Solved HashMap not working?!

Discussion in 'Plugin Development' started by Maxx_Qc, Oct 12, 2015.

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

    Maxx_Qc

    Hi guys, I have a problem.
    Code:
    if(hm.containsKey(p)) {
                    sender.sendMessage(colorize(getConfig().getString("goodboy")));
                    String AmountA = "-" + hm.get(p);
                    economy.depositPlayer(p, Integer.valueOf(AmountA));
                    Bukkit.getLogger().info(AmountA);
                    p.removePotionEffect(PotionEffectType.SLOW);
                    hm.remove(sender);
                } else {
                    sender.sendMessage(colorize(getConfig().getString("youstupid")));
                }
    In the console, it shows -500 but the player doesn't lose the 500$.
    It simply does nothing but removing the player from the hashmap and removing the potioneffect.
    Help! :(
     
  2. Offline

    SuperSniper

    @Maxx_Qc You can't deposit a negative number to a player's balance, you need to withdraw an amount. Also, you should parse the string to make it a integer.

    So do:

    Code:
    econemy.withdrawPlayer(p, Integer.parseInt(AmountA));
    
     
  3. Offline

    Maxx_Qc

    @SuperSniper Well, when I tried economy.depositPlayer(p, -250);, it worked!
    I'll try!

    EDIT: Thank you!
    Final code:
    Code:
    if(hm.containsKey(p)) {
                    sender.sendMessage(colorize(getConfig().getString("goodboy")));
                    Integer AmountA = hm.get(p);
                    economy.withdrawPlayer(p, (double)AmountA);
                    p.removePotionEffect(PotionEffectType.SLOW);
                    hm.remove(sender);
                } else {
                    sender.sendMessage(colorize(getConfig().getString("youstupid")));
                }
     
    Last edited: Oct 12, 2015
  4. Offline

    SuperSniper

    @Maxx_Qc Please mark the thread as "Solved" if it is solved. :)
     
  5. Offline

    Maxx_Qc

Thread Status:
Not open for further replies.

Share This Page