package fr.ethilvan.bukkit.drops.randomDrops;

import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;

import fr.aumgn.bukkitutils.util.Util;

public class CustomDrop {

    private String entityName;
    private int id;
    private short data;
    private String enchantmentName;
    private int enchantmentLevel;
    private int amountMin;
    private int amountMax;
    private double rate;

    public CustomDrop(String entityName, ItemStack drop, int amountMin,
            int amountMax, double rate, Enchantment enchantment,
            int enchantmentLevel) {
        this.entityName = entityName;
        this.id = drop.getTypeId();
        this.data = drop.getDurability();
        this.amountMin = amountMin;
        this.amountMax = amountMax;
        this.rate = rate;
        this.enchantmentName = enchantment.getName();
        this.enchantmentLevel = enchantmentLevel;
    }

    public CustomDrop(String entityName, ItemStack drop, int amountMin,
            int amountMax, double rate) {
        this.entityName = entityName;
        this.id = drop.getTypeId();
        this.data = drop.getDurability();
        this.amountMin = amountMin;
        this.amountMax = amountMax;
        this.rate = rate;
    }

    public ItemStack toItemStack() {
        int randomAmount = Util.getRandom().nextInt(amountMin, amountMax);
        ItemStack stack = new ItemStack(id, randomAmount, data);
        if (enchantmentName != null || enchantmentLevel != 0 
                || Enchantment.getByName(enchantmentName) != null) {
                stack.addEnchantment(Enchantment.getByName(enchantmentName),
                        enchantmentLevel);
        }
        return stack;
    }

    public EntityType getEntityType() {
        return EntityType.fromName(entityName);
    }

    public String getEntityName() {
        return entityName;
    }

    public boolean drop(EntityType entity) {
        return getEntityType() == entity 
                && Util.getRandom().nextDouble(100) < rate - 1;
    }
}

@@ -587,68 +587,8 @@
 rate
-, Enchantment enchantment,%0D%0A            int enchantmentLevel
 ) %7B%0D
@@ -812,114 +812,8 @@
 e;%0D%0A
-        this.enchantmentName = enchantment.getName();%0D%0A        this.enchantmentLevel = enchantmentLevel;%0D%0A
     
@@ -932,145 +932,104 @@
 rate
-) %7B%0D%0A        this.entityName = entityName;%0D%0A        this.id = drop.getTypeId();%0D%0A        this.data = drop.getDurability();%0D%0A        this.
+, Enchantment enchantment,%0D%0A            int enchantmentLevel) %7B%0D%0A        this(entityName, drop, 
 amou
@@ -1029,34 +1029,33 @@
 p, amountMin
- =
+,
  amountM
 in;%0D%0A       
@@ -1034,34 +1034,41 @@
 ountMin, amountM
-in
+ax, rate)
 ;%0D%0A        this.
@@ -1071,56 +1071,98 @@
 his.
-amountMax = amountMax;%0D%0A        this.rate = rate
+enchantmentName = enchantment.getName();%0D%0A        this.enchantmentLevel = enchantmentLevel
 ;%0D%0A 
@@ -1409,17 +1409,19 @@
 vel != 0
- 
+) %7B
 %0D%0A      
@@ -1430,14 +1430,29 @@
     
-    %7C%7C
+Enchantment enchant =
  Enc
@@ -1490,19 +1490,9 @@
 ame)
- != null) %7B
+;
 %0D%0A  
@@ -1501,19 +1501,36 @@
         
-   
+if (enchant != null)
  stack.a
@@ -1547,46 +1547,15 @@
 ent(
-Enchantment.getByName(enchantmentName)
+enchant
 ,%0D%0A 

Clean up CustomDrop.java