From 23b371f794b7f1f6f3cafc230a81e9cebbe04b62 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Sat, 14 Oct 2023 21:28:57 +0200 Subject: [PATCH] chore: simplify transform type --- .../events/PlayerTeleportToPlotEvent.java | 25 ++++++------------- .../java/com/plotsquared/core/plot/Plot.java | 4 +-- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/events/PlayerTeleportToPlotEvent.java b/Core/src/main/java/com/plotsquared/core/events/PlayerTeleportToPlotEvent.java index 90c74fb64..0b56c1e95 100644 --- a/Core/src/main/java/com/plotsquared/core/events/PlayerTeleportToPlotEvent.java +++ b/Core/src/main/java/com/plotsquared/core/events/PlayerTeleportToPlotEvent.java @@ -23,6 +23,8 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import org.checkerframework.checker.nullness.qual.Nullable; +import java.util.function.UnaryOperator; + /** * Called when a player teleports to a plot */ @@ -31,7 +33,7 @@ public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements Cancel private final TeleportCause cause; private Result eventResult; private final Location from; - private LocationTransformer locationTransformer; + private UnaryOperator locationTransformer; /** @@ -70,23 +72,23 @@ public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements Cancel } /** - * Gets the currently applied {@link LocationTransformer} or null, if none was set + * Gets the currently applied {@link UnaryOperator transformer} or null, if none was set * * @return LocationTransformer * @since TODO */ - public @Nullable LocationTransformer getLocationTransformer() { + public @Nullable UnaryOperator getLocationTransformer() { return this.locationTransformer; } /** - * Sets the {@link LocationTransformer} to mutate the location where the player will be teleported to. + * Sets the {@link UnaryOperator transformer} to mutate the location where the player will be teleported to. * May be {@code null}, if any previous set transformations should be discarded. * * @param locationTransformer The new transformer * @since TODO */ - public void setLocationTransformer(@Nullable LocationTransformer locationTransformer) { + public void setLocationTransformer(@Nullable UnaryOperator locationTransformer) { this.locationTransformer = locationTransformer; } @@ -100,17 +102,4 @@ public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements Cancel this.eventResult = e; } - public interface LocationTransformer { - - /** - * Transforms an input location {@code origin} to a new location - * - * @param origin The origin location which should be transformed - * @return The transformed location - * @since TODO - */ - Location transform(Location origin); - - } - } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index fb992e42b..8103b9604 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -2627,8 +2627,8 @@ public class Plot { } final Consumer locationConsumer = calculatedLocation -> { - Location location = event.getLocationTransformer() == null ? - calculatedLocation : event.getLocationTransformer().transform(calculatedLocation); + Location location = event.getLocationTransformer() == null ? calculatedLocation : + Objects.requireNonNullElse(event.getLocationTransformer().apply(calculatedLocation), calculatedLocation); if (Settings.Teleport.DELAY == 0 || player.hasPermission("plots.teleport.delay.bypass")) { player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot")); player.teleport(location, cause);