Can I use HashMaps for this?

Discussion in 'Plugin Development' started by ron975, Sep 8, 2012.

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

    ron975

    So, basically what I need to do is check how many times a player interacts with a lever, for example.

    So, I have a PlayerInteractEvent, and I want to get the existing value (number of times the player has used a lever before) and add 1 to it.
     
  2. Yes a HashMap is good for that.
    Just do
    Code:
    HashMap<String, int> counter = new HashMap<String, int>();
     
    String player = event.getPlayer().getName();
    int newValue = counter.get(player)+1;
    counter.put(player, newValue);
    pizza
     
  3. Offline

    ron975

    I get "Syntax error on token "int", Dimensions expected after this token" when copy-pasting that code in Eclipse
     
  4. Offline

    Tirelessly

    Write it out.
     
  5. Offline

    stelar7

    use Integer not int
     
Thread Status:
Not open for further replies.

Share This Page