Skip to content

Commit

Permalink
jspecify and move Targets
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed Jan 5, 2025
1 parent f379114 commit 0050b10
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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);

Expand All @@ -74,7 +72,6 @@ public interface PositionedRayTraceConfigurationBuilder {
*
* @return the FluidCollisionMode
*/
@NotNull
FluidCollisionMode fluidCollisionMode();

/**
Expand All @@ -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.
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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<? super Entity> entityFilter);

Expand All @@ -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<? super Block> blockFilter);

Expand All @@ -163,22 +155,13 @@ public interface PositionedRayTraceConfigurationBuilder {
* @return the targets
*/
@Nullable
List<Targets> targets();
List<RayTraceTargets> 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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.papermc.paper.raytracing;

/**
* List of Targets a builder can target.
*/
public enum RayTraceTargets {
ENTITIES,
BLOCKS
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,7 +22,7 @@ public class PositionedRayTraceConfigurationBuilderImpl implements PositionedRay
private double raySize = 0.0D;
private java.util.function.Predicate<? super org.bukkit.entity.Entity> entityFilter;
private java.util.function.Predicate<? super org.bukkit.block.Block> blockFilter;
private List<Targets> targets;
private List<RayTraceTargets> targets;

public PositionedRayTraceConfigurationBuilderImpl(World world) {
this.world = world;
Expand All @@ -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;
}
Expand Down Expand Up @@ -117,21 +118,21 @@ public double raySize() {
}

@Override
public @Nullable List<Targets> targets() {
public @Nullable List<RayTraceTargets> targets() {
return this.targets;
}

@Override
public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull Targets first, final @NotNull Targets... others) {
java.util.List<PositionedRayTraceConfigurationBuilder.Targets> targets = new java.util.ArrayList<>(java.util.List.of(others));
public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull RayTraceTargets first, final @NotNull RayTraceTargets... others) {
List<RayTraceTargets> 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());
}
Expand Down

0 comments on commit 0050b10

Please sign in to comment.