BaconIsBest

Untitled

Aug 19th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. package me.bacon.plugin;
  2.  
  3. import java.util.logging.Logger;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Material;
  7. import org.bukkit.enchantments.Enchantment;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.event.EventHandler;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.inventory.ClickType;
  12. import org.bukkit.event.inventory.InventoryClickEvent;
  13. import org.bukkit.event.inventory.InventoryMoveItemEvent;
  14. import org.bukkit.event.inventory.InventoryType.SlotType;
  15. import org.bukkit.inventory.InventoryHolder;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.bukkit.plugin.PluginDescriptionFile;
  18. import org.bukkit.plugin.PluginManager;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20. import org.bukkit.potion.PotionEffect;
  21. import org.bukkit.potion.PotionEffectType;
  22.  
  23. public class Main extends JavaPlugin implements Listener{
  24. Logger logger = getLogger();
  25. public static Main plugin;
  26.  
  27. public void onDisable() {
  28. PluginDescriptionFile pdfFile = this.getDescription();
  29. this.logger.info(pdfFile.getName() + " Has been disabled!");
  30. }
  31.  
  32. public void onEnable() {
  33. plugin = this;
  34. PluginDescriptionFile pdfFile = this.getDescription();
  35. this.logger.info(pdfFile.getName() + " Version: "
  36. + pdfFile.getVersion() + " Has been Enabled!");
  37. PluginManager pm = getServer().getPluginManager();
  38. pm.registerEvents(this, this);
  39. getConfig().options().copyDefaults(true);
  40. saveConfig();
  41. }
  42.  
  43. @EventHandler
  44. public void onInventoryClick(InventoryClickEvent e) {
  45. ItemStack current = e.getCurrentItem();
  46. //gets current item
  47. ItemStack cursor = e.getCursor();
  48. //gets cursor
  49. if(e.getSlotType() == SlotType.ARMOR){
  50. //if the slot type is armor
  51. if (current != null && current.getItemMeta() != null && current.getItemMeta().getDisplayName() != null)
  52. // if the current item, item meta, and display are not null
  53. potion(e.getInventory().getHolder(), current);
  54. //gets the potion method, and gets the current item
  55. else if (cursor != null && cursor.getItemMeta() != null && cursor.getItemMeta().getDisplayName() != null)
  56. // if the cursor cursor meta, cursor display name are not null
  57. potion(e.getInventory().getHolder(), cursor);
  58. //gets the potion method, and gets the cursor
  59. } else if(e.getClick().isShiftClick()){
  60. // if it is shift click
  61. if (current != null && current.getItemMeta() != null && current.getItemMeta().getDisplayName() != null)
  62. potion(e.getInventory().getHolder(), current);
  63. //gets the potion method, and gets the current item
  64. } else if (e.getClick().isRightClick()){
  65. // if it is right click
  66. if (current != null && current.getItemMeta() != null && current.getItemMeta().getDisplayName() != null)
  67. potion(e.getInventory().getHolder(), current);
  68. //gets the potion method, and gets the current item
  69. }
  70. }
  71.  
  72.  
  73. private void potion(InventoryHolder holder, ItemStack item) {
  74. if(item.getItemMeta().getDisplayName().equals(ChatColor.GOLD + "Basic Mining Helmet")){
  75. //get the name of the helmet
  76. if (holder instanceof Player){
  77. Player p = (Player) holder;
  78. if (p.getInventory().getHelmet() == null || p.getInventory().getHelmet().getType() == Material.AIR) {
  79. //p.sendMessage("Adding potion...");
  80. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0));
  81. } else {
  82. //p.sendMessage("Removing potion...");
  83. p.removePotionEffect(PotionEffectType.NIGHT_VISION);
  84. }
  85. }
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment