/Invis - Explained Below

Discussion in 'Plugin Development' started by XKnucklesX, Nov 10, 2013.

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

    XKnucklesX

    So how do I make it when a person doing /invis they become invisible for whatever time depending on what helmet they are wearing.

    Like:
    Leather Helmet = 3 secs
    Iron Helmet = 4 secs
    Gold Helmet = 5 secs
    Diamond Helmet = 6 secs
    Chainmail Helmet = 9 secs
     
  2. Offline

    Mathias Eklund

    you start a timer and check what helmet they are wearing.
     
  3. Offline

    XKnucklesX

    Well I need a example as I cannot code well
     
  4. Offline

    AndyMcB1

    This is much easier than your gunner plugin..

    Do you understand the concept of if /else if/ else?
     
  5. Offline

    Mathias Eklund

    Is this in the correct section?
     
  6. Offline

    MOMOTHEREAL

    Pretty easy to do... I can do that!

    https://dl.dropboxusercontent.com/u/103389090/bukkitRequests/inviscommand.jar Tell me if you need anything more! :)

    I just read your post again... woops. I thought you wanted someone to do it for you. This is what the plugin looks like:
    Code:java
    1. package me.momo.requests.invis;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.potion.PotionEffect;
    10. import org.bukkit.potion.PotionEffectType;
    11.  
    12. public class Main extends JavaPlugin{
    13. public void onEnable(){
    14. this.getLogger().info("InvisCommand has been enabled.");
    15. }
    16. public void onDisable(){
    17. this.getLogger().info("InvisCommand has been disabled.");
    18. }
    19. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args){
    20.  
    21. if (CommandLabel.equalsIgnoreCase("invis")){
    22. if (sender instanceof Player){
    23. Player player = (Player) sender;
    24. if (player.getInventory().getHelmet()==null){
    25. player.sendMessage(ChatColor.RED + "You do not have a helmet!");
    26. }else{
    27. if(player.getInventory().getHelmet().getType()==Material.LEATHER_HELMET){
    28. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 3*20, 0));
    29. player.sendMessage(ChatColor.GREEN + "You are now invisible for 3 seconds.");
    30. }
    31. if(player.getInventory().getHelmet().getType()==Material.IRON_HELMET){
    32. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 4*20, 0));
    33. player.sendMessage(ChatColor.GREEN + "You are now invisible for 4 seconds.");
    34. }
    35. if(player.getInventory().getHelmet().getType()==Material.GOLD_HELMET){
    36. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 5*20, 0));
    37. player.sendMessage(ChatColor.GREEN + "You are now invisible for 5 seconds.");
    38. }
    39. if(player.getInventory().getHelmet().getType()==Material.DIAMOND_HELMET){
    40. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 6*20, 0));
    41. player.sendMessage(ChatColor.GREEN + "You are now invisible for 6 seconds.");
    42. }
    43. if(player.getInventory().getHelmet().getType()==Material.CHAINMAIL_HELMET){
    44. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 9*20, 0));
    45. player.sendMessage(ChatColor.GREEN + "You are now invisible for 9 seconds.");
    46. }
    47. }
    48.  
    49. }else{
    50. //Console
    51. }
    52. }
    53. return false;
    54. }
    55. }
    56.  

    Tho it would be better to use Else If... but whatever :)

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

    Iroh

    Moved to plugin requests (as he doesn't ask any specific questions).
     
  8. Offline

    XKnucklesX

    I stopped programming
     
Thread Status:
Not open for further replies.

Share This Page