Adding EssentialsWarpEvent (#1921) @Banbeucmas

* Adding EssentialsWarpEvent for checking if player is wrapping

* Spacing

* Adding Trade parameter

* Refactoring

* Adding #setWarp() to the Event

* Spacing

* Documenting the purpose of the Event

* Javadoc?
This commit is contained in:
Banbeucmas 2018-10-29 01:53:52 +07:00 committed by md678685
parent a2a95ed840
commit 280d1215de
2 changed files with 74 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import com.earth2me.essentials.utils.DateUtil;
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 @@ public class Teleport implements net.ess3.api.ITeleport {
//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)) {

View File

@ -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;
}
}