Player Visibility Toggler

Discussion in 'Plugin Development' started by Vextricity, Mar 7, 2015.

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

    Vextricity

    So I'm having a bit of a problem with player a player visibility toggler. Everybody knows what I'm talking about as most server networks have one of these, basically it hides players and shows them depending on which is already activated.

    Here's my code:

    Code:
                    if (p.getItemInHand().equals(showplayers))
                       
                    {
                       
                        p.getInventory().setItem(6, hideplayers);
                       
                        for (Player ops : p.getWorld().getPlayers())
                           
                        {
                           
                            if (!ops.hasPermission(permission))
                               
                            {
                               
                                p.showPlayer(ops);
                               
                            }
                           
                        }
                       
                    }
               
                    else if (p.getItemInHand().equals(hideplayers))
                       
                    {
                       
                        p.getInventory().setItem(6, showplayers);
                       
                        for (Player ops : p.getWorld().getPlayers())
                           
                        {
                           
                            if (!ops.hasPermission(permission))
                               
                            {
                               
                                p.hidePlayer(ops);
                               
                            }
                           
                        }
                       
                    }

    So you can see that it loops through all players and hides them, or shows them. My problem is that whenever players are already hidden, and the showplayer is activated, nothing happens. The item changes, but the players aren't shown. Oh, and I don't get any errors in the console. I'm sure it's an easy fix, but any help?
     
  2. Offline

    TheFl4me

    Do you only want to hide the players ingame or also in tab?
     
  3. Offline

    Vextricity

    Just in-game is what I'm aiming for; however hiding also in tab would be helpful
     
  4. Offline

    TheFl4me

    replace:
    Code:
    for (Player ops : p.getWorld().getPlayers()) {
    with

    Code:
    for (Player ops : Bukkit.getServer().getOnlinePlayers()) {
    this (should) work.

    note: this will also hide the players in tab if you dont want that simply remove .getServer()
     
  5. Offline

    RROD

    Code:
    for (Player ops : p.getWorld().getPlayers()) {
        // Ignore a player if they have this permission
        if (ops.hasPermission(permission)) continue;
    
        // Show the player if our player can't see them, ignore if they already can
        if (p.getItemInHand().equals(showplayers) && !p.canSee(ops)) p.showPlayer(ops);
    
        // Hide if not already hidden, ignore if hidden
        if (p.getItemInHand().equals(hideplayers) && p.canSee(ops)) p.hidePlayer(ops);
    }
    
    Give that a whirr. In the meantime, where are you putting this code - in an event call? If so, which one?
     
  6. Offline

    Vextricity

    @RROD I'm putting it in a PlayerInteractEvent and checking if the action is a right click. The even works, just showing players is becoming an issue. I'll give your code a go.

    @RROD Nope, I'm still getting the same issue. The players vanish, but don't reappear.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  7. Offline

    Vextricity

  8. Offline

    LetsTalkTnTHere

    Why does "ops" need permission if the player is the one interacting?
     
Thread Status:
Not open for further replies.

Share This Page