Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spigot fallback to sign open event #6920

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class TownyPaperEvents implements Listener {
private static final String PAPER_PRIME_EVENT = "com.destroystokyo.paper.event.block.TNTPrimeEvent";

private static final String SIGN_OPEN_EVENT = "io.papermc.paper.event.player.PlayerOpenSignEvent";
private static final String SPIGOT_SIGN_OPEN_EVENT = "org.bukkit.event.player.PlayerSignOpenEvent";

public TownyPaperEvents(Towny plugin) {
this.plugin = plugin;
Expand All @@ -63,7 +64,7 @@ else if (GET_PRIMER_ENTITY != null) {
}

if (SIGN_OPEN_GET_CAUSE != null) {
registerEvent(SIGN_OPEN_EVENT, this::openSignListener, EventPriority.LOW, true);
registerEvent(JavaUtil.classExists(SIGN_OPEN_EVENT) ? SIGN_OPEN_EVENT : SPIGOT_SIGN_OPEN_EVENT, this::openSignListener, EventPriority.LOW, true);
TownyMessaging.sendDebugMsg("PlayerOpenSignEvent#getCause found, using PlayerOpenSignEvent listener.");
}
}
Expand Down Expand Up @@ -179,18 +180,20 @@ private static MethodHandle getPrimerEntityHandle() {
}

private static MethodHandle getSignOpenCauseHandle() {
final String eventClass = JavaUtil.classExists(SIGN_OPEN_EVENT) ? SIGN_OPEN_EVENT : SPIGOT_SIGN_OPEN_EVENT;
try {
// https://jd.papermc.io/paper/1.20/io/papermc/paper/event/player/PlayerOpenSignEvent.html
return MethodHandles.publicLookup().unreflect(Class.forName(SIGN_OPEN_EVENT).getMethod("getCause"));
return MethodHandles.publicLookup().unreflect(Class.forName(eventClass).getMethod("getCause"));
} catch (ReflectiveOperationException e) {
return null;
}
}

private static MethodHandle getSignOpenGetSignHandle() {
final String eventClass = JavaUtil.classExists(SIGN_OPEN_EVENT) ? SIGN_OPEN_EVENT : SPIGOT_SIGN_OPEN_EVENT;
try {
// https://jd.papermc.io/paper/1.20/io/papermc/paper/event/player/PlayerOpenSignEvent.html
return MethodHandles.publicLookup().unreflect(Class.forName(SIGN_OPEN_EVENT).getMethod("getSign"));
return MethodHandles.publicLookup().unreflect(Class.forName(eventClass).getMethod("getSign"));
} catch (ReflectiveOperationException e) {
return null;
}
Expand Down