hide all players

Discussion in 'Plugin Development' started by Ungemonstert, Jul 6, 2015.

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

    Ungemonstert

    Hey guys,
    I'd like to make a lobby, where everybody hide or show everyone.
    Don't know how to explain my problem so I use an example:
    On a server are 4 players. I join and want to hide them. It works.

    Another example:
    On a server are 4 players. I join. Example-Player "abc123" joins. I want to hide all. Everyone is hidden except "abc123".

    My question:
    How to hide all players, if there joined X Players after me?

    My current code:

    Main:
    Code:
    public class Main extends JavaPlugin
    {
        public static ArrayList<Player> hidden = new ArrayList<Player>();
      
        @Override
        public void onEnable()
        {
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(new L_onRightClick(), this);
        }
    }
    
    Item Click Listener:
    Code:
    if(e.getCurrentItem().getType() == Material.WOOL)
                {
                    if(e.getCurrentItem().getDurability() == 5)
                    {
                        for(Player players : Bukkit.getOnlinePlayers())
                        {
                            if(Main.hidden.contains(p))
                            {
                                Main.hidden.remove(p);
                                p.showPlayer(players);
                                p.sendMessage("§aAll players visible");
                            }
                        }
                    }
                    else if(e.getCurrentItem().getDurability() == 14)
                    {
                        for(Player players : Bukkit.getOnlinePlayers())
                        {
                            if(!Main.hidden.contains(p))
                            {
                                Main.hidden.add(p);
                                p.hidePlayer(players);
                                p.sendMessage("All players hidden!");
                            }
                        }
                    }
                  
                    e.getView().close();
                }
    (it's in an inventory)
     
  2. You have to use the playerjoinevent.
    For those who are in the 'hidden' list, hide the player that just joined.

    Also note that 'players' is a single object here.
    In some other languages you would have to write 'foreach(Class varName in someList)', just fyi.
     
  3. Offline

    Ungemonstert

    @adventuretc You mean I should write in the PlayerJoinEvent:

    Code:
    public void playerJoin(PlayerJoinEvent e)
    {
        Player p = e.getPlayer();
        for(Player pil : Main.hidden)
        {
            pil.hidePlayer(p);
        }
    }
    ?
     
  4. Offline

    NeguinDaFarofa

    Add this player to a arraylist or hashmap
     
  5. Offline

    Ungemonstert

    @NeguinDaFarofa you mean, that I have a arraylist/hashmap with all players?
     
    darthvader1925 likes this.
  6. Offline

    NeguinDaFarofa

    If if you want to leave an unknown player (random) visible, creates a hash with all players and take a random system.

    If you want a specific, the simplest way I know is to create a command or something that select the one player in a hash.
     
  7. Offline

    Ungemonstert

  8. Offline

    NeguinDaFarofa

    then use
    Code:
     for (Player other : Bukkit.getServer().getOnlinePlayers()) {
                                player.hidePlayer(other);
     
  9. Yes.
     
  10. Offline

    Ungemonstert

    I think you doesn't understand right. I have a server. On that server are 4 people. If I join, I want's to see them all (line normaly). If I use the Hide item, I want's to hide everyone. If I use it again, everyone is shown. If Hide-mode is turned off (I see everyone) and another player joins, and I turns the Mode on again. Every user is hidden, except the player who joins after me. Thats my problem. I want's to know how I can hide him too.
     
  11. I understand that. The above code does exactly that.
    If you have hidden the players it will hide the new player, that's all.
     
Thread Status:
Not open for further replies.

Share This Page