Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3207

Hiding players in a BukkitRunnable task doesn't hide them in the player list

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None

      Hiding players from each other in a BukkitRunnable breaks hiding in the player list (tab list).
       
      Here's some sample code you can copy-paste to reproduce it:
       

      public class TestPlugin extends JavaPlugin implements Listener {
        
          @Override
          public void onEnable() {
              // Listen to events
              Bukkit.getPluginManager().registerEvents(this, this);
          }
        
          @EventHandler
          public void onJoin(final PlayerJoinEvent event) {
              // Hide all players from each other on the next tick
              new BukkitRunnable() {  
                  public void run() {
                      Player player = event.getPlayer();
                    
                      for (Player other : Bukkit.getOnlinePlayers()) {
                          if (other.equals(player)) continue; // Skip self
                        
                          // Hide from each other
                          other.hidePlayer(player);
                          player.hidePlayer(other);
                        
                          // Confirm in console that this code is getting executed
                          getLogger().log(Level.INFO, "Hiding " + other.getName() + " and " + player.getName() + " from each other by task");
                      }
                  }
              }.runTaskLater(this, 1);
          }
        
          @EventHandler
          public void onCommand(PlayerCommandPreprocessEvent event) {
              if (event.getMessage().equalsIgnoreCase("/hideall")) {
                  Player player = event.getPlayer();
                
                  for (Player other : Bukkit.getOnlinePlayers()) {
                      if (other.equals(player)) continue; // Skip self
                    
                      // Hide from each other
                      other.hidePlayer(player);
                      player.hidePlayer(other);
                    
                      // Confirm in console that this code is getting executed
                      getLogger().log(Level.INFO, "Hiding " + other.getName() + " and " + player.getName() + " from each other by /hideall");
                  }
              }
          }
      }
      

        # PlayerA joins the game

      1. PlayerB joins the game
        • The two players cannot see each other in the game, as they are both hidden, but:
        • PlayerA can see PlayerB on the player list, but PlayerB can't see PlayerA on the player list
      2. Running the "/hideall" command doesn't fix it. It seems that if you do it in a runnable task it breaks hiding completely for the involved players

       

            Unassigned Unassigned
            VapidLinus Linus Närkling
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: