Hide player in Serverlist (/list and TAB)

Discussion in 'Plugin Development' started by LunaTiX_, Aug 12, 2012.

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

    LunaTiX_

    Hi,
    i want to write a plugin, which hides a player when he perform a command.
    For example:
    Code:
    if(cmd.getName().equalsIgnoreCase("hide")) {
    if(args.length == 0) {
      //Now the player should be hidden
    }
    }
    How can i do this ? Is there an event for hiding players ?
    I hope you can help me.
     
  2. Offline

    ThijsD

    Like this:
    Code:
                for (Player player : getServer().getOnlinePlayers()) {
                    player.hidePlayer(p); //P is ofc the player who called the command
                }
     
  3. Offline

    amitlin14

    maybe player.hidePlayer()?
     
  4. Offline

    LunaTiX_

    I tried that already, but it does not work.
    Code:
                    if(cmd.getName().equalsIgnoreCase("hide")) {
                            player.hidePlayer(player);
                        player.sendMessage("You are now hidden from the onlinelist");
                        return true;
                    }
     
  5. player.hidePlayer hides your avatar ingame...
    Did you try something like
    player.setListName(null);
    ?
     
  6. Offline

    amitlin14

    but then itll be just a blank space in the list no?
     
  7. Offline

    ThijsD

    That doesn't work becouse your hiding you from yourself.
    You have to tell EVERY player in the game to hide a specific player. Thats why I looped trough all the online players and told them to hide the player that used the command. You will always see yourself in the online list, even when hidden.

    Edit: This also means that you will be invisible in the game, and that if someone new logs in you have to hide the players from him/her aswell.

    It should hide you from the TAB list aswell :)
     
  8. Offline

    LunaTiX_

    Okay, so now i am hidden for every player who is online, but i always see myself in the online list ?
    All right, but i dont want me to be invisible. I just want to hide myself in the online list ..
    Code:
                    if(cmd.getName().equalsIgnoreCase("hide")) {
                        for(Player p : plugin.getServer().getOnlinePlayers()) {
                            p.hidePlayer(player);
                            return true;
                        }
                        player.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + plugin.getConfig().getString("StealthLogin.Prefix") + ChatColor.GRAY + "] " + ChatColor.GREEN + "StealthLogin ist nun aktiviert");
                        return true;
                    }
     
  9. Just looked at the CB sources: It won't work at all. :(
    The question is what would happen if you would do:
    ((CraftPlayer)player).getHandle().listName = null;
    cause this will set the list name to null in notch code. I think it will either work or cause a lot of errors (eventually crashing the game). ^^
    Another possible attacking point would be this file:
    https://github.com/Bukkit/CraftBukk...erver/ServerConfigurationManagerAbstract.java
    Just see how often the listName is used there. Also have a look at the disconnect function, cause it sends a packet containing the listName. Maybe the package to remove it from the list? ;)
    Code:java
    1. Packet201PlayerInfo packet = new Packet201PlayerInfo(entityplayer.listName, false, 9999);
    2. for (int i = 0; i < this.players.size(); ++i) {
    3. EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
    4.  
    5. if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
    6. entityplayer1.netServerHandler.sendPacket(packet);
    7. }
    8. }

    Maybe you could just send this package with the list name of the player you want to hide to all players and see what happens? This could be archived like this:
    Code:java
    1. Packet201PlayerInfo packet = new Packet201PlayerInfo(player.getPlayerListName(), false, 9999);
    2. for(Player p: getServer().getOnlinePlayers())
    3. ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(packet);

    Good to know, thanks. :)
     
  10. Offline

    evilmidget38

    You are correct, sending a Packet201PlayerInfo with the value false will remove them from the list.
     
  11. Offline

    LunaTiX_

    Thanks for your answers.
    When i use your code
    PHP:
    Packet201PlayerInfo packet = new Packet201PlayerInfo(player.getPlayerListName(), false9999);
    for(
    Player pgetServer().getOnlinePlayers())
        ((
    CraftPlayer)p).getHandle().netServerHandler.sendPacket(packet);
    eclipse underlines CraftPlayer (Cannot be resolved to a type)

    And what means the "9999" in your Packet201PlayerInfo object.
     
  12. Offline

    evilmidget38

    Make sure you are using CraftBukkit as an external jar, and have imported CraftPlayer.

    In this situation 9999 represents their ping(the green bars you seen by names when you press tab). In this instance it doesn't actually do anything, as the player is removed from the list.
     
  13. Offline

    Taco

    One issue with this, otherwise it'd work fine. You shouldn't return inside your loop. You will be able to see your own name on the list since you can't exactly hide from yourself it seems, but nobody else will see you.
     
  14. Offline

    LunaTiX_

    @evilmisget38: Thanks, it works. But there are two things i want to change ..
    1. Every time a player joins the game i have to perfom the command again. If not, the player can see my name is the online list
    The second thing is: If i type /list my name is visible. I dont know how to change it
     
  15. Offline

    evilmidget38

    1. Make a listener for PlayerJoinEvent, and hide yourself from the player whenever someone joins.
    2. I don't know how to change that, for I private request that added in fake players, I had to make my own /list and /who command.
     
Thread Status:
Not open for further replies.

Share This Page