Best way to make multiple values under player

Discussion in 'Plugin Development' started by Ethan, Jul 29, 2013.

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

    Ethan

    Okay, so I have a plugin that allows players to become married and under the 2 players I want to be able to store a location and a int and was wondering what the best way to do this was?

    So I want to store the spot that the players were married at and then I want to store an int for the amount of times these players have been married/divorced before, I was just curious how I would save a location and int variable under 2 players. (I have the location variable and the int already set up and working, just wondering how I would store it under the players)
     
  2. Offline

    callum2904

    HashMaps im guessing,
    HashMap<String, Location> location = new HashMap<String, Location>();
    the string being the players name and the location being...
    HashMap<String, Integer> int = new HashMap<String, Integer>();

    if you dont know how to use hashmaps i recommend either learning or not using them, dont try if you dont know because they can become confusing to new coders
     
  3. Offline

    Ethan

    I know how to use hashmaps, but that doesn't look like the most efficient way to do things; also I want to store the values under a pair of players and not just a single player.
     
  4. Offline

    callum2904

    i didnt say that it was the most efficient i was just saying that was a way to do it and you can just add both the players to it or make the first part

    HashMap<ArrayList<String>, Location> location = new HashMap<ArrayList<String>, Integer>();

    Ethan
    Make an object for your location/int and create a hashmap with the player name and the object.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 25, 2021
  5. Offline

    soulofw0lf

    yeah making a marraige object and tying both players to it would be the best way to go
     
  6. Offline

    Ethan

    xTrollxDudex
    This is a little delayed, but, when you add a object to the hashmap doesn't it just add the reference to the object? Not the actual values inside the object at that moment. Since there could me multiple of these objects running at the same time I'm not sure how I would go about figuring which object holds the correct values for the specific player.
     
  7. Offline

    xTrollxDudex

    Ethan
    You would use a key to the object, the player name to get the instance of the object, which hold the values which you made.
     
  8. Offline

    Ethan

    xTrollxDudex
    So if I have this
    Code:java
    1. //Marry being the object
    2. HashMap<String, Marry> mList = new HashMap<String, Marry>();


    How would I get the values inside that object? Since when I do this
    Code:java
    1. for(String s : mList.keySet()){
    2. if(s == player.getName()){
    3. player.sendMessage("" + mList.get(x));
    4. break;
    5. }
    6.  


    it just gives you the path of the object, how would I then use the path to get the values?
    (I just made the for loop send the player the results so I could see what it sent, in the finished product I don't actually want it to send the results of the object to the player).
     
  9. Offline

    xTrollxDudex

    Ethan
    A marry object should have getter/setters for the fields, when you reach the player name inside the HashMap, you would use the string to get the marry instance and use the getters/setters.
    PHP:
    for(String s mList.keySet()){
    if(
    == p.getName()){
    mList.get(s).//now you have the marry object, you do anything with the getters/setters
    break;
    }}
     
Thread Status:
Not open for further replies.

Share This Page