How to get numbers in

Discussion in 'Plugin Development' started by Ruptur, Mar 13, 2015.

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

    Ruptur

    I have a problem that i cant get over.

    Lets say i have a list of numbers with no particular pattern for example <> [3, 5, 8, 15, 18, 22]
    I have a method for retrieving the numbers and matching it to other numbers,

    For example:
    Code:
    Increasing number : List numbers
                 1
                 2
                 3                :        3
                 4             
                 5                :        5
    
                 ...
    
                 7
                 8                :         8
    
    So it basically matches a number increasing by 1 with the numbers in the list.

    My problem seems to be that is the increasing numbers
    were to exceed the max number in the list (in this case 22),
    how do i get the appropriate number in the list

    For example

    it exceeds 22
    Code:
    Increasing number : List numbers
              22   
              23   
              24   
              25                 :          3
    
    So it would 'go back' to the start of the list and start counting from there again


    Things i have tried so far:
    ( nothing worth mention)

    Any help would be appreciated, maybe im thinking about this too hard (or not at all)
    Thanks
     
  2. Offline

    1Rogue

    What's the point of all this? What are you attempting to accomplish by doing this? http://xyproblem.info/
     
    Konato_K likes this.
  3. Offline

    Ruptur

    @1Rogue
    Sorry my question is undeniably unclear

    I have a hashmap storing milestone to itemstacks.

    When a player kills, their streak increases. When their streak gets to a milestone they get the itemstacks

    But my problem is when the max number in the hashmap (the milestone) is exceeded.

    So if the max milestone was 20 and minimum was 5.
    And they get 25 streak, then they would get the itemstacks to the '5' milestone.

    So in other words after reaching the max number in the list, it goes back to the first.
    How do i this?
     
  4. Offline

    1Rogue

    So essentially once you've hit the maximum value in your map, you want to reset? I would probably have a class that manages killstreaks for me, and retrieves the killstreak by using a modulo operation of "current kills" by "max killstreak":

    Code:java
    1. public class KillStreaks {
    2.  
    3. private int max = 0;
    4. private final Map<Integer, KillStreak> streaks = new HashMap<>(); //Consider a MultiMap
    5.  
    6. public void registerKillStreak(KillStreak ks) {
    7. int kills = ks.getRequiredKills(); //Assuming a method like this exists
    8. if (kills > this.max) {
    9. this.max = kills;
    10. }
    11. this.streaks.put(kills, ks);
    12. }
    13.  
    14. public KillStreak getKillStreak(int kills) {
    15. return this.streaks.get(kills % this.max);
    16. }
    17.  
    18. }
     
Thread Status:
Not open for further replies.

Share This Page