Help with invisible players

Discussion in 'Spigot Plugin Development' started by DevelopmentHigh, Mar 19, 2020.

  1. Does SOMEONE have code when player join to put them on vanish, and after 2 seconds of join to get out of vanish?
     
  2. Just so you know, people aren’t here to spoon feed your ass. But I can explain to you how it works. Whenever the player join, put them in game mode 3 or give them the invisibility effect and store their name in a list if you want to keep track of the invisible players. Don’t forget to set the join message to null. In a bukkit runnable that is run 2 seconds later you remove the invisible effect or set their game mode to survival. Broadcast a message saying that the player joined the game. Remove them from the vanish list if used. Don’t forget to check if null in the runnable to make sure that the player is still online.

    also, another efficient way of hiding a player is to iterate through the online players and use onlinePlayer.hidePlayer(newPlayer);

    just curious, what are you trying to achieve though?
     
    • Winner Winner x 1
  3. No, its problem with custom plugin i need to set player invisible, and then after 2-3 seconds to get them visible
     
  4. Code (Java):
    @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e){
            Player p = e.getPlayer();
            Plugin plugin = /* plugin*/
            for(Player ps : Bukkit.getOnlinePlayers()){
                if(ps != p){
                    ps.hidePlayer(plugin, p);
                }
            }
            Bukkit.getScheduler().runTaskLater(plugin, () -> {
                for(Player ps : Bukkit.getOnlinePlayers()){
                    if(ps != p){
                        ps.showPlayer(plugin, p);
                    }
                }
            }, minutes * 60 * 20);
        }

     
    EDIT: that if you wanna vanish. If you wanna set Invisible effect - use
    Code (Text):
    p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, duration, level));
    like hidePlayer and
    Code (Text):
    p.removePotionEffect(PotionEffectType.INVISIBILITY);
    like showPlayer
     
    • Funny Funny x 1
  5. The previous poster already gave you all the clues you need. You can use Player#hidePlayer to completely hide a player from another one. All you would need to do is to loop over Server#getOnlinePlayers and call the method on each of the players you want to hide the player from. To undo the effect, schedule the task of looping over all players using Player#showPlayer after a few seconds, with the help of Server#getScheduler #runTaskLater.

    In pseudo-code:

    Code (Text):
    for all players
      player hidePlayer playerToHide

    scheduler run later
      for all players
        player showPlayer playerToShow
    as this plugin, delay in ticks
     
  6. Thank you i will try to do this now
     
  7. Strahan

    Benefactor

    Spoonfeeding makes you feel like you are helping, but in reality you are not because most people who ask will just copy and paste the code without learning what it means. By doing like Gadse and just outlining the process, it makes people actually learn how to implement it.

    Also, kinda weird to setup a plugin instance in the event. Most people would make a member variable for that.
     
    • Agree Agree x 1
  8. About plugin instance, i do that in main class but that is only an example (that why i doesn`t intialize Plugin in example and set comment). He wanna know how to do that and must read docs "What is that". If he write to me - l help , but why you think that ready examples doesn`t good? When l start l always see somethink like one-line code and doesn`t understood "where to place that" only becouse l was newbie at that, but ready code help me and i google about what line do. If he wanna code example - i doesn`t wanna enable toxic "read and understood", i give example.

    Sorry for my english, i realy bad at english
     
  9. Strahan

    Benefactor

    That's not an example, that's full implementation of his requested need.
     
  10. if you copy-paste my code - you get errors. So... that is not full implementation, maybe, if i uderstood what you mean.
     
  11. There’s like one small error in the code you posted and even the newbiest person could fix it
     
  12. i realy like when peaple wanna that another peaple know why that code there, but i think that example or how you say full implementation is not very bed and in some situations is more informative that "read docs"
     
  13. This isn’t about reading docs, this is about learning java and being able to find solution on your own just like every developer does.
     
  14. Strahan

    Benefactor

    That doesn't change that you are basically writing the whole thing. Don't need to be so defensive, just saying... make newbies work for it a little. It's better for them in the long run.
     
    • Agree Agree x 1
  15. yes i know to fix this