Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.81 KB | None | 0 0
  1. package com.lostcraft.net.alcohol;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.logging.Logger;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.Server;
  11. import org.bukkit.World;
  12. import org.bukkit.block.Block;
  13. import org.bukkit.configuration.file.FileConfiguration;
  14. import org.bukkit.configuration.file.FileConfigurationOptions;
  15. import org.bukkit.enchantments.Enchantment;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.event.EventHandler;
  18. import org.bukkit.event.Listener;
  19. import org.bukkit.event.block.Action;
  20. import org.bukkit.event.player.PlayerInteractEvent;
  21. import org.bukkit.event.player.PlayerItemConsumeEvent;
  22. import org.bukkit.inventory.ItemStack;
  23. import org.bukkit.inventory.meta.ItemMeta;
  24. import org.bukkit.plugin.PluginDescriptionFile;
  25. import org.bukkit.plugin.PluginManager;
  26. import org.bukkit.plugin.java.JavaPlugin;
  27. import org.bukkit.potion.PotionEffect;
  28. import org.bukkit.potion.PotionEffectType;
  29.  
  30. public class Alcohol extends JavaPlugin
  31.   implements Listener
  32. {
  33.   private String alcoholName = "Beer";
  34.   private String alcoholLore = "&3A tasty brew";
  35.  
  36.   private int ingredient = 269;
  37.   private int ingredientAmount = 4;
  38.   private int alcoholAmount = 4;
  39.   private ItemStack alcohol;
  40.   private Server server;
  41.   private PluginDescriptionFile pdf;
  42.   private List<String> lore;
  43.  
  44.   public void onEnable()
  45.   {
  46.     this.server = getServer();
  47.     this.pdf = getDescription();
  48.  
  49.     FileConfiguration config = getConfig();
  50.  
  51.     config.addDefault("Alcohol-Name", this.alcoholName);
  52.     config.addDefault("Alcohol-Lore", this.alcoholLore);
  53.     config.addDefault("Ingredient", Integer.valueOf(this.ingredient));
  54.     config.addDefault("Ingredient-Amount", Integer.valueOf(this.ingredientAmount));
  55.     config.addDefault("Alcohol-Amount", Integer.valueOf(this.alcoholAmount));
  56.  
  57.     config.options().copyDefaults(true);
  58.     saveConfig();
  59.  
  60.     this.alcoholName = ChatColor.translateAlternateColorCodes('&', config.getString("Alcohol-Name"));
  61.     this.alcoholLore = ChatColor.translateAlternateColorCodes('&', config.getString("Alcohol-Lore"));
  62.     this.ingredient = config.getInt("Ingredient");
  63.     this.ingredientAmount = config.getInt("Ingredient-Amount");
  64.     this.alcoholAmount = config.getInt("Alcohol-Amount");
  65.  
  66.     this.alcohol = new ItemStack(373, 1);
  67.  
  68.     ItemMeta meta = this.alcohol.getItemMeta();
  69.  
  70.     meta.setDisplayName(ChatColor.RESET + this.alcoholName);
  71.     meta.setLore(Arrays.asList(new String[] { ChatColor.RESET + this.alcoholLore }));
  72.     for (Enchantment enchant : meta.getEnchants().keySet())
  73.     {
  74.       meta.removeEnchant(enchant);
  75.     }
  76.  
  77.     this.alcohol.setItemMeta(meta);
  78.  
  79.     this.lore = this.alcohol.getItemMeta().getLore();
  80.  
  81.     this.server.getPluginManager().registerEvents(this, this);
  82.  
  83.     getLogger().info(getName() + " version " + this.pdf.getVersion() + " has been enabled!");
  84.   }
  85.  
  86.   public void onDisable()
  87.   {
  88.     getLogger().info(getName() + " version " + this.pdf.getVersion() + " has been disabled!");
  89.   }
  90.  
  91.   @EventHandler
  92.   public void onCauldronInteract(PlayerInteractEvent event)
  93.   {
  94.     if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
  95.     {
  96.       Block block = event.getClickedBlock();
  97.  
  98.       if (block.getType() == Material.CAULDRON)
  99.       {
  100.         Player player = event.getPlayer();
  101.         ItemStack inHand = player.getItemInHand();
  102.  
  103.         if (inHand != null)
  104.         {
  105.           if (inHand.getTypeId() == this.ingredient)
  106.           {
  107.             if (block.getData() > 0)
  108.             {
  109.               if (inHand.getAmount() == this.ingredientAmount)
  110.               {
  111.                 player.setItemInHand(new ItemStack(Material.AIR, 0));
  112.               }
  113.               else if (inHand.getAmount() > this.ingredientAmount)
  114.               {
  115.                 inHand.setAmount(inHand.getAmount() - this.ingredientAmount);
  116.               }
  117.               else
  118.               {
  119.                 return;
  120.               }
  121.  
  122.               block.setData((byte)(block.getData() - 1));
  123.               for (int i = 0; i < this.ingredientAmount; i++)
  124.               {
  125.                 block.getWorld().dropItemNaturally(block.getLocation().add(0.0D, 1.0D, 0.0D), this.alcohol);
  126.               }
  127.             }
  128.           }
  129.         }
  130.       }
  131.     }
  132.   }
  133.  
  134.   @EventHandler
  135.   public void onBeerDrink(PlayerItemConsumeEvent event)
  136.   {
  137.     if (event.getItem().hasItemMeta())
  138.     {
  139.       if (event.getItem().getItemMeta().hasLore())
  140.       {
  141.         if (event.getItem().getItemMeta().getLore().equals(this.lore))
  142.         {
  143.           Player player = event.getPlayer();
  144.           player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 5));
  145.           player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 400, 2));
  146.         }
  147.       }
  148.     }
  149.   }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement