3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 19:10:09 +01:00
Paper/patches/api/0462-Clone-mutables-to-prevent-unexpected-issues.patch
Jake Potrebic ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) (#10691)
Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
fa99e752 PR-1007: Add ItemMeta#getAsComponentString()
94a91782 Fix copy-pasted BlockType.Typed documentation
9b34ac8c Largely restore deprecated PotionData API
51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5
702d15fe Fix Javadoc reference
42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them
237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it
8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more
87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent

CraftBukkit Changes:
4af0f22e8 SPIGOT-7664: Item meta should prevail over block states
c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot
124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects
66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API
6118e5398 Fix regression listening to minecraft:brand custom payloads
c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check
12360a7ec Remove unused imports
147b098b4 PR-1397: Add ItemMeta#getAsComponentString()
428aefe0e Largely restore deprecated PotionData API
afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them
8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it
441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets
0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource
f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA
2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more
c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent
741b84480 PR-1390: Improve internal handling of damage sources
0364df4e1 SPIGOT-7657: Error when loading angry entities
2024-05-11 23:48:37 +02:00

152 Zeilen
6.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 16 Mar 2024 11:10:48 -0700
Subject: [PATCH] Clone mutables to prevent unexpected issues
There are lots of locations in the API where mutable
types are not cloned, either on return or when passed
as a parameter and assigned to a field, which can cause
unexpected behaviors. Let this be a lesson to use
immutable types for simple things Location, Vector, and
others.
diff --git a/src/main/java/org/bukkit/event/block/BlockCanBuildEvent.java b/src/main/java/org/bukkit/event/block/BlockCanBuildEvent.java
index 08d09c2a92d8aa6adf6610cc05905d58a76fce1f..c74ac0cb004aa219ce2f761969a4bb46cb7c9160 100644
--- a/src/main/java/org/bukkit/event/block/BlockCanBuildEvent.java
+++ b/src/main/java/org/bukkit/event/block/BlockCanBuildEvent.java
@@ -102,7 +102,7 @@ public class BlockCanBuildEvent extends BlockEvent {
*/
@NotNull
public BlockData getBlockData() {
- return blockData;
+ return blockData.clone(); // Paper - clone because mutation isn't used
}
/**
diff --git a/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java b/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java
index 1a9575ad4c81aefa5ef0b927f6ac8f7064b55c49..24e1a49e48dd8f9eb2515b2ffe472a0c4d2bc09b 100644
--- a/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityChangeBlockEvent.java
@@ -61,7 +61,7 @@ public class EntityChangeBlockEvent extends EntityEvent implements Cancellable {
*/
@NotNull
public BlockData getBlockData() {
- return to;
+ return to.clone(); // Paper - clone because mutation isn't used
}
@NotNull
diff --git a/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java b/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java
index 099efafa14c10910e4ed04abb1823f0c1a96b6a6..8506fa03293c575c35b55b052224807470fdbd98 100644
--- a/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityExplodeEvent.java
@@ -59,7 +59,7 @@ public class EntityExplodeEvent extends EntityEvent implements Cancellable {
*/
@NotNull
public Location getLocation() {
- return location;
+ return location.clone(); // Paper - clone to avoid changes
}
/**
diff --git a/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java b/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
index 6818e9f0ba32ca1a1e612703f7526b29f5a6438f..e4e3d2e22c28ef251d76c48ade267b4eb3749e7d 100644
--- a/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityPortalEnterEvent.java
@@ -24,7 +24,7 @@ public class EntityPortalEnterEvent extends EntityEvent {
*/
@NotNull
public Location getLocation() {
- return location;
+ return location.clone(); // Paper - clone to avoid changes
}
@NotNull
diff --git a/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java b/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java
index 6fc66197eb2c5d59c70d8d028b7963748371edbe..2bb29fa449cd6c90b52d2786ed15b6154d591607 100644
--- a/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java
+++ b/src/main/java/org/bukkit/event/entity/ItemDespawnEvent.java
@@ -46,7 +46,7 @@ public class ItemDespawnEvent extends EntityEvent implements Cancellable {
*/
@NotNull
public Location getLocation() {
- return location;
+ return location.clone(); // Paper - clone to avoid changes
}
@NotNull
diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java
index d0a437bd8aeec18f800893f51ece06deb0c8972c..50fad23cf4d9f591b12a9eaebeb4e26f18e8528d 100644
--- a/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java
+++ b/src/main/java/org/bukkit/event/vehicle/VehicleBlockCollisionEvent.java
@@ -31,7 +31,7 @@ public class VehicleBlockCollisionEvent extends VehicleCollisionEvent {
*/
@NotNull
public org.bukkit.util.Vector getVelocity() {
- return velocity;
+ return velocity.clone();
}
// Paper end
diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java
index 7bfb84d3948c773e943374316ea25a19288ec7d0..fc4cf7b21b24fe38617fa150f697bc29da76754e 100644
--- a/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java
+++ b/src/main/java/org/bukkit/event/vehicle/VehicleMoveEvent.java
@@ -27,7 +27,7 @@ public class VehicleMoveEvent extends VehicleEvent {
*/
@NotNull
public Location getFrom() {
- return from;
+ return from.clone(); // Paper - clone to avoid changes
}
/**
@@ -37,7 +37,7 @@ public class VehicleMoveEvent extends VehicleEvent {
*/
@NotNull
public Location getTo() {
- return to;
+ return to.clone(); // Paper - clone to avoid changes
}
diff --git a/src/main/java/org/bukkit/event/world/GenericGameEvent.java b/src/main/java/org/bukkit/event/world/GenericGameEvent.java
index 2a2a329877d8da45c2d6afecf78ce88d52635cad..fb975fefc74d8c9746cab4c02860f55654cf92f7 100644
--- a/src/main/java/org/bukkit/event/world/GenericGameEvent.java
+++ b/src/main/java/org/bukkit/event/world/GenericGameEvent.java
@@ -49,7 +49,7 @@ public class GenericGameEvent extends WorldEvent implements Cancellable {
*/
@NotNull
public Location getLocation() {
- return location;
+ return location.clone(); // Paper - clone to avoid changes
}
/**
diff --git a/src/main/java/org/bukkit/event/world/SpawnChangeEvent.java b/src/main/java/org/bukkit/event/world/SpawnChangeEvent.java
index 9ce93d00935446589cb2bb970cb540d109616e85..73997ae04ff39ac3984c59de32aaced9eb72ce16 100644
--- a/src/main/java/org/bukkit/event/world/SpawnChangeEvent.java
+++ b/src/main/java/org/bukkit/event/world/SpawnChangeEvent.java
@@ -25,7 +25,7 @@ public class SpawnChangeEvent extends WorldEvent {
*/
@NotNull
public Location getPreviousLocation() {
- return previousLocation;
+ return previousLocation.clone(); // Paper - clone to avoid changes
}
@NotNull
diff --git a/src/main/java/org/bukkit/event/world/StructureGrowEvent.java b/src/main/java/org/bukkit/event/world/StructureGrowEvent.java
index 7af8d6e51c824cf0592b722b834f1d4986e3cc08..783e74bc382f0f6d24203fde7b811f588a674731 100644
--- a/src/main/java/org/bukkit/event/world/StructureGrowEvent.java
+++ b/src/main/java/org/bukkit/event/world/StructureGrowEvent.java
@@ -39,7 +39,7 @@ public class StructureGrowEvent extends WorldEvent implements Cancellable {
*/
@NotNull
public Location getLocation() {
- return location;
+ return location.clone(); // Paper - clone to avoid changes
}
/**