Trying to get players from a player array list...

Discussion in 'Plugin Development' started by Creeoer, Aug 27, 2014.

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

    Creeoer

    Noob issue, how to get player objects from a player list.........

    Code:
    blic static List<Player> getUniP(){
            List<Player> list = new ArrayList();
            for (UUID id: Hunters.getHunters()){
                Player p = Bukkit.getPlayer(id);
                if (p != null){
                    list.add(p);
                }
            for (UUID id1 : Runners.getRunners()){
                Player p1 = Bukkit.getPlayer(id1);
                    if (p1 != null){
                        list.add(p1);
                    }
                }
            }
           
            return list;
     
    //Returns a Player array list from UUIDS
     
    Player p = (Player) DeathMongol.getUniP();
     
    //Can't cast a list to a player
     
  2. Offline

    SmooshCakez

    You can't cast a list to a player. Change it to List<Player> p;, remove the (Player) cast, and do p.get(0); to get the first player, p.get(1); for the second, etc.
     
  3. Offline

    Creeoer

    SmooshCakez That is specific, I want to get all the players from the list
     
  4. Offline

    Necrodoom

    Creeoer then loop though the list and apply whatever you need to each player. You cannot declare "apply method X to all objects in collection" like that.
     
  5. Offline

    ZachBora

    for a list you can do something like this :
    Code:
    for(object objectname : collection) {
    }
    
     
  6. Offline

    Creeoer

    Necrodoom I dont want to apply a method, this is rooting back to the activateGame method in the onEnable ( which you are familiar with) I need to get tthese player objects and use them for my activateGame method since they are on the team..I did that because I wanted all of the players in the list to be put into the activateGame Method. If you don't understand my point here.. I have a list of players, I need these list of players to be used in the activateGame Method since it needs player as an argument, all of these playersw will be brought to the arena spawn and given items. Sorry if this is pure ignorance at it's best, my intention isnt't to frustrate anyone here.
     
  7. Offline

    Necrodoom

    Creeoer for god damn sake, your "activeGame" method still doesn't need ANY player given, your code is nonsense, delete the whole thing and start over, not before you learn Java and think what you are doing though.
     
  8. Offline

    Creeoer

    Necrodoom As far as java, I did watch 30 of boston's tutorials , and am self-teaching at the age of 13(Of course you dont need to know that)but I guess I shoudlnt tackle array list, the code is fine , maybe it what I am trying to do with the method that isnt explained well. Well then until I leanr about list better I might as well just have the players not spawn at once, and just have them join freely.I know very well what my code does, as I know that list took my UUID list and got players from them and returened the player list. Anyways sorry about this mess of 3 threads , and the inconvicene I brought upon everoyne in this thread. As far as nonsense, the activae game metohd can be removed and players can join and leave the game freely, just not all at once. I
     
Thread Status:
Not open for further replies.

Share This Page