Convert List<MPlayer> to player

Discussion in 'Spigot Plugin Development' started by iNoXs, Jun 29, 2016.

  1. Hi i'm looking for a way to convert a list of a player into player name or looping through this list to add a custom listname i tried different things but doesn't work :/
    Code (Text):
        public void setTabRel(Player p1){
            MPlayer p;
            p = MPlayer.get(p1);
            Faction faction1 = p.getFaction();  

            for (Faction factionall : FactionColl.get().getAll()){
            List<MPlayer> factionother = factionall.getMPlayers();
    After this im stuck

    Thanks for help
    • Funny Funny x 1
  2. Is MPlayer an interface? Just asking xD
  3. Choco


    Your question is unclear. I'm not sure I know what you're trying to do. Also, what is an MPlayer? Are you using a faction API? If so, which Faction plugin API are you using. This question has a lot of missing information

    EDIT: Perhaps MassiveCraft's Factions API? (MPlayer = MassivePlayer). Question is still however unclear
  4. MPlayer is from Faction, is just a player, so i have a list of MPlayer and i have to convert it to a player
    and i use the latest version of factions from massiveCraft
  5. Choco


    There should be an MPlayer#getPlayer() method, is there not?
    • Winner Winner x 1
  6. yes MPlayer p = MPlayer.get(player);
  7. No he means a method that actually returns a player within the MPlayer class.
  8. MPlayer#getPlayer() returns the Player interface from Bukkit
    #8 ItsMonkey, Jun 29, 2016
    Last edited: Jun 29, 2016
    • Winner Winner x 3
  9. List<Player> playerList = -> p.getPlayer()).collect(Collectors.toList());
    • Useful Useful x 1
  10. One other litle thing : is it possible to change the players name in the tab list for the sender only ?
    • Like Like x 1
  11. That looks really inefficient. Why not just use for-each?
  12. It's fine as an answer. The only real optimalization that could be done (even though it's applicability entirely depends on the use case), is directly using forEach on the Stream<Player> rather than collecting it (if OP wants to directly do something with the Players)

    For the rest, it's just amazing syntactic sugar :p
  13. i want to add a nickname to each player in this list but i can't cast to a player

    Code (Text):
            MPlayer p;
            p = MPlayer.get(p1);
            Faction faction1 = p.getFaction();  
            for (Faction factionall : FactionColl.get().getAll()){      
                if(faction1.getRelationTo(factionall) == Rel.ENEMY){              
                   //add a tag to factionall player's but the tag can be only view by the sender