Skip to content

Commit

Permalink
add request event
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Feb 1, 2024
1 parent 492cb60 commit f45e300
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/java/me/hsgamer/yatpa/event/TeleportRequestEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
7 changes: 7 additions & 0 deletions src/main/java/me/hsgamer/yatpa/request/RequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/hsgamer/yatpa/request/RequestStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public enum RequestStatus {
SUCCESS,
ALREADY_SENT,
CANCELLED,
}

0 comments on commit f45e300

Please sign in to comment.