[Closed] Vanish Command Hide Player on Join

Discussion in 'Programming' started by Sullaysur, Feb 11, 2019.

Thread Status:
Not open for further replies.
  1. Hey,

    i have a Question and hope that i can find an Answere here,
    I have made an /vanish Command, and now i want that if a player Join that all Player in Vanish gets "invisible" hide for him.

    My Player Join event:
    Code (Java):
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player p = e.getPlayer();
        if(PlayerManager.isvanish(p.getUniqueId().toString())) {
                for(Player all : Bukkit.getOnlinePlayers()) {
                    all.hidePlayer(p);
                }
                p.setAllowFlight(true);
                p.setFlying(true);
                p.getWorld().strikeLightningEffect(p.getLocation());
                p.sendMessage(Main.prefix + "┬žeDu bist im Vanish gejoint!");
            }
    }
    Hope you can help me,
    Sullaysur

    ps.Sorry for my bad English
     
  2. Strahan

    Benefactor

    So, is it not working? If not, are you getting an error? Post the stack trace. You should also be using the ChatColor enum, not hardcoding the color character.

    PS playing the lightning strike effect at the player location for a vanished player seems to be counter productive, lol
     
    #2 Strahan, Feb 12, 2019
    Last edited: Feb 12, 2019
  3. No it worked fine, but if a new Player joins he can see all persons that are Vanish, how can i make it that the Vanish players are also for the new Joined player invisible?
     
  4. You have to check in your for loop if the current player is also in vanish, if he is then hide him for the joined Player

    Code should something like that:
    Code (Java):
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        Player p = e.getPlayer();
                for(Player all : Bukkit.getOnlinePlayers()) {
                    if(PlayerManager.isvanish(p.getUniqueId().toString())) //Moved it here so that the for loop is always executed
                    all.hidePlayer(p);
                    if(PlayerManager.isvanish(all.getUniqueId().toString()))  //Check if the current checked player is in vanish
                    p.hidePlayer(all); //Vanishes the current checked Player for the joined player
                }
                if(PlayerManager.isvanish(p.getUniqueId().toString())) { //Here we have to check if the player joined in vanish again to give him fly
                p.setAllowFlight(true);
                p.setFlying(true);
                p.getWorld().strikeLightningEffect(p.getLocation());
                p.sendMessage(Main.prefix + "┬žeDu bist im Vanish gejoint!");
            }
    }
     
    • Agree Agree x 1
  5. Sorry Sorry and Sorry for my bad english, i had made an video about the situation, please watch this and i hope you will understand what i mean!

     
  6. Strahan

    Benefactor

    His reply was in regards to what you were showing in the video. As he said; when you loop the players, if the current player that you are looping over is vanished, just set him vanished to the joined player.

    Also, you do not need to see the server info to be able to join if you know the server is up. Hitting "refresh" until you got the MOTD was not necessary.
     
  7. But it didnt work
     
  8. Strahan

    Benefactor

    Then you are doing something wrong, as it works fine for me. Post your code.

    PS: Here is my test.
     
    #8 Strahan, Feb 13, 2019
    Last edited: Feb 13, 2019
    • Agree Agree x 1
  9. If it still doesn't work show us your current code, maybe there is something else wrong?
     
  10. Sorry for my Late Answer, i had a little much to do at work.

    Thanks for the Video, your code works well and now my works also well, Thanks again!
     
    #10 Sullaysur, Feb 15, 2019 at 4:10 PM
    Last edited: Feb 15, 2019 at 5:53 PM
Thread Status:
Not open for further replies.

Share This Page