Get all players in an event

Discussion in 'Plugin Development' started by koochi10, Jul 25, 2013.

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

    koochi10

    Does anyone know how to get all the players in a PlayerJoinEvent I think you need a list but can anyone guide me through that process thanks
     
  2. Offline

    soulofw0lf

    well a player join event is just one player at a time, but you can use Bukkit.getOnlinePlayers() to return a list of all online players when someone joins?
     
    koochi10 likes this.
  3. Offline

    koochi10

    Yeah but what Im trying to do is check once all the total number of players in game is = to 4
    List<Player> allplayers;
    int countplayers = allplayers.size();
    if (countplayers == 4){
    for (int swag = 0; swag == countplayers; swag++){// error the type of expression must be an array type but is resolved to a list<Player>
    Player hi = allplayers[swag]; // error the method counter(PlayerJoinEvent) in the type castlewars is not applicable for the arguments player
    counter(hi);
    }
    }
     
  4. Offline

    soulofw0lf

    i'm not 100% sure what you're trying to accomplish.. but there are a lot of things wrng with your code. Only one i'm going to make sure to mention here is NEVER store a player object, always store the name. You'll pre-emptively stop 9 million problems that way :)

    Code:java
    1. List<String> playerNames = new ArrayList<>();
    2. @Override
    3. public void onEnable(){
    4. //all your enabel stuff
    5. }
    6. @EventHandler
    7. public void playerJoin(PlayerJoinEvent e){
    8. Player p = e.getPlayer();
    9. playerNames.add(p.getName());
    10. if (playerNames.size >= 4){
    11. //not sure what your are trying to do with this next part
    12. for (String name : playerNames){
    13. Bukkit.getPlayer(name).sendMessage("hi?");
    14. }
    15. }
     
    koochi10 likes this.
  5. Offline

    koochi10

    Thanks fairly new to coding in general appreciate your help
     
Thread Status:
Not open for further replies.

Share This Page