mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-16 18:46:12 +00:00
65 lines
3.8 KiB
Diff
65 lines
3.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Video <videogamesm12@gmail.com>
|
|
Date: Wed, 27 Jul 2022 22:30:39 -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 c3a5aa2cbfeef1d2841ef85d135a2f6e0a7a2f61..43174f72360e35e1b5112b0f2ecd7881c673c07c 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1939,6 +1939,18 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
}
|
|
// 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());
|
|
@@ -3456,17 +3468,24 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
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);
|
|
|
|
- if (this.player.level.isLoaded(blockposition)) {
|
|
- // 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
|
|
+ if (this.player.level.isLoaded(blockposition))
|
|
+ {
|
|
+ // 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
|
|
}
|
|
}
|
|
|