Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace UserTeleportEvent with more sane events (#3192)
This PR replaces UserTeleportEvent with two new teleport events called at different stages: - TeleportWarmupEvent; called before a user's teleport warmup begins and allows plugins to skip it or prevent a teleportation - PreTeleportEvent; called after the warmup completes but before any safety checks are carried out This is a **breaking change** as it removes UserTeleportEvent, but the previous event isn't useful or descriptive in its current form and was only recently introduced, so it's unlikely that many plugins already depend on this. Closes #2506.
- Loading branch information
Showing
6 changed files
with
200 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
Essentials/src/net/ess3/api/events/teleport/PreTeleportEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.ess3.api.events.teleport; | ||
|
||
import com.earth2me.essentials.ITarget; | ||
import net.ess3.api.IUser; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
||
/** | ||
* Called before a player is teleported. | ||
* <p> | ||
* Note that this is called after any warmup has been performed but before teleport safety checks are performed. | ||
* Cancelling this event will cancel the teleport without warning the user. | ||
*/ | ||
public class PreTeleportEvent extends TeleportEvent { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
public PreTeleportEvent(IUser teleportee, PlayerTeleportEvent.TeleportCause cause, ITarget target) { | ||
super(teleportee, cause, target); | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
Essentials/src/net/ess3/api/events/teleport/TeleportEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package net.ess3.api.events.teleport; | ||
|
||
import com.earth2me.essentials.ITarget; | ||
import net.ess3.api.IUser; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.Cancellable; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
||
public abstract class TeleportEvent extends Event implements Cancellable { | ||
|
||
private final IUser teleporter; | ||
private final IUser teleportee; | ||
private final PlayerTeleportEvent.TeleportCause cause; | ||
private final ITarget target; | ||
private boolean cancelled = false; | ||
|
||
TeleportEvent(IUser teleporter, IUser teleportee, PlayerTeleportEvent.TeleportCause cause, ITarget target) { | ||
super(!Bukkit.isPrimaryThread()); | ||
this.teleporter = teleporter; | ||
this.teleportee = teleportee; | ||
this.cause = cause; | ||
this.target = target; | ||
} | ||
|
||
TeleportEvent(IUser teleportee, PlayerTeleportEvent.TeleportCause cause, ITarget target) { | ||
this(teleportee, teleportee, cause, target); | ||
} | ||
|
||
/** | ||
* @return The user that initiated the teleportation, or null if unknown | ||
*/ | ||
public IUser getTeleporter() { | ||
return teleporter; | ||
} | ||
|
||
/** | ||
* @return The user to be teleported | ||
*/ | ||
public IUser getTeleportee() { | ||
return teleportee; | ||
} | ||
|
||
/** | ||
* @return The reason for teleportation | ||
*/ | ||
public PlayerTeleportEvent.TeleportCause getTeleportCause() { | ||
return cause; | ||
} | ||
|
||
/** | ||
* @return The target to teleport to, or null if unknown at this stage (such as a forced respawn) | ||
*/ | ||
public ITarget getTarget() { | ||
return target; | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return cancelled; | ||
} | ||
|
||
@Override | ||
public void setCancelled(boolean b) { | ||
cancelled = b; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Essentials/src/net/ess3/api/events/teleport/TeleportWarmupEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package net.ess3.api.events.teleport; | ||
|
||
import com.earth2me.essentials.ITarget; | ||
import net.ess3.api.IUser; | ||
import org.bukkit.event.HandlerList; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
||
/** | ||
* Called when a command starts a player's teleport warmup. | ||
* <p> | ||
* Cancelling this event will prevent the user from teleporting, and any previously pending teleport will commence rather than being cancelled. | ||
* To skip the warmup delay, see {@link #setDelay(double)}. | ||
*/ | ||
public class TeleportWarmupEvent extends TeleportEvent { | ||
|
||
private static final HandlerList handlers = new HandlerList(); | ||
|
||
private double delay; | ||
|
||
public TeleportWarmupEvent(IUser teleporter, IUser teleportee, PlayerTeleportEvent.TeleportCause cause, ITarget target, double delay) { | ||
super(teleporter, teleportee, cause, target); | ||
this.delay = delay; | ||
} | ||
|
||
public TeleportWarmupEvent(IUser teleportee, PlayerTeleportEvent.TeleportCause cause, ITarget target, double delay) { | ||
super(teleportee, cause, target); | ||
this.delay = delay; | ||
} | ||
|
||
public static HandlerList getHandlerList() { | ||
return handlers; | ||
} | ||
|
||
@Override | ||
public HandlerList getHandlers() { | ||
return handlers; | ||
} | ||
|
||
/** | ||
* @return The warmup delay, in seconds. | ||
*/ | ||
public double getDelay() { | ||
return delay; | ||
} | ||
|
||
/** | ||
* @param delay The warmup delay, in seconds. Set this to 0 to skip the warmup delay. | ||
*/ | ||
public void setDelay(double delay) { | ||
this.delay = delay; | ||
} | ||
} |