1.15.2 per player variable

Discussion in 'Spigot Plugin Development' started by catssss, Mar 27, 2020 at 4:38 AM.

  1. how would I make a per player variable so that each player has a variable because I want to make something like hypixel skyblock mana but don't know how I would save the integer for the player.
  2. Not that I am not willing to help, but it sounds like you have little or no knowledge in what you would need to accomplish this in Java.

    You would use a very basic data structure in Java that is called Map for this.
    Since you obviously don't know what this is (or you would not ask the question), I would recommend you to read up on how some basic data structures work in Java. This will improve the quality of your future coding and will save us time answering questions related to fundamental Java knowledge :)
  3. I know what a map is IDK how to use them super well but I have used them before but IDK how I would use it for what I want I could probably figure it out and get it to work but it would be pretty bad compared to someone else's code
  4. Code (Java):
    // Create a map
    HashMap<UUID, YourType> map = new HashMap<UUID, YourType>();

    // Put values into it, using the player UUID as key and a value
    map.put(player.getUniqueId(), value);

    // Check if a value was put for the players UUID before

    // Get a value with the players UUID (returns null if not set)
    YourType value = map.get(player.getUniqueId());
    You just need to integrate it in your code properly.
  5. Thank you that actually clears up how to use a hashmap some as well
  6. This doesn't really need to be persistent because it is gonna have a max value and if somebody reloads and makes it go to max that's fine