Solved Retrieve all players on a team

Discussion in 'Plugin Development' started by Hugi21, Nov 1, 2015.

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

    Hugi21

    Hello.
    I want to recover all the players on a team. But the problem is I do not know how I know that it is not possible to make its
    Code:
    Team example;
    for(Player p : example.getPlayersTeam()){
    //do   things
    // I wrote this very quickly may code the name of the method is not exact sorry
    }
    So here I hope you can help me
    Best regards
    Hugi21
     
  2. Offline

    Scimiguy

    That code will loop through each player on that team

    What's the problem?
     
  3. Offline

    FabeGabeMC

    @Hugi21
    The problem might be that the 'example' team is null.
     
  4. Offline

    Hugi21

    @FabeGabeMC I know it is equal to null but as the variable name indicates this is an EXAMPLE So imagine you her if her can help you
    Code:
     @EventHandler
        public void onJoin(PlayerJoinEvent e ){
            Player p =  e.getPlayer();
            Scoreboard sb = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
            Objective obj = sb.registerNewObjective("test","dummy");
            Team example = sb.registerNewTeam("example");
    
            example.addPlayer(p);









    @Scimiguy NO because the method getPlayers() return OfflinePlayer and not players
    ,and so finally I found the solution



    Code:
    for(OfflinePlayer p : example.getPlayers(){
    Player playersTeam = (Player) p ;
    
    //do stuff
    
    }
     
Thread Status:
Not open for further replies.

Share This Page