Solved Storing a username associated to a int

Discussion in 'Spigot Plugin Development' started by ckamps2020, May 15, 2016.

  1. Hello there! I'm quite curious as to what the best method would be to store a username associated to a number would be? I'm making a lottery plugin, so they right click the villager, open the menu, watch the animation, then boom. But I ran into the issue of what if they have more then one ticket? I can't just use a simple array for it.

    If you could maybe link me where I could learn how to do this, or show me and example of what method to use, that would be wonderful. Please don't spoon feed me as I want to learn this myself.

  2. What does the number represent?
  3. SQLite or YAML would probably be the easiest.
  4. Don't answer if you have no idea about what the answer is.
    • Agree Agree x 1
  5. Code (Text):
    private ArrayList<Double> test = new ArrayList();
    I could store it like this, but when I'm trying to get both the username and the int. Is there an array to do both at the same time?

    I am storing the amount of "tickets" someone has with their username

    How would I go about using these to store the data?
  6. HashMaps are there for this.

    Code (Java):
    Map<UUID, double> = new HashMap<>();
    Or if you'd like them to have more tickets, you'd need to create a double array or a double List.
  7. you could mess about with it, and maybe see if you can have "if(this.contains)
  8. Try
    Code (Java):
    HashMap<Double, String> map = new HashMap<>();
    If you have their lottery number, you can get the associated player's name by doing map.get(number);
    To add a number do map.put(number, player.getName());
  9. Thank you!

    Thank you!
    • Friendly Friendly x 1
  10. Another tip forwards:
    Google searches.
    Search up your problem but add "" at the end. You won't regret.
    • Like Like x 1