Math and hashmaps!

Discussion in 'Plugin Development' started by Miniwarbos, Apr 15, 2014.

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

    Miniwarbos

    Hello. I want to detect a value on a player in a hashmap (sorry if i have bad terminology).
    I need to detect whether a value is more than something, but less than another value.
    In normal maths, it would look like this:

    n<10
    10<=n< 30
    30<=n< 50
    50<=n< 100
    100<n

    And here is my code:
    Code:
                public void run() {
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        UUID player = p.getUniqueId();
                        if (map.get(player).{SOMETHING}()) {
                           
     
                        }
                    }
     
                    update();
                }

    How can I do this? Sorry its a really vague question but I'm new. I also need to add that the value map.get(player) is long. Thanks!
     
  2. Offline

    Asgernohns

    Miniwarbos map.get(Key) returns your value so you should use it Like you would with an integer
     
  3. Offline

    Miniwarbos

    Asgernohns I don't understand how i would do the math operations as well.
    What would it be?

    sorry for kinda asking for code, but i dont know where to start. How does 10<=n< 30 translate into that.

    if (map.get(player).{SOMETHING}()) {
     
  4. Offline

    Asgernohns

  5. Offline

    Ad237

    Miniwarbos
    Code:java
    1. int value = map.get(player);
    2. if(value >= 10 && value < 30) {
    3. //Do something
    4. }
     
  6. Offline

    Miniwarbos

    Asgernohns
    That, N is the value. its algirba
    Thanks!

    Ad237
    so since map.get(player) is long, do i need to do
    int value = map.get(player).intValue();

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

  7. No, just do this:
    Code:java
    1.  
    2. long value = map.get(player);
    3. if(value >=10L && value <30 L)
    4. {
    5. //Do something
    6. }
    7.  


    Java needs an "L" behind Longs, so it will handle it as Longs. (And all math-Operations can be used on int,long,double etc.)
     
  8. Offline

    Miniwarbos

Thread Status:
Not open for further replies.

Share This Page