Solved Putting Hashmap information into a scoreboard

Discussion in 'Plugin Development' started by SantaClawz69, Aug 13, 2016.

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

    SantaClawz69

    I'm having trouble displaying information from a hashmap into a scoreboard.

    I basically have a hashmap that is for wanted people, and if the player kills x amount of players he'll be wanted with x stars like GTA. I need the scoreboard to display the players name and how many stars they have if they are in the hashmap, does anyone know how I can do this?

    Here is what I tried to do: Score score = o.getScore((OfflinePlayer) wanted.keySet());
    I'm not sure if that's going to work.
     
  2. @SantaClawz69
    Loop through the HashMap and add them to the scoreboard?
     
  3. Offline

    Zombie_Striker

    @SantaClawz69
    Hashmap#keySet returns a Set of Entry<Key,Values>. If your hashmap has Players as keys, and ints as the value, here is what you need to do.
    1. Make a repeating task. This will update the scoreboard
    2. Inside that task, loop through all the entry in the hashmap.
    3. If the value is zero, make sure the player is not on the scoreboard and continue (you don't display them if they are not wanted)
    4. Else, get the scoreboard and add the player's name alongside how many stars they have. The score for each player will be equal to the int. If the int represents the starts (going from 0 to 5), then set the score equal to the amount of stars they have (this will order the players from 5stars at the top, 1 star at the bottom). If the int represent the kills the player has, it will rank the amount of kills a player has.
     
  4. Offline

    MCMastery

    Don't make a repeating task when you don't need to... just update the scoreboard when you update the hashmap
     
    Zombie_Striker likes this.
  5. Offline

    SantaClawz69

    Can you give me an example? I'm kind of new to scoreboards.

    A bit confused on #3 I don't know how to do that.
     
  6. Offline

    Zombie_Striker

    @SantaClawz69
    An example for @MCMastery 's post would be to update the scoreboard every time a player kills another player and when their "wanted level" goes down. (e.g. from 5 stars to 4)
     
    MCMastery likes this.
  7. Offline

    SantaClawz69

    Forget what I said, I solved this. Thanks for the help!
     
    Last edited: Aug 14, 2016
Thread Status:
Not open for further replies.

Share This Page