Help with seeing invisible players

Discussion in 'Plugin Development' started by Ricecutter0, Aug 21, 2014.

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

    Ricecutter0

    Today I made a plugin that makes players go invisible.. That works completely fine.. exempt that I want it so all players with the permission FairiHide.see can see the players that are invisible..

    Could someone please help me and provide a code and where to put it please.

    Current code:

    Code:java
    1. package me.Ricecutter0.FairiHide;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14. public class Main extends JavaPlugin {
    15.  
    16. Logger l = Bukkit.getLogger();
    17.  
    18. @Override
    19. public void onEnable()
    20. {
    21. l.info("Plugin starting");
    22. }
    23.  
    24. @Override
    25. public void onDisable()
    26. {
    27. l.info("Plugin stopping");
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String [] args)
    31. {
    32. if(commandLabel.equalsIgnoreCase("hides"))
    33. {
    34. Player p = (Player) sender;
    35. if(p.hasPermission("FairiHide.hides"))
    36. {
    37. p.sendMessage(ChatColor.GOLD + "Hiding from the world..");
    38. p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0));
    39. }
    40. else p.sendMessage(ChatColor.DARK_RED + "Permission Denied");
    41. }
    42.  
    43. if(commandLabel.equalsIgnoreCase("show"))
    44. {
    45. Player p = (Player) sender;
    46. if(p.hasPermission("FairiHide.show"))
    47. {
    48. p.sendMessage(ChatColor.BLUE + "Revealing yourself");
    49. for(PotionEffect pe : p.getActivePotionEffects())
    50. p.removePotionEffect(pe.getType());
    51. }
    52. else p.sendMessage(ChatColor.DARK_RED + "Permission Denied");
    53.  
    54. }
    55. return false;
    56.  
    57. }
    58.  
    59. }
    60.  


    Bump
    I'd really appreciate it if someone could help :D

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

    es359

    Don't use commandLabel. Use cmd.getName(). Also why do you keep declaring Player p?
     
  3. Offline

    Ricecutter0


    I do Player p because it's easier to type. Lol. And Do you know how to solve my problem?
     
  4. Offline

    MOMOTHEREAL

    1.
    Tell me how you are supposed to learn anything from copy-pasting and spoon-fed?
    2. Giving a player Invisibility hides the player to anyone. You could use the methods Player.showPlayer(Player) and Player.hidePlayer(Player) instead. Read more about these methods here and here.
     
  5. Offline

    tempelis

    If you are looking to remove the player from a player (This makes the player not able to be seen or attacked by the player it is being hidden from), use the hidePlayer(Player player) and showPlayer(Player player) methods.

    http://jd.bukkit.org/rb/apidocs/org/bukkit/entity/Player.html#hidePlayer(org.bukkit.entity.Player)

    http://jd.bukkit.org/rb/apidocs/org/bukkit/entity/Player.html#showPlayer(org.bukkit.entity.Player)

    Used:
    PlayerToHideFrom.hidePlayer(HidingPlayer)
    PlayerToShowTo.showPlayer(PlayerToShow)
     
  6. Offline

    es359

    I understand why you did it, but you declare it twice in your code. You should only declare it once.
    Also, due to the nature of this plugin, you should check to see if the sender is player first, that way you won't throw a NPE from the console.
     
Thread Status:
Not open for further replies.

Share This Page