How to get a players arraylist??

Discussion in 'Plugin Development' started by PizzaPixel, Apr 5, 2014.

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

    PizzaPixel

    How would i get which arraylist the player is in????
     
  2. Offline

    mazentheamazin

    PizzaPixel
    arrayList.contains(player.getName())?
     
  3. Offline

    St3venAU

    Your question doesn't make much sense to me. If you have an ArrayList<Player> you can check if a player is in that list with if(yourarraylist.contains(theplayer))
     
  4. Offline

    Juicyzbox

    They are in the one you put them in. For them to get into an arraylist you have to put them there. Unless you are talking about the list of online players? In that case it is getServer().getOnlinePlayers()

    I would explain more exactly what you mean/want in order to get more detailed help.
     
  5. Offline

    JPG2000

    Assuming the ArrayList is
    Code:java
    1. ArrayList<Player> list = new ArrayList<Player>();
    2.  


    Then either loop through the list and get all the players:
    Code:java
    1. for (Player p: list) {
    2. //p is the player
    3. //do code in here
    4. }


    Or get a specific player by index:
    Code:java
    1. list.get(0); //This will return player in the position 90


    Or get the player by name (use this method below). This will return the players name, or "none" if no string matches there name
    Code:java
    1. public Player getPlayerFromList(ArrayList<Player> player, String name) {
    2. for (Player p: player) {
    3. if (p.getName().equalsIgnoreCase(name)) {
    4. return name;
    5. }
    6. }
    7. return "none";
    8. }


    BTW I haven't done bukkit in 6 months so this is assuming that everything hasn't drastically changed
     
  6. Offline

    PizzaPixel

  7. Offline

    PluginStudios

    PizzaPixel you mean which ArrayList? I believe he already showed you?
     
  8. Offline

    Juicyzbox

    You have to put them into an array list first to know which they are in. Array lists and players aren't magically and appear. You have to do it

    Like I said before. Explain more what you are trying to do and achieve
     
  9. Offline

    mazentheamazin

    PizzaPixel
    Okay, lets have two array lists
    Code:java
    1. ArrayList<String> foo = new ArrayList<String>();
    2. ArrayList<String> bar = new ArrayList<String>();

    This is what you should use to check which one the player is in:
    Code:java
    1. public ArrayList<?> whichArrayList(Player player, ArrayList<?> fo, ArrayList<?> ba) {
    2. if(fo.contains(player)) {
    3. return fo;
    4. }else if(ba.contains(player)) {
    5. return ba;
    6. }
    7. return null;
    8. }

    Then you'd call the method like this:
    Code:java
    1. whichArrayList(player, foo, bar);
     
  10. Offline

    PizzaPixel

    Juicyzbox I know i will explain you what i mean, lets say a player right clicks on a sign that adds to a arraylist.
    Bu then they click another sign that adds them to an arraylist but the plugin need to know which arraylist they joined before. so the plugin does Arraylistname.remove(p.getname) and then does arraylistname.add(p.getname) to remove them of the arraylist they were in before and add them to the new one
     
  11. Offline

    Juicyzbox

    Then you need to keep track of which sign the player has clicked. You can use metadata for storing this or another data structure. And if you really need that the signs have array lists then keep track of that too. Then after setting up the data structures get each one and handle it how you want and compare. Not sure what you are trying to achieve but maybe a sign shop or something? Either way, it looks like you know what you want now just think about it. You will learn more if you do it yourself. Just setup the data structures you need.
     
Thread Status:
Not open for further replies.

Share This Page