How to hide an player

Discussion in 'Plugin Development' started by luigieai, Dec 23, 2013.

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

    luigieai

    Hello :D, im creating a plugin and i dont know how to when a player that have a admin permission type /admin he will be hidden for all players except others admin, how i can do that?
     
  2. Offline

    pope_on_dope

    loop through all the players on the server, and if the player doesn't have your admin permission, hide your target player from them
    like this
    Code:
    for(Player p : getallplayers)
        if(!p.hasPermission("your.perm")
            p.hidePlayer(targetAdmin);
     
  3. Offline

    luigieai

    Code:java
    1. public class admin implements CommandExecutor{
    2. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    3. final Player p = (Player) sender;
    4. if(commandLabel.equalsIgnoreCase("admin"))
    5. {
    6. if(args.length == 0)
    7. {
    8. for(Player p : Bukkit.getOnlinePlayers())
    9. if(!p.hasPermission("lotus.staff.admin")){
    10. p.hidePlayer(p.getPlayer());
    11. }
    12. }
    13. return true;
    14. }
    15. return false;
    16.  
    17. }
    18. }

    in "for(Player p : Bukkit.getOnlinePlayers())" the p is giving error
     
  4. Offline

    pope_on_dope

    change the p in your loop to player, your variables are named the same

    also, you need to check if the command sender is a player before you cast it as one.
     
  5. Offline

    luigieai

    pope_on_dope
    but the
    is checking if the player is sender, or is other way?
     
  6. Offline

    pope_on_dope

    you must check if the CommandSender is a player before you cast it as one.
    CommandSenders can either by a player or the console so before you create your player object, you must check this
    Code:
    if(sender instanceof Player) {
        code...
    }
     
Thread Status:
Not open for further replies.

Share This Page