13
0
geforkt von Mirrors/Paper

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.
Dieser Commit ist enthalten in:
Jake Potrebic 2024-03-16 11:10:48 -07:00
Ursprung d19f69b3eb
Commit 96f6033450
10 geänderte Dateien mit 11 neuen und 11 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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