Fix cancel checking causing errors
This commit is contained in:
parent
9cc31658a1
commit
eb44131801
@ -2,6 +2,7 @@ package org.patchbukkit.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -37,6 +38,13 @@ public class PatchBukkitEventFactory {
|
||||
return new PlayerQuitEvent(player, quitMessage, PlayerQuitEvent.QuitReason.DISCONNECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an event implements Cancellable.
|
||||
*/
|
||||
public static boolean isCancellable(@NotNull Event event) {
|
||||
return event instanceof org.bukkit.event.Cancellable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a player by UUID string. Returns null with a warning if not found.
|
||||
*/
|
||||
|
||||
@ -51,13 +51,22 @@ impl EventManager {
|
||||
],
|
||||
)?;
|
||||
|
||||
let cancelled = match jvm.invoke(
|
||||
&jvm.clone_instance(&j_event)?,
|
||||
"isCancelled",
|
||||
InvocationArg::empty(),
|
||||
) {
|
||||
Ok(instance) => jvm.to_rust::<bool>(instance).unwrap_or(false),
|
||||
Err(_) => false,
|
||||
let is_cancellable: bool = jvm.to_rust(jvm.invoke_static(
|
||||
"org.patchbukkit.events.PatchBukkitEventFactory",
|
||||
"isCancellable",
|
||||
&[InvocationArg::from(jvm.clone_instance(&j_event)?)],
|
||||
)?)?;
|
||||
|
||||
let cancelled = match is_cancellable {
|
||||
true => match jvm.invoke(
|
||||
&jvm.clone_instance(&j_event)?,
|
||||
"isCancelled",
|
||||
InvocationArg::empty(),
|
||||
) {
|
||||
Ok(instance) => jvm.to_rust::<bool>(instance).unwrap_or(false),
|
||||
Err(_) => false,
|
||||
},
|
||||
false => false,
|
||||
};
|
||||
|
||||
Ok(cancelled)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user