2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-04-25 10:52:30 +00:00
From: Aikar <aikar@aikar.co>
Date: Sat, 25 Apr 2020 06:46:35 -0400
Subject: [PATCH] Fix numerous item duplication issues 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.
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2020-09-19 11:29:53 +00:00
index 063c5ce566644a59652dec9b306f9f9282560589..7df29df2d6023e549e1fba0b5b1d1c1abcf92f8b 100644
2020-04-25 10:52:30 +00:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2020-09-19 11:29:53 +00:00
@@ -1879,11 +1879,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2020-04-25 10:52:30 +00:00
} else {
// CraftBukkit start - Capture drops for death event
if (this instanceof EntityLiving && !((EntityLiving) this).forceDrops) {
- ((EntityLiving) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack));
+ ((EntityLiving) this).drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)); // Paper - mirror so we can destroy it later
return null;
}
// CraftBukkit end
- EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + (double) f, this.locZ(), itemstack);
+ EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY() + (double) f, this.locZ(), itemstack.cloneItemStack()); // Paper - clone so we can destroy original
+ itemstack.setCount(0); // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe
entityitem.defaultPickupDelay();
// CraftBukkit start
2020-09-19 11:29:53 +00:00
@@ -2531,6 +2532,12 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2020-04-25 10:52:30 +00:00
@Nullable
2020-06-26 01:53:21 +00:00
public Entity teleportTo(WorldServer worldserver, BlockPosition location) {
2020-04-25 10:52:30 +00:00
// CraftBukkit end
+ // Paper start - fix bad state entities causing dupes
+ if (!isAlive() || !valid) {
2020-06-26 01:53:21 +00:00
+ LOGGER.warn("Illegal Entity Teleport " + this + " to " + worldserver + ":" + location, new Throwable());
2020-04-25 10:52:30 +00:00
+ return null;
+ }
+ // Paper end
2020-06-26 01:53:21 +00:00
if (this.world instanceof WorldServer && !this.dead) {
2020-04-25 10:52:30 +00:00
this.world.getMethodProfiler().enter("changeDimension");
2020-06-26 01:53:21 +00:00
// CraftBukkit start
2020-09-19 11:29:53 +00:00
@@ -2566,7 +2573,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2020-08-25 02:22:08 +00:00
entity.bukkitEntity = this.getBukkitEntity();
2020-05-16 08:31:53 +00:00
2020-08-25 02:22:08 +00:00
if (this instanceof EntityInsentient) {
- ((EntityInsentient) this).unleash(true, false); // Unleash to prevent duping of leads.
+ ((EntityInsentient) this).unleash(true, true); // Paper drop lead
}
// CraftBukkit end
2020-05-16 08:31:53 +00:00
}
2020-09-19 11:29:53 +00:00
@@ -2686,7 +2693,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2020-04-25 10:52:30 +00:00
}
public boolean canPortal() {
- return true;
+ return isAlive() && valid; // Paper
}
public float a(Explosion explosion, IBlockAccess iblockaccess, BlockPosition blockposition, IBlockData iblockdata, Fluid fluid, float f) {
diff --git a/src/main/java/net/minecraft/server/EntityArmorStand.java b/src/main/java/net/minecraft/server/EntityArmorStand.java
2020-09-10 23:47:58 +00:00
index 5c3d2bbf7b2ae22347d251c90c85388779c2cd44..937fa3c69a5cba2fc2fa4506dc34ff8a37dae19c 100644
2020-04-25 10:52:30 +00:00
--- a/src/main/java/net/minecraft/server/EntityArmorStand.java
+++ b/src/main/java/net/minecraft/server/EntityArmorStand.java
2020-08-25 02:22:08 +00:00
@@ -559,7 +559,7 @@ public class EntityArmorStand extends EntityLiving {
2020-04-25 10:52:30 +00:00
for (i = 0; i < this.handItems.size(); ++i) {
itemstack = (ItemStack) this.handItems.get(i);
if (!itemstack.isEmpty()) {
- drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)); // CraftBukkit - add to drops // Paper - mirror so we can destroy it later - though this call site was safe
2020-06-26 01:53:21 +00:00
this.handItems.set(i, ItemStack.b);
2020-04-25 10:52:30 +00:00
}
}
2020-08-25 02:22:08 +00:00
@@ -567,7 +567,7 @@ public class EntityArmorStand extends EntityLiving {
2020-04-25 10:52:30 +00:00
for (i = 0; i < this.armorItems.size(); ++i) {
itemstack = (ItemStack) this.armorItems.get(i);
if (!itemstack.isEmpty()) {
- drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
+ drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)); // CraftBukkit - add to drops // Paper - mirror so we can destroy it later - though this call site was safe
2020-06-26 01:53:21 +00:00
this.armorItems.set(i, ItemStack.b);
2020-04-25 10:52:30 +00:00
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2020-10-14 14:00:43 +00:00
index 2f1fa0587636c594d3f15fa6bdfabaca3d98017c..9127df12252bbd619d97db996a88ae91da9d3345 100644
2020-04-25 10:52:30 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2020-09-02 09:12:25 +00:00
@@ -811,7 +811,8 @@ public class CraftEventFactory {
2020-04-25 10:52:30 +00:00
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
2020-05-02 01:44:06 +00:00
+ 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
2020-04-25 10:52:30 +00:00
}
return event;