diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java index 2e9efaa174a6..bcfe452cd44b 100644 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java @@ -6,14 +6,15 @@ import org.bukkit.entity.Entity; import org.bukkit.util.Vector; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import java.util.List; import java.util.function.Predicate; /** * Holds information about how to cast a raytrace. */ +@NullMarked public interface PositionedRayTraceConfigurationBuilder { /** @@ -30,9 +31,8 @@ public interface PositionedRayTraceConfigurationBuilder { * @param start the new starting location * @return a reference to this object */ - @NotNull @Contract("_ -> this") - PositionedRayTraceConfigurationBuilder start(@NotNull Location start); + PositionedRayTraceConfigurationBuilder start(Location start); /** * Gets the direction. @@ -48,9 +48,8 @@ public interface PositionedRayTraceConfigurationBuilder { * @param direction the new direction * @return a reference to this object */ - @NotNull @Contract("_ -> this") - PositionedRayTraceConfigurationBuilder direction(@NotNull Vector direction); + PositionedRayTraceConfigurationBuilder direction(Vector direction); /** * Gets the maximum distance. @@ -65,7 +64,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param maxDistance the new maxDistance * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder maxDistance(double maxDistance); @@ -74,7 +72,6 @@ public interface PositionedRayTraceConfigurationBuilder { * * @return the FluidCollisionMode */ - @NotNull FluidCollisionMode fluidCollisionMode(); /** @@ -83,9 +80,8 @@ public interface PositionedRayTraceConfigurationBuilder { * @param fluidCollisionMode the new FluidCollisionMode * @return a reference to this object */ - @NotNull @Contract("_ -> this") - PositionedRayTraceConfigurationBuilder fluidCollisionMode(@NotNull FluidCollisionMode fluidCollisionMode); + PositionedRayTraceConfigurationBuilder fluidCollisionMode(FluidCollisionMode fluidCollisionMode); /** * Gets if the raytrace will ignore passable blocks when looking for block collisions. @@ -100,7 +96,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param ignorePassableBlocks if the raytrace should ignore passable blocks * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder ignorePassableBlocks(boolean ignorePassableBlocks); @@ -117,7 +112,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param raySize the new raytrace size * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder raySize(double raySize); @@ -135,7 +129,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param entityFilter predicate for entities the ray can potentially collide with, or null to consider all entities * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder entityFilter(@Nullable Predicate entityFilter); @@ -153,7 +146,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param blockFilter predicate for blocks the ray can potentially collide with, or null to consider all blocks * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder blockFilter(@Nullable Predicate blockFilter); @@ -163,22 +155,13 @@ public interface PositionedRayTraceConfigurationBuilder { * @return the targets */ @Nullable - List targets(); + List targets(); /** * Sets the targets for the rayTrace. * * @return a reference to this object */ - @NotNull @Contract("_, _ -> this") - PositionedRayTraceConfigurationBuilder targets(@NotNull Targets first, @NotNull Targets... others); - - /** - * List of Targets the builder can target. - */ - enum Targets { - ENTITIES, - BLOCKS - } + PositionedRayTraceConfigurationBuilder targets(RayTraceTargets first, RayTraceTargets... others); } diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java new file mode 100644 index 000000000000..77c5ba6758e4 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java @@ -0,0 +1,9 @@ +package io.papermc.paper.raytracing; + +/** + * List of Targets a builder can target. + */ +public enum RayTraceTargets { + ENTITIES, + BLOCKS +} diff --git a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java index 5883aa13eb0f..1a8cbe080c02 100644 --- a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java +++ b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java @@ -7,6 +7,7 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; @@ -21,7 +22,7 @@ public class PositionedRayTraceConfigurationBuilderImpl implements PositionedRay private double raySize = 0.0D; private java.util.function.Predicate entityFilter; private java.util.function.Predicate blockFilter; - private List targets; + private List targets; public PositionedRayTraceConfigurationBuilderImpl(World world) { this.world = world; @@ -34,7 +35,7 @@ public PositionedRayTraceConfigurationBuilderImpl(World world) { } @Override - public @NotNull PositionedRayTraceConfigurationBuilder start(final @NotNull Location start) { + public PositionedRayTraceConfigurationBuilder start(final @NotNull Location start) { this.start = start; return this; } @@ -117,21 +118,21 @@ public double raySize() { } @Override - public @Nullable List targets() { + public @Nullable List targets() { return this.targets; } @Override - public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull Targets first, final @NotNull Targets... others) { - java.util.List targets = new java.util.ArrayList<>(java.util.List.of(others)); + public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull RayTraceTargets first, final @NotNull RayTraceTargets... others) { + List targets = new ArrayList<>(List.of(others)); targets.add(first); this.targets = targets; return this; } public RayTraceResult cast() { - if (targets.contains(Targets.ENTITIES)) { - if(targets.contains(Targets.BLOCKS)) + if (targets.contains(RayTraceTargets.ENTITIES)) { + if(targets.contains(RayTraceTargets.BLOCKS)) return world.rayTrace(this.start(), this.direction(), this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.raySize(), this.entityFilter(), this.blockFilter()); return world.rayTraceEntities(this.start(), this.direction(), this.maxDistance(), this.raySize(), this.entityFilter()); }