mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-03 19:15:44 +00:00
Add teleport warmup event to API (#2590)
* Update Teleport.java * Create UserTeleportEvent.java * Update Teleport.java * Add location to event
This commit is contained in:
parent
89743f9900
commit
c8b8e505f3
2 changed files with 67 additions and 3 deletions
|
@ -7,6 +7,7 @@ import net.ess3.api.IEssentials;
|
||||||
import net.ess3.api.ITeleport;
|
import net.ess3.api.ITeleport;
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
import net.ess3.api.events.UserWarpEvent;
|
import net.ess3.api.events.UserWarpEvent;
|
||||||
|
import net.ess3.api.events.UserTeleportEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -120,9 +121,16 @@ public class Teleport implements ITeleport {
|
||||||
|
|
||||||
protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws Exception {
|
protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws Exception {
|
||||||
cancel(false);
|
cancel(false);
|
||||||
teleportee.setLastLocation();
|
|
||||||
Location loc = target.getLocation();
|
Location loc = target.getLocation();
|
||||||
|
|
||||||
|
UserTeleportEvent event = new UserTeleportEvent(teleportee, cause, loc);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
teleportee.setLastLocation();
|
||||||
|
|
||||||
if (LocationUtil.isBlockUnsafeForUser(teleportee, loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
|
if (LocationUtil.isBlockUnsafeForUser(teleportee, loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
|
||||||
if (ess.getSettings().isTeleportSafetyEnabled()) {
|
if (ess.getSettings().isTeleportSafetyEnabled()) {
|
||||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||||
|
@ -286,10 +294,10 @@ public class Teleport implements ITeleport {
|
||||||
public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause cause) throws Exception {
|
public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause cause) throws Exception {
|
||||||
UserWarpEvent event = new UserWarpEvent(teleportee, warp, chargeFor);
|
UserWarpEvent event = new UserWarpEvent(teleportee, warp, chargeFor);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (event.isCancelled()) {
|
||||||
if(event.isCancelled()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
warp = event.getWarp();
|
warp = event.getWarp();
|
||||||
Location loc = ess.getWarps().getWarp(warp);
|
Location loc = ess.getWarps().getWarp(warp);
|
||||||
teleportee.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
teleportee.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||||
|
|
56
Essentials/src/net/ess3/api/events/UserTeleportEvent.java
Normal file
56
Essentials/src/net/ess3/api/events/UserTeleportEvent.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package net.ess3.api.events;
|
||||||
|
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
/**
|
||||||
|
* Called when the player teleports
|
||||||
|
*/
|
||||||
|
public class UserTeleportEvent extends Event implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private IUser user;
|
||||||
|
private TeleportCause cause;
|
||||||
|
private Location target;
|
||||||
|
private boolean cancelled = false;
|
||||||
|
|
||||||
|
public UserTeleportEvent(IUser user, TeleportCause cause, Location target) {
|
||||||
|
this.user = user;
|
||||||
|
this.cause = cause;
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IUser getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TeleportCause getTeleportCause() {
|
||||||
|
return cause;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean b) {
|
||||||
|
cancelled = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue