Fix item duplication and teleport issues

This notably fixes the newest "Donkey Dupe", but also fixes a lot
of dupe bugs in general around nether portals and entity world transfer

We also fix item duplication generically by anytime we clone an item
to drop it on the ground, destroy the source item.

This avoid an itemstack ever existing twice in the world state pre
clean up stage.

So even if something NEW comes up, it would be impossible to drop the
same item twice because the source was destroyed.
This commit is contained in:
Aikar
2020-04-25 06:46:35 -04:00
parent 8a71e1c7da
commit 4b1f23c2e8
4 changed files with 133 additions and 102 deletions

View File

@@ -903,6 +903,11 @@ public class CraftEventFactory {
}
public static EntityDeathEvent callEntityDeathEvent(net.minecraft.world.entity.LivingEntity victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops) {
// Paper start
return CraftEventFactory.callEntityDeathEvent(victim, damageSource, drops, com.google.common.util.concurrent.Runnables.doNothing());
}
public static EntityDeathEvent callEntityDeathEvent(net.minecraft.world.entity.LivingEntity victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops, Runnable lootCheck) {
// Paper end
CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
CraftWorld world = (CraftWorld) entity.getWorld();
@@ -917,11 +922,13 @@ public class CraftEventFactory {
playDeathSound(victim, event);
// Paper end
victim.expToDrop = event.getDroppedExp();
lootCheck.run(); // Paper - advancement triggers before destroying items
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;
world.dropItem(entity.getLocation(), stack);
world.dropItem(entity.getLocation(), stack); // Paper - note: dropItem already clones due to this being bukkit -> NMS
if (stack instanceof CraftItemStack) stack.setAmount(0); // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe, but don't nuke bukkit stacks of manually added items
}
return event;