From 0ac53efb30de4f07cc673c37d5a24b24b750395b Mon Sep 17 00:00:00 2001 From: Toon Schoenmakers Date: Wed, 28 Oct 2020 21:39:02 +0100 Subject: [PATCH] Avoid crashing clients when fishing loot is empty, Fixes #4235 (#4681) --- ...ling-up-when-item-stack-is-empty-in-.patch | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Spigot-Server-Patches/0594-Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch diff --git a/Spigot-Server-Patches/0594-Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch b/Spigot-Server-Patches/0594-Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch new file mode 100644 index 000000000..9bc4da429 --- /dev/null +++ b/Spigot-Server-Patches/0594-Avoid-error-bubbling-up-when-item-stack-is-empty-in-.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Toon Schoenmakers +Date: Fri, 23 Oct 2020 15:01:44 +0200 +Subject: [PATCH] Avoid error bubbling up when item stack is empty in fishing + loot + +This can realistically only happen if there's custom loot active on fishing +which can return 0 items. This would disconnect the player who's fishing. + +diff --git a/src/main/java/net/minecraft/server/EntityFishingHook.java b/src/main/java/net/minecraft/server/EntityFishingHook.java +index b6cace72ab2f3389408a5e528981fcff3b511180..25ec9e9319ca7badde845906679d78934eaf0ad6 100644 +--- a/src/main/java/net/minecraft/server/EntityFishingHook.java ++++ b/src/main/java/net/minecraft/server/EntityFishingHook.java +@@ -433,9 +433,15 @@ public class EntityFishingHook extends IProjectile { + + while (iterator.hasNext()) { + ItemStack itemstack1 = (ItemStack) iterator.next(); +- EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY(), this.locZ(), itemstack1); ++ // Paper start, new EntityItem would throw if for whatever reason (mostly shitty datapacks) the itemstack1 turns out to be empty ++ // if the item stack is empty we instead just have our entityitem as null ++ EntityItem entityitem = null; ++ if (!itemstack1.isEmpty()) { ++ entityitem = new EntityItem(this.world, this.locX(), this.locY(), this.locZ(), itemstack1); ++ } ++ // Paper end + // CraftBukkit start +- PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH); ++ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem != null ? entityitem.getBukkitEntity() : null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH); // Paper - entityitem may be null + playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1); + this.world.getServer().getPluginManager().callEvent(playerFishEvent); + +@@ -448,8 +454,12 @@ public class EntityFishingHook extends IProjectile { + double d2 = entityhuman.locZ() - this.locZ(); + double d3 = 0.1D; + +- entityitem.setMot(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D); +- this.world.addEntity(entityitem); ++ // Paper start, entity item can be null, so we need to check against this ++ if (entityitem != null) { ++ entityitem.setMot(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D); ++ this.world.addEntity(entityitem); ++ } ++ // Paper end + // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop() + if (playerFishEvent.getExpToDrop() > 0) { + entityhuman.world.addEntity(new EntityExperienceOrb(entityhuman.world, entityhuman.locX(), entityhuman.locY() + 0.5D, entityhuman.locZ() + 0.5D, playerFishEvent.getExpToDrop(), org.bukkit.entity.ExperienceOrb.SpawnReason.FISHING, this.getOwner(), this)); // Paper