Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.lostcraft.net.alcohol;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Map;
- import java.util.logging.Logger;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.FileConfigurationOptions;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerItemConsumeEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- public class Alcohol extends JavaPlugin
- implements Listener
- {
- private String alcoholName = "Beer";
- private String alcoholLore = "&3A tasty brew";
- private int ingredient = 269;
- private int ingredientAmount = 4;
- private int alcoholAmount = 4;
- private ItemStack alcohol;
- private Server server;
- private PluginDescriptionFile pdf;
- private List<String> lore;
- public void onEnable()
- {
- this.server = getServer();
- this.pdf = getDescription();
- FileConfiguration config = getConfig();
- config.addDefault("Alcohol-Name", this.alcoholName);
- config.addDefault("Alcohol-Lore", this.alcoholLore);
- config.addDefault("Ingredient", Integer.valueOf(this.ingredient));
- config.addDefault("Ingredient-Amount", Integer.valueOf(this.ingredientAmount));
- config.addDefault("Alcohol-Amount", Integer.valueOf(this.alcoholAmount));
- config.options().copyDefaults(true);
- saveConfig();
- this.alcoholName = ChatColor.translateAlternateColorCodes('&', config.getString("Alcohol-Name"));
- this.alcoholLore = ChatColor.translateAlternateColorCodes('&', config.getString("Alcohol-Lore"));
- this.ingredient = config.getInt("Ingredient");
- this.ingredientAmount = config.getInt("Ingredient-Amount");
- this.alcoholAmount = config.getInt("Alcohol-Amount");
- this.alcohol = new ItemStack(373, 1);
- ItemMeta meta = this.alcohol.getItemMeta();
- meta.setDisplayName(ChatColor.RESET + this.alcoholName);
- meta.setLore(Arrays.asList(new String[] { ChatColor.RESET + this.alcoholLore }));
- for (Enchantment enchant : meta.getEnchants().keySet())
- {
- meta.removeEnchant(enchant);
- }
- this.alcohol.setItemMeta(meta);
- this.lore = this.alcohol.getItemMeta().getLore();
- this.server.getPluginManager().registerEvents(this, this);
- getLogger().info(getName() + " version " + this.pdf.getVersion() + " has been enabled!");
- }
- public void onDisable()
- {
- getLogger().info(getName() + " version " + this.pdf.getVersion() + " has been disabled!");
- }
- @EventHandler
- public void onCauldronInteract(PlayerInteractEvent event)
- {
- if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
- {
- Block block = event.getClickedBlock();
- if (block.getType() == Material.CAULDRON)
- {
- Player player = event.getPlayer();
- ItemStack inHand = player.getItemInHand();
- if (inHand != null)
- {
- if (inHand.getTypeId() == this.ingredient)
- {
- if (block.getData() > 0)
- {
- if (inHand.getAmount() == this.ingredientAmount)
- {
- player.setItemInHand(new ItemStack(Material.AIR, 0));
- }
- else if (inHand.getAmount() > this.ingredientAmount)
- {
- inHand.setAmount(inHand.getAmount() - this.ingredientAmount);
- }
- else
- {
- return;
- }
- block.setData((byte)(block.getData() - 1));
- for (int i = 0; i < this.ingredientAmount; i++)
- {
- block.getWorld().dropItemNaturally(block.getLocation().add(0.0D, 1.0D, 0.0D), this.alcohol);
- }
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void onBeerDrink(PlayerItemConsumeEvent event)
- {
- if (event.getItem().hasItemMeta())
- {
- if (event.getItem().getItemMeta().hasLore())
- {
- if (event.getItem().getItemMeta().getLore().equals(this.lore))
- {
- Player player = event.getPlayer();
- player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 5));
- player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 400, 2));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement