Nooby question - Making a variable for each player

Discussion in 'Plugin Development' started by Billythekidzz, Jul 24, 2013.

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

    Billythekidzz

    So how do you make variables for each player, and isn't global? Initiating it outside the method will make the variable for everyone, not each player. However, if I initiate it in a method then it will not be able to be used in schedulers unless it's final, which I do not want. A very nooby question but could I have some answers and preferably an example too? Thanks a lot. :D
     
  2. By the time 100 different peps are one your server you used 0.99GB off your server data

    Anyways you need a build every second to keep up with minecraft.net's 1-3 buy per sec
     
  3. Offline

    Billythekidzz

    Heckya1234 (The_3_gamers)
    There are many plugins that do it and don't lag the server though. (Essentials for example) How do you do it? :O
     
  4. Offline

    ZeusAllMighty11

    Can you elaborate a bit more on your question?​
     
  5. Offline

    jdawgerj515

    It depends on how you are storing the variables:
    • Single config file with player pathways with variables
    • Individual config files for each player that hold player variables
    • Hashmaps
    All of those have different Pro's and Con's. You will have to have some form of storage though to store variables after server has been shutdown. But many people suggest storing things like that to Hashmaps so you are not constantly reading from a file.
     
  6. Offline

    chasechocolate

    I would use a HashMap:
    Code:java
    1. //Example for storing per-player scores
    2. HashMap<String, Integer> playerScores = new HashMap<String, Integer>();
    3.  
    4. //Setting score
    5. playerScores.put(player.getName(), score);
     
  7. Offline

    gomeow

    But why not make it final? I don't see why not of all you want to do is use a local variable inside a scheduler
     
  8. Offline

    Billythekidzz

    chasechocolate
    jdawgerj515
    Hashmaps are what I was looking for. How would I get the object in the Hashmap?
    E.g. If I have
    HashMap<Player, Material> map = new HashMap<Player, Material>();
    And I stored a player and material with
    map.put(event.getPlayer, materialvariable);
    How would I be able to check and get the material of materialvariable?
     
  9. Offline

    Pawnguy7

    Store the player's name (player.getName(), a String), not the player. Bad things happen otherwise. Anyway, assuming you switch to strings, it would be map.get(playername). In the current version, map.get(player).
     
  10. Offline

    jdawgerj515

    Code:
    HashMap <String player, Location location> playerHm = new HashMap<String, Location>;
    I think. Just remember to do player.getName() instead of keeping the player object it will give you something totally different.

    To get the player's location that you playerHm.put();'d, just use playerHm.get(player.getName());
     
Thread Status:
Not open for further replies.

Share This Page