diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index e45523a0ab9..82d17ffae85 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -4,6 +4,8 @@ import com.earth2me.essentials.utils.LocationUtil; import net.ess3.api.IEssentials; import net.ess3.api.IUser; +import net.ess3.api.events.UserWarpEvent; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerRespawnEvent; @@ -247,6 +249,13 @@ protected void respawnNow(IUser teleportee, TeleportCause cause) throws Exceptio //The warp function is a wrapper used to teleportPlayer a player to a /warp @Override public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause cause) throws Exception { + UserWarpEvent event = new UserWarpEvent(teleportee, warp, chargeFor); + Bukkit.getServer().getPluginManager().callEvent(event); + + if(event.isCancelled()) { + return; + } + warp = event.getWarp(); Location loc = ess.getWarps().getWarp(warp); teleportee.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); if (!teleportee.equals(teleportOwner)) { diff --git a/Essentials/src/net/ess3/api/events/UserWarpEvent.java b/Essentials/src/net/ess3/api/events/UserWarpEvent.java new file mode 100644 index 00000000000..5bcafc6f325 --- /dev/null +++ b/Essentials/src/net/ess3/api/events/UserWarpEvent.java @@ -0,0 +1,65 @@ +package net.ess3.api.events; + +import com.earth2me.essentials.Trade; +import net.ess3.api.IUser; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +/** + * Called when the player use the command /warp + */ +public class UserWarpEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private IUser user; + private String warp; + private Trade trade; + private boolean cancelled = false; + + + public UserWarpEvent(IUser user, String warp, Trade trade){ + this.user = user; + this.warp = warp; + this.trade = trade; + } + + public IUser getUser() { + return user; + } + + public String getWarp() { + return warp; + } + + /** + * Getting payment handling information + * @return The payment handling class + */ + public Trade getTrade() { + return trade; + } + + public void setWarp(String warp) { + this.warp = warp; + } + + @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; + } +}