Solved ArrayList help

Discussion in 'Plugin Development' started by lewysryan, Feb 21, 2014.

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

    lewysryan

    ok so I am storing the players names instead of the player object to avoid memory leaks:
    List<String> test = new ArrayList<String>();

    BUT

    How would I get the player then though?

    Code:java
    1. ublic void onEnable(){
    2. Bukkit.getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable(){
    3. @Override
    4. public void run() {
    5. for(String p : test){
    6. if(p.getInventory().contains(Material.SNOW_BALL, 5)){
    7. return;
    8. }
    9. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 2.0F, 2.0F);
    10. p.getInventory().addItem(snowball());
    11. }
    12. }
    13. }, 100, 100);


    I have tried
    for(Player p = bukkit.getPlayer(test));

    I don't know what else to do :/ little stuck with this


    EDIT GOT IT:

    I did this
    Code:java
    1. for(Player p : Bukkit.getOnlinePlayers()){
    2. if(test.contains(p.getName())){
    3. if(p.getInventory().contains(Material.SNOW_BALL, 5)){
    4. return;
    5. }
    6. p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 2.0F, 2.0F);
    7. p.getInventory().addItem(snowball());
    8. }else{
    9. return;
    10. }
    11. }
    12. }
    13.  
    14. }, 100, 100);
     
Thread Status:
Not open for further replies.

Share This Page