Begin switching to JSpecify annotations (#11448)

* Begin switching to JSpecify annotations

* more

* fixes
This commit is contained in:
Jake Potrebic 2024-09-29 12:52:13 -07:00 committed by GitHub
parent 6d7a438fad
commit f9c7f2a5c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 750 additions and 920 deletions

View file

@ -6,10 +6,10 @@ Subject: [PATCH] EntityMoveEvent
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityMoveEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityMoveEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd46c2ad77c
index 0000000000000000000000000000000000000000..49ace395393839b3652a537207b4cf5b24beeac0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityMoveEvent.java
@@ -0,0 +1,150 @@
@@ -0,0 +1,146 @@
+package io.papermc.paper.event.entity;
+
+import com.google.common.base.Preconditions;
@ -20,13 +20,14 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Holds information for living entity movement events
+ * <p>
+ * Does not fire for players; use {@link PlayerMoveEvent} for player movement.
+ */
+@NullMarked
+public class EntityMoveEvent extends EntityEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
@ -37,14 +38,13 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public EntityMoveEvent(@NotNull LivingEntity entity, @NotNull Location from, @NotNull Location to) {
+ public EntityMoveEvent(final LivingEntity entity, final Location from, final Location to) {
+ super(entity);
+ this.from = from;
+ this.to = to;
+ }
+
+ @Override
+ @NotNull
+ public LivingEntity getEntity() {
+ return (LivingEntity) super.getEntity();
+ }
@ -54,7 +54,6 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ *
+ * @return Location the entity moved from
+ */
+ @NotNull
+ public Location getFrom() {
+ return this.from;
+ }
@ -64,8 +63,8 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ *
+ * @param from New location to mark as the entity's previous location
+ */
+ public void setFrom(@NotNull Location from) {
+ validateLocation(from);
+ public void setFrom(final Location from) {
+ this.validateLocation(from);
+ this.from = from;
+ }
+
@ -74,7 +73,6 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ *
+ * @return Location the entity moved to
+ */
+ @NotNull
+ public Location getTo() {
+ return this.to;
+ }
@ -84,8 +82,8 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ *
+ * @param to New Location this entity will move to
+ */
+ public void setTo(@NotNull Location to) {
+ validateLocation(to);
+ public void setTo(final Location to) {
+ this.validateLocation(to);
+ this.to = to;
+ }
+
@ -95,7 +93,7 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ * @return whether the entity has changed position or not
+ */
+ public boolean hasChangedPosition() {
+ return hasExplicitlyChangedPosition() || !this.from.getWorld().equals(this.to.getWorld());
+ return this.hasExplicitlyChangedPosition() || !this.from.getWorld().equals(this.to.getWorld());
+ }
+
+ /**
@ -113,7 +111,7 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ * @return whether the entity has moved to a new block or not
+ */
+ public boolean hasChangedBlock() {
+ return hasExplicitlyChangedBlock() || !from.getWorld().equals(to.getWorld());
+ return this.hasExplicitlyChangedBlock() || !this.from.getWorld().equals(this.to.getWorld());
+ }
+
+ /**
@ -134,7 +132,7 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ return this.from.getPitch() != this.to.getPitch() || this.from.getYaw() != this.to.getYaw();
+ }
+
+ private void validateLocation(@NotNull Location loc) {
+ private void validateLocation(final Location loc) {
+ Preconditions.checkArgument(loc != null, "Cannot use null location!");
+ Preconditions.checkArgument(loc.getWorld() != null, "Cannot use null location with null world!");
+ }
@ -145,17 +143,15 @@ index 0000000000000000000000000000000000000000..46990a220f70b04218b14aec1e9efbd4
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ public void setCancelled(final boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }