Solved Hide player plugin

Discussion in 'Plugin Development' started by PolarCraft, Oct 22, 2013.

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

    whitehooder

    Code:java
    1. package net.bc.minecraft;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.metadata.FixedMetadataValue;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10.  
    11. public class Hide extends JavaPlugin {
    12.  
    13. @Override
    14. public void onEnable() {
    15. getCommand("hide").setExecutor(this);
    16. }
    17.  
    18. @Override
    19. public void onDisable() {
    20.  
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    24. Player player = (Player) sender;
    25. if(cmd.getName().equalsIgnoreCase("hide")){
    26. if (sender.hasPermission("bc.hide") && !player.hasMetadata("---BCHIDDEN---")){
    27. for(Player ps : Bukkit.getOnlinePlayers()){
    28. ps.hidePlayer(player);
    29. }
    30. player.setMetadata("---BCHIDDEN---", new FixedMetadataValue(this, null));
    31. player.sendMessage(ChatColor.GRAY +"You are now hidden!");
    32. return true;
    33. } else if (sender.hasPermission("bc.hide")) {
    34. for(Player ps : Bukkit.getOnlinePlayers()){
    35. ps.showPlayer(player);
    36. }
    37. player.removeMetadata("---BCHIDDEN---", this);
    38. player.sendMessage(ChatColor.GRAY +"You are no longer hidden!");
    39. return true;
    40. }
    41. }
    42. return false;
    43. }
    44. }


    This code is working.. as was my last one, and probably negative_codezZ's too. There is just something wrong on your side.

    [​IMG]
     
  2. Offline

    zombiekiller753

    xTrollxDudex
    I don't normally have commands in my main class, so that's something out of my depth

    Anyways, I did say it was unconfirmed :)

    P.S.
    This post has been edited 6969 times? Only you...
     
  3. Offline

    xTrollxDudex

    whitehooder
    Line 15 is really annoying me. It's completely redundant
     
  4. Offline

    DailyLove

    PolarCraft Try using this. It was from my HideAll plugin I made for a request

    Code:
    public void hideAll(final Player player) {
            if(!player.hasPermission("hideall.use")) {
                player.sendMessage((new StringBuilder()).append(ChatColor.RED).append("You don't have the Permission to do that!").toString());
                return;
            }
            itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("item name")));
            item2.setItemMeta(itemMeta);
            item.setItemMeta(itemMeta);
            Player aplayer[];
            int j = (aplayer = Bukkit.getOnlinePlayers()).length;
            if(cooldown.contains(player)) {
                cooldown.remove(player);
                cd.add(player);
                player.sendMessage(prefix + ChatColor.GREEN + "All players are now " + ChatColor.GOLD + "visible!");
                    for(int i = 0; i < j; i++) {
                        Player other = aplayer[i];
                        player.showPlayer(other);
                    }
                    player.getInventory().removeItem(player.getInventory().getItemInHand());
                    player.getInventory().setItemInHand(item);
                    Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            cd.remove(player);
                        }
                    }, 100L);
                    return;
            } else {
                cd.add(player);
                cooldown.add(player);
                player.sendMessage(prefix + ChatColor.GREEN + "All players are now " +  ChatColor.DARK_RED + "hidden!");
                player.getInventory().removeItem(player.getInventory().getItemInHand());
                player.getInventory().setItemInHand(item2);
                for(int i = 0; i < j; i++) {
                    Player other = aplayer[i];
                    if(!other.hasPermission("hideall.admin"))
                        player.hidePlayer(other);
                        Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                            public void run() {
                                cd.remove(player);
                            }
                        }, 100L);
                }
            } 
    }
     
  5. Offline

    PolarCraft

    A friend of mine helped me ^_^. The following code worked. So if anyone wants to use it go ahead :D
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    2. {
    3. Player p = (Player)sender;
    4. if (cmd.getName().equalsIgnoreCase("hide")) {
    5. if(!sender.hasPermission("bc.hide")) {
    6. sender.sendMessage(ChatColor.DARK_RED +"Sorry no permissions towards /hide!");
    7. return false;
    8. }
    9.  
    10. if(!p.hasMetadata("hidden")) {
    11. for(Player ps : Bukkit.getOnlinePlayers()) {
    12. ps.hidePlayer(p);
    13. }
    14. p.setMetadata("hidden", new FixedMetadataValue(this, true));
    15. p.sendMessage(ChatColor.GRAY + "You are now hidden!");
    16. return true;
    17. } else {
    18. for(Player ps : Bukkit.getOnlinePlayers()) {
    19. ps.showPlayer(p);
    20. }
    21. p.removeMetadata("hidden", this);
    22. p.sendMessage(ChatColor.GRAY + "You are now unhidden!");
    23. return true;
    24. }
    25. }
    26. return false;
    27. }
    28. }
     
Thread Status:
Not open for further replies.

Share This Page