mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-03 10:43:45 +01:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			feat/mutab
			...
			migrate-en
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					f5972317bd | 
@@ -21,26 +21,21 @@ package com.plotsquared.core.events;
 | 
			
		||||
import com.plotsquared.core.location.Location;
 | 
			
		||||
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
 | 
			
		||||
 */
 | 
			
		||||
public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements CancellablePlotEvent {
 | 
			
		||||
 | 
			
		||||
    private final Location from;
 | 
			
		||||
    private final TeleportCause cause;
 | 
			
		||||
    private Result eventResult;
 | 
			
		||||
    private final Location from;
 | 
			
		||||
    private UnaryOperator<Location> locationTransformer;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * PlayerTeleportToPlotEvent: Called when a player teleports to a plot
 | 
			
		||||
     *
 | 
			
		||||
     * @param player That was teleported
 | 
			
		||||
     * @param from   The origin location, from where the teleport was triggered (players location most likely)
 | 
			
		||||
     * @param from   Start location
 | 
			
		||||
     * @param plot   Plot to which the player was teleported
 | 
			
		||||
     * @param cause  Why the teleport is being completed
 | 
			
		||||
     * @since 6.1.0
 | 
			
		||||
@@ -62,8 +57,7 @@ public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements Cancel
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the location, from where the teleport was triggered
 | 
			
		||||
     * (the players current location when executing the home command for example)
 | 
			
		||||
     * Get the from location
 | 
			
		||||
     *
 | 
			
		||||
     * @return Location
 | 
			
		||||
     */
 | 
			
		||||
@@ -71,27 +65,6 @@ public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements Cancel
 | 
			
		||||
        return this.from;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the currently applied {@link UnaryOperator<Location> transformer} or null, if none was set
 | 
			
		||||
     *
 | 
			
		||||
     * @return LocationTransformer
 | 
			
		||||
     * @since TODO
 | 
			
		||||
     */
 | 
			
		||||
    public @Nullable UnaryOperator<Location> getLocationTransformer() {
 | 
			
		||||
        return this.locationTransformer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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 UnaryOperator<Location> locationTransformer) {
 | 
			
		||||
        this.locationTransformer = locationTransformer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Result getEventResult() {
 | 
			
		||||
        return eventResult;
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,6 @@ import com.plotsquared.core.configuration.caption.CaptionUtility;
 | 
			
		||||
import com.plotsquared.core.configuration.caption.StaticCaption;
 | 
			
		||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
 | 
			
		||||
import com.plotsquared.core.database.DBFunc;
 | 
			
		||||
import com.plotsquared.core.events.PlayerTeleportToPlotEvent;
 | 
			
		||||
import com.plotsquared.core.events.Result;
 | 
			
		||||
import com.plotsquared.core.events.TeleportCause;
 | 
			
		||||
import com.plotsquared.core.generator.ClassicPlotWorld;
 | 
			
		||||
@@ -2615,9 +2614,8 @@ public class Plot {
 | 
			
		||||
     */
 | 
			
		||||
    public void teleportPlayer(final PlotPlayer<?> player, TeleportCause cause, Consumer<Boolean> resultConsumer) {
 | 
			
		||||
        Plot plot = this.getBasePlot(false);
 | 
			
		||||
 | 
			
		||||
        PlayerTeleportToPlotEvent event = this.eventDispatcher.callTeleport(player, player.getLocation(), plot, cause);
 | 
			
		||||
        if (event.getEventResult() == Result.DENY) {
 | 
			
		||||
        Result result = this.eventDispatcher.callTeleport(player, player.getLocation(), plot, cause).getEventResult();
 | 
			
		||||
        if (result == Result.DENY) {
 | 
			
		||||
            player.sendMessage(
 | 
			
		||||
                    TranslatableCaption.of("events.event_denied"),
 | 
			
		||||
                    TagResolver.resolver("value", Tag.inserting(Component.text("Teleport")))
 | 
			
		||||
@@ -2625,10 +2623,7 @@ public class Plot {
 | 
			
		||||
            resultConsumer.accept(false);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final Consumer<Location> locationConsumer = calculatedLocation -> {
 | 
			
		||||
            Location location = event.getLocationTransformer() == null ? calculatedLocation :
 | 
			
		||||
                    Objects.requireNonNullElse(event.getLocationTransformer().apply(calculatedLocation), calculatedLocation);
 | 
			
		||||
        final Consumer<Location> locationConsumer = location -> {
 | 
			
		||||
            if (Settings.Teleport.DELAY == 0 || player.hasPermission("plots.teleport.delay.bypass")) {
 | 
			
		||||
                player.sendMessage(TranslatableCaption.of("teleport.teleported_to_plot"));
 | 
			
		||||
                player.teleport(location, cause);
 | 
			
		||||
 
 | 
			
		||||
@@ -42,27 +42,14 @@ public class EntityUtil {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static int capNumeral(final @NonNull String flagName) {
 | 
			
		||||
        int i;
 | 
			
		||||
        switch (flagName) {
 | 
			
		||||
            case "mob-cap":
 | 
			
		||||
                i = CAP_MOB;
 | 
			
		||||
                break;
 | 
			
		||||
            case "hostile-cap":
 | 
			
		||||
                i = CAP_MONSTER;
 | 
			
		||||
                break;
 | 
			
		||||
            case "animal-cap":
 | 
			
		||||
                i = CAP_ANIMAL;
 | 
			
		||||
                break;
 | 
			
		||||
            case "vehicle-cap":
 | 
			
		||||
                i = CAP_VEHICLE;
 | 
			
		||||
                break;
 | 
			
		||||
            case "misc-cap":
 | 
			
		||||
                i = CAP_MISC;
 | 
			
		||||
                break;
 | 
			
		||||
            case "entity-cap":
 | 
			
		||||
            default:
 | 
			
		||||
                i = CAP_ENTITY;
 | 
			
		||||
        }
 | 
			
		||||
        int i = switch (flagName) {
 | 
			
		||||
            case "mob-cap" -> CAP_MOB;
 | 
			
		||||
            case "hostile-cap" -> CAP_MONSTER;
 | 
			
		||||
            case "animal-cap" -> CAP_ANIMAL;
 | 
			
		||||
            case "vehicle-cap" -> CAP_VEHICLE;
 | 
			
		||||
            case "misc-cap" -> CAP_MISC;
 | 
			
		||||
            default -> CAP_ENTITY;
 | 
			
		||||
        };
 | 
			
		||||
        return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user