diff --git a/pom.xml b/pom.xml
index 7eb4931..2c152b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
io.github.totemo
Doppelganger
- 0.9.0
+ 0.9.1
jar
Doppelganger
diff --git a/src/io/github/totemo/doppelganger/Doppelganger.java b/src/io/github/totemo/doppelganger/Doppelganger.java
index 613e465..dd1ed9b 100644
--- a/src/io/github/totemo/doppelganger/Doppelganger.java
+++ b/src/io/github/totemo/doppelganger/Doppelganger.java
@@ -1,6 +1,7 @@
package io.github.totemo.doppelganger;
import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -170,10 +171,13 @@ public void onBlockPlace(BlockPlaceEvent event)
// --------------------------------------------------------------------------
/**
- * Bukkit or vanilla Minecraft doesn't always drop equipment, when the drop
- * chance is 1.0 (or more). Try to work around that by moving the equipment
- * into the drops. Normally the equipment is not part of the drops. It is
- * dropped by some other mechanism.
+ * Vanilla Minecraft doesn't always drop equipment when the drop chance is 1.0
+ * (or more). Try to work around that by moving the equipment into the drops
+ * if it is not already there.
+ *
+ * In Bukkit versions prior to 1.7.9, the equipment was not part of the drops
+ * list in the EntityDeathEvent. Bukkit fixed that issue with the API, but had
+ * to retain vanilla's handling of drop probabilities, which is still faulty.
*
* This handler will process any entity death, but naturally spawned monsters
* probably won't have a (near) 1.0 drop chance for the their equipment, and
@@ -182,39 +186,61 @@ public void onBlockPlace(BlockPlaceEvent event)
@EventHandler(ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event)
{
+ final float NEAR_UNITY = 0.999f;
boolean forcedDrops = false;
if (event.getEntity() instanceof Creature)
{
EntityEquipment equipment = event.getEntity().getEquipment();
- if (equipment.getHelmetDropChance() > 0.999f)
+ List drops = event.getDrops();
+ if (equipment.getHelmetDropChance() > NEAR_UNITY)
{
- event.getDrops().add(equipment.getHelmet());
- equipment.setHelmet(null);
forcedDrops = true;
+ ItemStack helmet = equipment.getHelmet();
+ if (helmet != null && !drops.contains(helmet))
+ {
+ drops.add(helmet);
+ equipment.setHelmet(null);
+ }
}
- if (equipment.getChestplateDropChance() > 0.999f)
+ if (equipment.getChestplateDropChance() > NEAR_UNITY)
{
- event.getDrops().add(equipment.getChestplate());
- equipment.setChestplate(null);
forcedDrops = true;
+ ItemStack chestplate = equipment.getChestplate();
+ if (chestplate != null && !drops.contains(chestplate))
+ {
+ drops.add(chestplate);
+ equipment.setChestplate(null);
+ }
}
- if (equipment.getLeggingsDropChance() > 0.999f)
+ if (equipment.getLeggingsDropChance() > NEAR_UNITY)
{
- event.getDrops().add(equipment.getLeggings());
- equipment.setLeggings(null);
forcedDrops = true;
+ ItemStack leggings = equipment.getLeggings();
+ if (leggings != null && !drops.contains(leggings))
+ {
+ drops.add(leggings);
+ equipment.setLeggings(null);
+ }
}
- if (equipment.getBootsDropChance() > 0.999f)
+ if (equipment.getBootsDropChance() > NEAR_UNITY)
{
- event.getDrops().add(equipment.getBoots());
- equipment.setBoots(null);
forcedDrops = true;
+ ItemStack boots = equipment.getBoots();
+ if (boots != null && !drops.contains(boots))
+ {
+ drops.add(boots);
+ equipment.setBoots(null);
+ }
}
- if (equipment.getItemInHandDropChance() > 0.999f)
+ if (equipment.getItemInHandDropChance() > NEAR_UNITY)
{
- event.getDrops().add(equipment.getItemInHand());
- equipment.setItemInHand(null);
forcedDrops = true;
+ ItemStack itemInHand = equipment.getItemInHand();
+ if (itemInHand != null && !drops.contains(itemInHand))
+ {
+ drops.add(itemInHand);
+ equipment.setItemInHand(null);
+ }
}
}