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.
This commit is contained in:
Jake Potrebic 2024-03-16 11:10:48 -07:00
parent d19f69b3eb
commit 96f6033450
10 changed files with 11 additions and 11 deletions

View File

@ -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
}
/**

View File

@ -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

View File

@ -72,7 +72,7 @@ public class EntityExplodeEvent extends EntityEvent implements Cancellable {
*/
@NotNull
public Location getLocation() {
return location;
return location.clone(); // Paper - clone to avoid changes
}
/**

View File

@ -35,7 +35,7 @@ public class EntityPortalEnterEvent extends EntityEvent implements org.bukkit.ev
*/
@NotNull
public Location getLocation() {
return location;
return location.clone(); // Paper - clone to avoid changes
}
// Paper start

View File

@ -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

View File

@ -31,7 +31,7 @@ public class VehicleBlockCollisionEvent extends VehicleCollisionEvent {
*/
@NotNull
public org.bukkit.util.Vector getVelocity() {
return velocity;
return velocity.clone();
}
// Paper end

View File

@ -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
}

View File

@ -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
}
/**

View File

@ -25,7 +25,7 @@ public class SpawnChangeEvent extends WorldEvent {
*/
@NotNull
public Location getPreviousLocation() {
return previousLocation;
return previousLocation.clone(); // Paper - clone to avoid changes
}
@NotNull

View File

@ -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
}
/**