Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/server/0729-Reset-placed-block-on-exception.patch

39 Zeilen
2.6 KiB
Diff

2022-01-10 14:03:18 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Nassim Jahnke <nassim@njahnke.dev>
2022-01-10 14:03:18 +01:00
Date: Fri, 7 Jan 2022 11:45:15 +0100
Subject: [PATCH] Reset placed block on exception
diff --git a/src/main/java/net/minecraft/world/item/BlockItem.java b/src/main/java/net/minecraft/world/item/BlockItem.java
index e68b7a1b03783e4f9de24c5ae8773fc359bd2d37..daf093518f1daf598c858cfaf48357255a1fb0cf 100644
2022-01-10 14:03:18 +01:00
--- a/src/main/java/net/minecraft/world/item/BlockItem.java
+++ b/src/main/java/net/minecraft/world/item/BlockItem.java
2022-12-07 22:35:34 +01:00
@@ -80,6 +80,7 @@ public class BlockItem extends Item {
if (this instanceof PlaceOnWaterBlockItem || this instanceof SolidBucketItem) {
2022-01-10 14:03:18 +01:00
blockstate = org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos());
}
+ final org.bukkit.block.BlockState oldBlockstate = blockstate != null ? blockstate : org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockactioncontext1.getLevel(), blockactioncontext1.getClickedPos()); // Paper - Reset placed block on exception
2022-01-10 14:03:18 +01:00
// CraftBukkit end
if (iblockdata == null) {
2022-12-07 22:35:34 +01:00
@@ -95,7 +96,19 @@ public class BlockItem extends Item {
2022-01-10 14:03:18 +01:00
if (iblockdata1.is(iblockdata.getBlock())) {
iblockdata1 = this.updateBlockStateFromTag(blockposition, world, itemstack, iblockdata1);
+ // Paper start - Reset placed block on exception
2022-01-10 14:03:18 +01:00
+ try {
this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1);
+ } catch (Exception e) {
+ oldBlockstate.update(true, false);
+ if (entityhuman instanceof ServerPlayer player) {
+ org.apache.logging.log4j.LogManager.getLogger().error("Player {} tried placing invalid block", player.getScoreboardName(), e);
+ player.getBukkitEntity().kickPlayer("Packet processing error");
+ return InteractionResult.FAIL;
+ }
+ throw e; // Rethrow exception if not placed by a player
+ }
+ // Paper end - Reset placed block on exception
2022-01-10 14:03:18 +01:00
iblockdata1.getBlock().setPlacedBy(world, blockposition, iblockdata1, entityhuman, itemstack);
// CraftBukkit start
if (blockstate != null) {