LobbyPlugin - Hider

Discussion in 'Spigot Plugin Help' started by ThunderRamun, Aug 4, 2018.

  1. Hello,


    At the moment I am working on a LobbyPlugin which later has a player hide function. Unfortunately that does not work what I programmed. Hide All Players and Show All Players will only work Show Team Members will not work. (If you click on the item, only team members will be shown, but as soon as you rejoint all players will be activated.)

    Code (Text):
    public class PlayerHide implements Listener {

       
       
        public Main plugin;
       
        public PlayerHide(Main instance){
                plugin = instance;
        }
       
        ArrayList<String> HideShow = new ArrayList<String>();
        ArrayList<String> HideShow2 = new ArrayList<String>();
               
               
        @EventHandler
        public void klickEvent(InventoryClickEvent e) {
            Player p = null;
            if (e.getWhoClicked() instanceof Player) {
                p = (Player) e.getWhoClicked();
            }
            if (e.getCurrentItem().getItemMeta().getDisplayName().equals("§aAlle Spieler zeigen")) {
                e.setCancelled(true);
                for(Player players : Bukkit.getOnlinePlayers()) {
                    if (HideShow.contains(p.getName())) {
                        HideShow.remove(p.getName());
                        p.showPlayer(players);
                    } if (HideShow2.contains(p.getName())) {
                        HideShow2.remove(p.getName());
                        p.showPlayer(players);
                    } else {
                        p.showPlayer(players);
                    }
                }
                p.sendMessage(Main.Prefix + "§7Alle §9Spieler §7sind für dich nun §asichtbar§7!");
                p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
                p.closeInventory();
            }

            if (e.getCurrentItem().getItemMeta().getDisplayName().equals("§cAlle Spieler verstecken")) {
                e.setCancelled(true);
                for(Player players : Bukkit.getOnlinePlayers()) {
                    if (!HideShow.contains(p.getName())) {
                        HideShow.add(p.getName());
                        p.hidePlayer(players);
                        if (HideShow2.contains(p.getName())) {
                            HideShow2.remove(p.getName());
                            p.hidePlayer(players);                      
                        }
                    } else {
                        p.hidePlayer(players);
                    }
                }
                p.sendMessage(Main.Prefix + "§7Alle §9Spieler §7sind für dich nun §cunsichtbar§7!");
                p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
                p.closeInventory();
            }

            if (e.getCurrentItem().getItemMeta().getDisplayName().equals("§eNur Teamler zeigen")) {
                e.setCancelled(true);
                for(Player players : Bukkit.getOnlinePlayers()) {
                    if (HideShow.contains(p.getName())) {
                        HideShow.remove(p.getName());
                    }if (!HideShow2.contains(p.getName())) {
                        HideShow2.add(p.getName());
                        if (players.hasPermission("lobby.hide.bypass")) {
                            p.showPlayer(players);
                        } else {
                            p.hidePlayer(players);
                        }
                    }
                }
                p.sendMessage(Main.Prefix + "§7Nur noch §eTeammitglieder §7sind nun für dich §asichtbar§7!");
                p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
                p.closeInventory();
            }
        }

        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            for(Player players : Bukkit.getOnlinePlayers()) {
                if (HideShow.contains(players.getName())) {
                    players.hidePlayer(p);
                } if (HideShow2.contains(players.getName())) {
                    if (players.hasPermission("lobby.hide.bypass")) {
                        players.showPlayer(p);
                    } else {
                        players.hidePlayer(p);
                    }
                }
            }
        }
    }
    Info:

    I have been programming for 4 weeks

    Sry for my bad English
     
  2. Hello,


    Now it works!

    //close