mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
chore: simplify transform type
This commit is contained in:
parent
9d2c632ca8
commit
23b371f794
@ -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<Location> 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<Location> transformer} or null, if none was set
|
||||
*
|
||||
* @return LocationTransformer
|
||||
* @since TODO
|
||||
*/
|
||||
public @Nullable LocationTransformer getLocationTransformer() {
|
||||
public @Nullable UnaryOperator<Location> getLocationTransformer() {
|
||||
return this.locationTransformer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link LocationTransformer} to mutate the location where the player will be teleported to.
|
||||
* Sets the {@link UnaryOperator<Location> 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<Location> 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2627,8 +2627,8 @@ public class Plot {
|
||||
}
|
||||
|
||||
final Consumer<Location> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user