Finish converting all events to jspecify annotations

This commit is contained in:
Jake Potrebic
2024-09-29 16:48:34 -07:00
parent fa97c59a4e
commit 29a25df60e
78 changed files with 757 additions and 883 deletions

View File

@@ -12,15 +12,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@
+package com.destroystokyo.paper.entity.ai;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.EnumSet;
+
+import org.bukkit.entity.Mob;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Represents an AI goal of an entity
+ */
+@NullMarked
+public interface Goal<T extends Mob> {
+
+ /**
@@ -36,7 +35,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @return if this goal should stay active
+ */
+ default boolean shouldStayActive() {
+ return shouldActivate();
+ return this.shouldActivate();
+ }
+
+ /**
@@ -63,17 +62,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @return the goal key
+ */
+ @NotNull
+ GoalKey<T> getKey();
+
+ /**
+ * Returns a list of all applicable flags for this goal.<br>
+ *
+ * <p>
+ * This method is only called on construction.
+ *
+ * @return the subtypes.
+ */
+ @NotNull
+ EnumSet<GoalType> getTypes();
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/GoalKey.java b/src/main/java/com/destroystokyo/paper/entity/ai/GoalKey.java
@@ -85,64 +82,59 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+package com.destroystokyo.paper.entity.ai;
+
+import com.google.common.base.Objects;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.StringJoiner;
+
+import org.bukkit.NamespacedKey;
+import org.bukkit.entity.Mob;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+/**
+ *
+ * Used to identify a Goal. Consists of a {@link NamespacedKey} and the type of mob the goal can be applied to
+ *
+ * @param <T> the type of mob the goal can be applied to
+ */
+public class GoalKey<T extends Mob> {
+@NullMarked
+public final class GoalKey<T extends Mob> {
+
+ private final Class<T> entityClass;
+ private final NamespacedKey namespacedKey;
+
+ private GoalKey(@NotNull Class<T> entityClass, @NotNull NamespacedKey namespacedKey) {
+ private GoalKey(Class<T> entityClass, NamespacedKey namespacedKey) {
+ this.entityClass = entityClass;
+ this.namespacedKey = namespacedKey;
+ }
+
+ @NotNull
+ public Class<T> getEntityClass() {
+ return entityClass;
+ return this.entityClass;
+ }
+
+ @NotNull
+ public NamespacedKey getNamespacedKey() {
+ return namespacedKey;
+ return this.namespacedKey;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ public boolean equals(@Nullable Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (o == null || this.getClass() != o.getClass()) return false;
+ GoalKey<?> goalKey = (GoalKey<?>) o;
+ return Objects.equal(entityClass, goalKey.entityClass) &&
+ Objects.equal(namespacedKey, goalKey.namespacedKey);
+ return Objects.equal(this.entityClass, goalKey.entityClass) &&
+ Objects.equal(this.namespacedKey, goalKey.namespacedKey);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(entityClass, namespacedKey);
+ return Objects.hashCode(this.entityClass, this.namespacedKey);
+ }
+
+ @Override
+ public String toString() {
+ return new StringJoiner(", ", GoalKey.class.getSimpleName() + "[", "]")
+ .add("entityClass=" + entityClass)
+ .add("namespacedKey=" + namespacedKey)
+ .add("entityClass=" + this.entityClass)
+ .add("namespacedKey=" + this.namespacedKey)
+ .toString();
+ }
+
+ @NotNull
+ public static <A extends Mob> GoalKey<A> of(@NotNull Class<A> entityClass, @NotNull NamespacedKey namespacedKey) {
+ public static <A extends Mob> GoalKey<A> of(Class<A> entityClass, NamespacedKey namespacedKey) {
+ return new GoalKey<>(entityClass, namespacedKey);
+ }
+}
@@ -177,53 +169,45 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@
+package com.destroystokyo.paper.entity.ai;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+
+import org.bukkit.entity.Mob;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Represents a part of the "brain" of a mob. It tracks all tasks (running or not), allows adding and removing goals
+ */
+@NullMarked
+public interface MobGoals {
+
+ <T extends Mob> void addGoal(@NotNull T mob, int priority, @NotNull Goal<T> goal);
+ <T extends Mob> void addGoal(T mob, int priority, Goal<T> goal);
+
+ <T extends Mob> void removeGoal(@NotNull T mob, @NotNull Goal<T> goal);
+ <T extends Mob> void removeGoal(T mob, Goal<T> goal);
+
+ <T extends Mob> void removeAllGoals(@NotNull T mob);
+ <T extends Mob> void removeAllGoals(T mob);
+
+ <T extends Mob> void removeAllGoals(@NotNull T mob, @NotNull GoalType type);
+ <T extends Mob> void removeAllGoals(T mob, GoalType type);
+
+ <T extends Mob> void removeGoal(@NotNull T mob, @NotNull GoalKey<T> key);
+ <T extends Mob> void removeGoal(T mob, GoalKey<T> key);
+
+ <T extends Mob> boolean hasGoal(@NotNull T mob, @NotNull GoalKey<T> key);
+ <T extends Mob> boolean hasGoal(T mob, GoalKey<T> key);
+
+ @Nullable
+ <T extends Mob> Goal<T> getGoal(@NotNull T mob, @NotNull GoalKey<T> key);
+ <T extends Mob> @Nullable Goal<T> getGoal(T mob, GoalKey<T> key);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getGoals(@NotNull T mob, @NotNull GoalKey<T> key);
+ <T extends Mob> Collection<Goal<T>> getGoals(T mob, GoalKey<T> key);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getAllGoals(@NotNull T mob);
+ <T extends Mob> Collection<Goal<T>> getAllGoals(T mob);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getAllGoals(@NotNull T mob, @NotNull GoalType type);
+ <T extends Mob> Collection<Goal<T>> getAllGoals(T mob, GoalType type);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getAllGoalsWithout(@NotNull T mob, @NotNull GoalType type);
+ <T extends Mob> Collection<Goal<T>> getAllGoalsWithout(T mob, GoalType type);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getRunningGoals(@NotNull T mob);
+ <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getRunningGoals(@NotNull T mob, @NotNull GoalType type);
+ <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob, GoalType type);
+
+ @NotNull
+ <T extends Mob> Collection<Goal<T>> getRunningGoalsWithout(@NotNull T mob, @NotNull GoalType type);
+ <T extends Mob> Collection<Goal<T>> getRunningGoalsWithout(T mob, GoalType type);
+}
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644