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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -37,6 +38,13 @@ public class PatchBukkitEventFactory {
|
|||||||
return new PlayerQuitEvent(player, quitMessage, PlayerQuitEvent.QuitReason.DISCONNECTED);
|
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.
|
* 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(
|
let is_cancellable: bool = jvm.to_rust(jvm.invoke_static(
|
||||||
&jvm.clone_instance(&j_event)?,
|
"org.patchbukkit.events.PatchBukkitEventFactory",
|
||||||
"isCancelled",
|
"isCancellable",
|
||||||
InvocationArg::empty(),
|
&[InvocationArg::from(jvm.clone_instance(&j_event)?)],
|
||||||
) {
|
)?)?;
|
||||||
Ok(instance) => jvm.to_rust::<bool>(instance).unwrap_or(false),
|
|
||||||
Err(_) => false,
|
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)
|
Ok(cancelled)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user