From b9c09dbfcb41df6af10e05f1e49006534bcb8d6c Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sat, 11 Jun 2022 23:09:00 -0500 Subject: [PATCH] Create 0022-Validate-coordinates-before-attempting-to-get-block-.patch --- ...ates-before-attempting-to-get-block-.patch | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 patches/server/0022-Validate-coordinates-before-attempting-to-get-block-.patch diff --git a/patches/server/0022-Validate-coordinates-before-attempting-to-get-block-.patch b/patches/server/0022-Validate-coordinates-before-attempting-to-get-block-.patch new file mode 100644 index 0000000..7ca2b28 --- /dev/null +++ b/patches/server/0022-Validate-coordinates-before-attempting-to-get-block-.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Telesphoreo +Date: Sat, 11 Jun 2022 23:05:12 -0500 +Subject: [PATCH] Validate coordinates before attempting to get block entities + when handling Creative Inventory packets + + +diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +index 630a762b71861bfe21c47a11d4fe05e1a3b7d339..f13b4e880c179e4f6e76cc0a2655b9f148a08290 100644 +--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java ++++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +@@ -1837,6 +1837,18 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser + } + // Spigot end + ++ // Scissors start - Readd the following Paper code ++ // Paper start ++ private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6; ++ private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7; ++ private boolean isOutsideOfReach(double x, double y, double z) { ++ Location eyeLoc = this.getCraftPlayer().getEyeLocation(); ++ double reachDistance = org.bukkit.util.NumberConversions.square(eyeLoc.getX() - x) + org.bukkit.util.NumberConversions.square(eyeLoc.getY() - y) + org.bukkit.util.NumberConversions.square(eyeLoc.getZ() - z); ++ return reachDistance > (this.getCraftPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED); ++ } ++ // Paper end ++ // Scissors end ++ + @Override + public void handleUseItemOn(ServerboundUseItemOnPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); +@@ -3182,15 +3194,22 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser + if (!itemstack.isEmpty() && nbttagcompound != null && nbttagcompound.contains("x") && nbttagcompound.contains("y") && nbttagcompound.contains("z") && this.player.getBukkitEntity().hasPermission("minecraft.nbt.copy")) { // Spigot + BlockPos blockposition = BlockEntity.getPosFromTag(nbttagcompound); + // Paper start +- BlockEntity tileentity = null; +- if (this.player.distanceToSqr(blockposition.getX(), blockposition.getY(), blockposition.getZ()) < 32 * 32 && this.player.getLevel().isLoadedAndInBounds(blockposition)) { +- tileentity = this.player.level.getBlockEntity(blockposition); +- } +- // Paper end ++ // Scissors start - Validate coordinates and whether the player can reach them ++ if (Level.isInSpawnableBounds(blockposition) && !isOutsideOfReach(blockposition.getX(), blockposition.getY(), blockposition.getZ())) ++ { ++ BlockEntity tileentity = null; ++ if (this.player.distanceToSqr(blockposition.getX(), blockposition.getY(), blockposition.getZ()) < 32 * 32 && this.player.getLevel().isLoadedAndInBounds(blockposition)) ++ { ++ tileentity = this.player.level.getBlockEntity(blockposition); ++ } ++ // Paper end + +- if (tileentity != null) { +- tileentity.saveToItem(itemstack); ++ if (tileentity != null) ++ { ++ tileentity.saveToItem(itemstack); ++ } + } ++ // Scissors end + } + + boolean flag1 = packet.getSlotNum() >= 1 && packet.getSlotNum() <= 45;