package com.colt.HeadRegen;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.java.JavaPlugin;

public class HeadRegen extends JavaPlugin {
	
	public void onEnable() {
		saveDefaultConfig();
	}
	
	public void onDisable() {
		skulls.clear();
		lore.clear();
	}
	
	List<String> lore = new ArrayList<String>();
	ArrayList<ItemStack> skulls = new ArrayList<ItemStack>();
	
	@EventHandler
	public void click(PlayerInteractEvent e) {
	Player p = e.getPlayer();
    	if(!p.hasPermission("headregen.use")) {
    		String msg = ChatColor.translateAlternateColorCodes('&', getConfig().getString("noperms"));
    		p.sendMessage(msg);
    	} else {
		if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
			if(skulls.contains(e.getItem())) {
				Inventory inv = p.getInventory();		
				inv.removeItem(e.getItem());
				skulls.remove(e.getItem());
				p.setHealth(p.getHealth() + getConfig().getDouble("Hearts"));
			}
		}
    	}
	}
	
    @EventHandler
    public void kill(PlayerDeathEvent e) {
    	Player p = (Player)e.getEntity();
    	List<String> worlds = getConfig().getStringList("worlds");
    	for(String w : worlds) {
    		if(p.getWorld().equals(w)) {	
    			if(p.hasPermission("headregen.use")) {
    				lore.clear();
    				lore.add(ChatColor.AQUA + "Right Click for a +" + ChatColor.GREEN + "" + getConfig().getDouble("Hearts") + "" + ChatColor.AQUA + " Heart Regen!");
    				ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)SkullType.PLAYER.ordinal());
    				SkullMeta meta = (SkullMeta)skull.getItemMeta();
    				meta.setOwner(p.getName());
    				meta.setDisplayName(p.getName());
    				meta.setLore(lore);
    				skull.setItemMeta(meta);
    				skulls.add(skull);
    				p.getWorld().dropItemNaturally(p.getLocation(), skull);
    			}
    		}
    	}
    }
}

@@ -74,16 +74,42 @@
 .List;%0A%0A
+import org.bukkit.Bukkit;%0A
 import o
@@ -129,16 +129,16 @@
 tColor;%0A
-
 import o
@@ -186,16 +186,41 @@
 llType;%0A
+import org.bukkit.World;%0A
 import o
@@ -918,16 +918,17 @@
 nt e) %7B%0A
+%09
 %09Player 
@@ -942,24 +942,24 @@
 etPlayer();%0A
-
     %09if(!p.h
@@ -1752,20 +1752,54 @@
 rlds) %7B%0A
-    
+%09%09%09World world = Bukkit.getWorld(w);%0A%09
 %09%09if(p.g
@@ -1820,13 +1820,16 @@
 ls(w
+orld
 )) %7B
-%09
 %0A   

Update HeadRegen.java