001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.events; 020 021import com.plotsquared.core.location.Location; 022import com.plotsquared.core.player.PlotPlayer; 023import com.plotsquared.core.plot.Plot; 024import org.checkerframework.checker.nullness.qual.Nullable; 025 026import java.util.function.UnaryOperator; 027 028/** 029 * Called when a player teleports to a plot 030 */ 031public class PlayerTeleportToPlotEvent extends PlotPlayerEvent implements CancellablePlotEvent { 032 033 private final TeleportCause cause; 034 private Result eventResult; 035 private final Location from; 036 private UnaryOperator<Location> locationTransformer; 037 038 039 /** 040 * PlayerTeleportToPlotEvent: Called when a player teleports to a plot 041 * 042 * @param player That was teleported 043 * @param from The origin location, from where the teleport was triggered (players location most likely) 044 * @param plot Plot to which the player was teleported 045 * @param cause Why the teleport is being completed 046 * @since 6.1.0 047 */ 048 public PlayerTeleportToPlotEvent(PlotPlayer<?> player, Location from, Plot plot, TeleportCause cause) { 049 super(player, plot); 050 this.from = from; 051 this.cause = cause; 052 } 053 054 /** 055 * Get the teleport cause 056 * 057 * @return TeleportCause 058 * @since 6.1.0 059 */ 060 public TeleportCause getCause() { 061 return cause; 062 } 063 064 /** 065 * Get the location, from where the teleport was triggered 066 * (the players current location when executing the home command for example) 067 * 068 * @return Location 069 */ 070 public Location getFrom() { 071 return this.from; 072 } 073 074 /** 075 * Gets the currently applied {@link UnaryOperator<Location> transformer} or null, if none was set 076 * 077 * @return LocationTransformer 078 * @since 7.2.1 079 */ 080 public @Nullable UnaryOperator<Location> getLocationTransformer() { 081 return this.locationTransformer; 082 } 083 084 /** 085 * Sets the {@link UnaryOperator<Location> transformer} to mutate the location where the player will be teleported to. 086 * May be {@code null}, if any previous set transformations should be discarded. 087 * 088 * @param locationTransformer The new transformer 089 * @since 7.2.1 090 */ 091 public void setLocationTransformer(@Nullable UnaryOperator<Location> locationTransformer) { 092 this.locationTransformer = locationTransformer; 093 } 094 095 @Override 096 public Result getEventResult() { 097 return eventResult; 098 } 099 100 @Override 101 public void setEventResult(Result e) { 102 this.eventResult = e; 103 } 104 105}