Use ? super in Consumer/Predicate API (#9939)

This commit is contained in:
Jake Potrebic
2023-11-25 15:03:02 -08:00
parent 3d12fa65fa
commit cea171de11
13 changed files with 186 additions and 223 deletions

View File

@@ -25,23 +25,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Represents a 3-dimensional position in a world.
* <br>
@@ -0,0 +0,0 @@ public class Location implements Cloneable, ConfigurationSerializable, io.paperm
centerLoc.setZ(getBlockZ() + 0.5);
return centerLoc;
}
+
// Paper end - expand Location API
+ // Paper start - additional getNearbyEntities API
+ /**
+ * Returns a list of entities within a bounding box centered around a Location.
+ *
+ * <p>
+ * Some implementations may impose artificial restrictions on the size of the search bounding box.
+ *
+ * @param x 1/2 the size of the box along x axis
+ * @param y 1/2 the size of the box along y axis
+ * @param z 1/2 the size of the box along z axis
+ * @param x 1/2 the size of the box along the x-axis
+ * @param y 1/2 the size of the box along the y-axis
+ * @param z 1/2 the size of the box along the z-axis
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Entity> getNearbyEntities(double x, double y, double z) {
+ World world = this.getWorld();
+ public @NotNull Collection<Entity> getNearbyEntities(final double x, final double y, final double z) {
+ final World world = this.getWorld();
+ if (world == null) {
+ throw new IllegalArgumentException("Location has no world");
+ }
@@ -53,9 +52,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param radius X Radius
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<LivingEntity> getNearbyLivingEntities(double radius) {
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, radius, radius, radius);
+ public @NotNull Collection<LivingEntity> getNearbyLivingEntities(final double radius) {
+ return this.getNearbyEntitiesByType(LivingEntity.class, radius, radius, radius);
+ }
+
+ /**
@@ -64,9 +62,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param yRadius Y Radius
+ * @return the collection of living entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<LivingEntity> getNearbyLivingEntities(double xzRadius, double yRadius) {
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xzRadius, yRadius, xzRadius);
+ public @NotNull Collection<LivingEntity> getNearbyLivingEntities(final double xzRadius, final double yRadius) {
+ return this.getNearbyEntitiesByType(LivingEntity.class, xzRadius, yRadius, xzRadius);
+ }
+
+ /**
@@ -76,9 +73,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param zRadius Z radius
+ * @return the collection of living entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<LivingEntity> getNearbyLivingEntities(double xRadius, double yRadius, double zRadius) {
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xRadius, yRadius, zRadius);
+ public @NotNull Collection<LivingEntity> getNearbyLivingEntities(final double xRadius, final double yRadius, final double zRadius) {
+ return this.getNearbyEntitiesByType(LivingEntity.class, xRadius, yRadius, zRadius);
+ }
+
+ /**
@@ -87,9 +83,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param predicate a predicate used to filter results
+ * @return the collection of living entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<LivingEntity> getNearbyLivingEntities(double radius, @Nullable Predicate<LivingEntity> predicate) {
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, radius, radius, radius, predicate);
+ public @NotNull Collection<LivingEntity> getNearbyLivingEntities(final double radius, final @Nullable Predicate<? super LivingEntity> predicate) {
+ return this.getNearbyEntitiesByType(LivingEntity.class, radius, radius, radius, predicate);
+ }
+
+ /**
@@ -99,9 +94,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param predicate a predicate used to filter results
+ * @return the collection of living entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<LivingEntity> getNearbyLivingEntities(double xzRadius, double yRadius, @Nullable Predicate<LivingEntity> predicate) {
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xzRadius, yRadius, xzRadius, predicate);
+ public @NotNull Collection<LivingEntity> getNearbyLivingEntities(final double xzRadius, final double yRadius, final @Nullable Predicate<? super LivingEntity> predicate) {
+ return this.getNearbyEntitiesByType(LivingEntity.class, xzRadius, yRadius, xzRadius, predicate);
+ }
+
+ /**
@@ -112,9 +106,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param predicate a predicate used to filter results
+ * @return the collection of living entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<LivingEntity> getNearbyLivingEntities(double xRadius, double yRadius, double zRadius, @Nullable Predicate<LivingEntity> predicate) {
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xRadius, yRadius, zRadius, predicate);
+ public @NotNull Collection<LivingEntity> getNearbyLivingEntities(final double xRadius, final double yRadius, final double zRadius, final @Nullable Predicate<? super LivingEntity> predicate) {
+ return this.getNearbyEntitiesByType(LivingEntity.class, xRadius, yRadius, zRadius, predicate);
+ }
+
+ /**
@@ -122,9 +115,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param radius X/Y/Z Radius
+ * @return the collection of players near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Player> getNearbyPlayers(double radius) {
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, radius, radius, radius);
+ public @NotNull Collection<Player> getNearbyPlayers(final double radius) {
+ return this.getNearbyEntitiesByType(Player.class, radius, radius, radius);
+ }
+
+ /**
@@ -133,9 +125,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param yRadius Y Radius
+ * @return the collection of players near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Player> getNearbyPlayers(double xzRadius, double yRadius) {
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xzRadius, yRadius, xzRadius);
+ public @NotNull Collection<Player> getNearbyPlayers(final double xzRadius, final double yRadius) {
+ return this.getNearbyEntitiesByType(Player.class, xzRadius, yRadius, xzRadius);
+ }
+
+ /**
@@ -145,9 +136,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param zRadius Z Radius
+ * @return the collection of players near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Player> getNearbyPlayers(double xRadius, double yRadius, double zRadius) {
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xRadius, yRadius, zRadius);
+ public @NotNull Collection<Player> getNearbyPlayers(final double xRadius, final double yRadius, final double zRadius) {
+ return this.getNearbyEntitiesByType(Player.class, xRadius, yRadius, zRadius);
+ }
+
+ /**
@@ -156,9 +146,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param predicate a predicate used to filter results
+ * @return the collection of players near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Player> getNearbyPlayers(double radius, @Nullable Predicate<Player> predicate) {
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, radius, radius, radius, predicate);
+ public @NotNull Collection<Player> getNearbyPlayers(final double radius, final @Nullable Predicate<? super Player> predicate) {
+ return this.getNearbyEntitiesByType(Player.class, radius, radius, radius, predicate);
+ }
+
+ /**
@@ -168,9 +157,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param predicate a predicate used to filter results
+ * @return the collection of players near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Player> getNearbyPlayers(double xzRadius, double yRadius, @Nullable Predicate<Player> predicate) {
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xzRadius, yRadius, xzRadius, predicate);
+ public @NotNull Collection<Player> getNearbyPlayers(final double xzRadius, final double yRadius, final @Nullable Predicate<? super Player> predicate) {
+ return this.getNearbyEntitiesByType(Player.class, xzRadius, yRadius, xzRadius, predicate);
+ }
+
+ /**
@@ -181,9 +169,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param predicate a predicate used to filter results
+ * @return the collection of players near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public Collection<Player> getNearbyPlayers(double xRadius, double yRadius, double zRadius, @Nullable Predicate<Player> predicate) {
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xRadius, yRadius, zRadius, predicate);
+ public @NotNull Collection<Player> getNearbyPlayers(final double xRadius, final double yRadius, final double zRadius, final @Nullable Predicate<? super Player> predicate) {
+ return this.getNearbyEntitiesByType(Player.class, xRadius, yRadius, zRadius, predicate);
+ }
+
+ /**
@@ -193,9 +180,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param <T> the entity type
+ * @return the collection of entities of type clazz near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, double radius) {
+ return getNearbyEntitiesByType(clazz, radius, radius, radius, null);
+ public @NotNull <T extends Entity> Collection<T> getNearbyEntitiesByType(final @Nullable Class<? extends T> clazz, final double radius) {
+ return this.getNearbyEntitiesByType(clazz, radius, radius, radius, null);
+ }
+
+ /**
@@ -206,9 +192,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param <T> the entity type
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, double xzRadius, double yRadius) {
+ return getNearbyEntitiesByType(clazz, xzRadius, yRadius, xzRadius, null);
+ public @NotNull <T extends Entity> Collection<T> getNearbyEntitiesByType(final @Nullable Class<? extends T> clazz, final double xzRadius, final double yRadius) {
+ return this.getNearbyEntitiesByType(clazz, xzRadius, yRadius, xzRadius, null);
+ }
+
+ /**
@@ -220,9 +205,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param <T> the entity type
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, double xRadius, double yRadius, double zRadius) {
+ return getNearbyEntitiesByType(clazz, xRadius, yRadius, zRadius, null);
+ public @NotNull <T extends Entity> Collection<T> getNearbyEntitiesByType(final @Nullable Class<? extends T> clazz, final double xRadius, final double yRadius, final double zRadius) {
+ return this.getNearbyEntitiesByType(clazz, xRadius, yRadius, zRadius, null);
+ }
+
+ /**
@@ -233,9 +217,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param <T> the entity type
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, double radius, @Nullable Predicate<T> predicate) {
+ return getNearbyEntitiesByType(clazz, radius, radius, radius, predicate);
+ public @NotNull <T extends Entity> Collection<T> getNearbyEntitiesByType(final @Nullable Class<? extends T> clazz, final double radius, final @Nullable Predicate<? super T> predicate) {
+ return this.getNearbyEntitiesByType(clazz, radius, radius, radius, predicate);
+ }
+
+ /**
@@ -247,9 +230,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param <T> the entity type
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, double xzRadius, double yRadius, @Nullable Predicate<T> predicate) {
+ return getNearbyEntitiesByType(clazz, xzRadius, yRadius, xzRadius, predicate);
+ public @NotNull <T extends Entity> Collection<T> getNearbyEntitiesByType(final @Nullable Class<? extends T> clazz, final double xzRadius, final double yRadius, final @Nullable Predicate<? super T> predicate) {
+ return this.getNearbyEntitiesByType(clazz, xzRadius, yRadius, xzRadius, predicate);
+ }
+
+ /**
@@ -262,14 +244,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param <T> the entity type
+ * @return the collection of entities near location. This will always be a non-null collection.
+ */
+ @NotNull
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends Entity> clazz, double xRadius, double yRadius, double zRadius, @Nullable Predicate<T> predicate) {
+ World world = this.getWorld();
+ public @NotNull <T extends Entity> Collection<T> getNearbyEntitiesByType(final @Nullable Class<? extends Entity> clazz, final double xRadius, final double yRadius, final double zRadius, final @Nullable Predicate<? super T> predicate) {
+ final World world = this.getWorld();
+ if (world == null) {
+ throw new IllegalArgumentException("Location has no world");
+ }
+ return world.getNearbyEntitiesByType(clazz, this, xRadius, yRadius, zRadius, predicate);
+ }
// Paper end
+ // Paper end - additional getNearbyEntities API
+
@Override
public boolean equals(Object obj) {
if (obj == null) {