diff --git a/src/main/java/me/hsgamer/yatpa/event/TeleportRequestEvent.java b/src/main/java/me/hsgamer/yatpa/event/TeleportRequestEvent.java new file mode 100644 index 0000000..f833597 --- /dev/null +++ b/src/main/java/me/hsgamer/yatpa/event/TeleportRequestEvent.java @@ -0,0 +1,40 @@ +package me.hsgamer.yatpa.event; + +import me.hsgamer.yatpa.request.RequestEntry; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class TeleportRequestEvent extends Event implements Cancellable { + private static final HandlerList HANDLERS = new HandlerList(); + private final RequestEntry requestEntry; + private boolean cancelled; + + public TeleportRequestEvent(RequestEntry requestEntry) { + this.requestEntry = requestEntry; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + public RequestEntry getRequestEntry() { + return requestEntry; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/src/main/java/me/hsgamer/yatpa/request/RequestManager.java b/src/main/java/me/hsgamer/yatpa/request/RequestManager.java index 80da74e..052a58c 100644 --- a/src/main/java/me/hsgamer/yatpa/request/RequestManager.java +++ b/src/main/java/me/hsgamer/yatpa/request/RequestManager.java @@ -3,6 +3,7 @@ import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import me.hsgamer.yatpa.YATPA; +import me.hsgamer.yatpa.event.TeleportRequestEvent; import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -30,6 +31,12 @@ public RequestStatus request(RequestEntry requestEntry) { return RequestStatus.ALREADY_SENT; } + TeleportRequestEvent event = new TeleportRequestEvent(requestEntry); + plugin.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return RequestStatus.CANCELLED; + } + requestTable.put(requester, target, requestEntry); return RequestStatus.SUCCESS; } diff --git a/src/main/java/me/hsgamer/yatpa/request/RequestStatus.java b/src/main/java/me/hsgamer/yatpa/request/RequestStatus.java index e31cd00..b50fd21 100644 --- a/src/main/java/me/hsgamer/yatpa/request/RequestStatus.java +++ b/src/main/java/me/hsgamer/yatpa/request/RequestStatus.java @@ -3,4 +3,5 @@ public enum RequestStatus { SUCCESS, ALREADY_SENT, + CANCELLED, }