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
parent fa1f6a5d78
commit 64e918335c
62 changed files with 580 additions and 750 deletions

View File

@@ -23,19 +23,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.util.Vector;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired when an Entity is knocked back by the hit of another Entity. The acceleration
+ * vector can be modified. If this event is cancelled, the entity is not knocked back.
+ */
+@NullMarked
+public class EntityKnockbackByEntityEvent extends EntityPushedByEntityAttackEvent {
+
+ private final float knockbackStrength;
+
+ @ApiStatus.Internal
+ public EntityKnockbackByEntityEvent(final @NonNull LivingEntity entity, final @NonNull Entity hitBy, final EntityKnockbackEvent.@NonNull Cause cause, final float knockbackStrength, final @NonNull Vector knockback) {
+ public EntityKnockbackByEntityEvent(final LivingEntity entity, final Entity hitBy, final EntityKnockbackEvent.Cause cause, final float knockbackStrength, final Vector knockback) {
+ super(entity, cause, hitBy, knockback);
+ this.knockbackStrength = knockbackStrength;
+ }
@@ -44,7 +45,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @return the entity which was knocked back
+ */
+ @Override
+ public @NonNull LivingEntity getEntity() {
+ public LivingEntity getEntity() {
+ return (LivingEntity) super.getEntity();
+ }
+
@@ -62,7 +63,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @return the Entity which hit
+ */
+ public @NonNull Entity getHitBy() {
+ public Entity getHitBy() {
+ return super.getPushedBy();
+ }
+
@@ -81,14 +82,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.util.Vector;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Called when an entity receives knockback.
+ * @see EntityPushedByEntityAttackEvent
+ * @see com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent
+ */
+@NullMarked
+public class EntityKnockbackEvent extends EntityEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
@@ -98,7 +100,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public EntityKnockbackEvent(final @NonNull Entity entity, final EntityKnockbackEvent.@NonNull Cause cause, final @NonNull Vector knockback) {
+ public EntityKnockbackEvent(final Entity entity, final EntityKnockbackEvent.Cause cause, final Vector knockback) {
+ super(entity);
+ this.cause = cause;
+ this.knockback = knockback;
@@ -109,7 +111,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @return the cause of the knockback
+ */
+ public EntityKnockbackEvent.@NonNull Cause getCause() {
+ public EntityKnockbackEvent.Cause getCause() {
+ return this.cause;
+ }
+
@@ -121,7 +123,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @return the knockback
+ */
+ public @NonNull Vector getKnockback() {
+ public Vector getKnockback() {
+ return this.knockback.clone();
+ }
+
@@ -130,7 +132,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @param knockback the knockback
+ */
+ public void setKnockback(final @NonNull Vector knockback) {
+ public void setKnockback(final Vector knockback) {
+ Preconditions.checkArgument(knockback != null, "knockback");
+ this.knockback = knockback.clone();
+ }
@@ -146,11 +148,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ @Override
+ public @NonNull HandlerList getHandlers() {
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static @NonNull HandlerList getHandlerList() {
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
@@ -200,8 +202,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import org.bukkit.entity.Entity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.util.Vector;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired when an entity is pushed by another entity's attack. The acceleration vector can be
@@ -210,12 +212,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Note: Some entities might trigger this multiple times on the same entity
+ * as multiple acceleration calculations are done.
+ */
+@NullMarked
+public class EntityPushedByEntityAttackEvent extends EntityKnockbackEvent implements Cancellable {
+
+ private final Entity pushedBy;
+
+ @ApiStatus.Internal
+ public EntityPushedByEntityAttackEvent(final @NonNull Entity entity, final EntityKnockbackEvent.@NonNull Cause cause, final @NonNull Entity pushedBy, final @NonNull Vector knockback) {
+ public EntityPushedByEntityAttackEvent(final Entity entity, final EntityKnockbackEvent.Cause cause, final Entity pushedBy, final Vector knockback) {
+ super(entity, cause, knockback);
+ this.pushedBy = pushedBy;
+ }
@@ -225,7 +228,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @return the pushing entity
+ */
+ public @NonNull Entity getPushedBy() {
+ public Entity getPushedBy() {
+ return this.pushedBy;
+ }
+
@@ -236,7 +239,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @deprecated use {@link #getKnockback()}
+ */
+ @Deprecated(since = "1.20.6", forRemoval = true)
+ public @NonNull Vector getAcceleration() {
+ public Vector getAcceleration() {
+ return this.knockback; // TODO Clone in 1.21 to not instantly break what was technically already modifiable (call super.getKnockback())
+ }
+
@@ -247,7 +250,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @deprecated use {@link #setKnockback(Vector)}
+ */
+ @Deprecated(since = "1.20.6", forRemoval = true)
+ public void setAcceleration(final @NonNull Vector acceleration) {
+ public void setAcceleration(final Vector acceleration) {
+ super.setKnockback(acceleration);
+ }
+