Solved How to get Players from an Array List

Discussion in 'Plugin Development' started by SomewhatEvil, Mar 4, 2014.

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

    SomewhatEvil

    Hello, I'm trying to get players from an array-list to give them all items upon joining an arena, this would also involve using a for loop with each player needed to be equipped, unfortunately I'm not to sure how to do that, so how exactly should I make it so that i can get all the players from my minigame to get items as soon as the game starts. I'm not sure if there's a simpler way, but if there is please show me how. Thanks in advance and any help would be much appreciated! (Btw I already have the arraylist with the players in it)

    Heres the code:
    Code:java
    1. public void PlayerEquip() {
    2. Player p = ???;
    3. p.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 3));
    4. p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100000, 3));
    5. p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100000, 2));
    6. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100000, 1));
    7. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100000, 1));
    8. }
     
  2. Offline

    Minesuchtiiii

    public void playerEquip(Player p) {
    //rest
    }
     
  3. Offline

    Maulss

    Code:java
    1. // Contains the names of the players. (Not player objects)
    2. public List<String> players = new ArrayList<>();
    3.  
    4. public void playerEquip() {
    5. for (String name : this.players) {
    6. Player player = Bukkit.getPlayer(name);
    7. // Do stuff to player.
    8. }
    9. }
     
  4. Offline

    Minecrafter_NL

    Use this code:

    public void playerEquip(ArrayList<Player> players){
    for(Player p : players){
    ////you can do anything with player p here
    }
    }
     
  5. Offline

    SomewhatEvil

    Minecrafter_NL your method worked nicely, thanks everyone for your help! I'll test the plugin now to make sure it worked.

    FINAL EDIT: I didn't initialize the ArrayList in the main method.
     
Thread Status:
Not open for further replies.

Share This Page