From 547feeb7ff4e24e767b96d4dd4e7563df0c10143 Mon Sep 17 00:00:00 2001 From: Rhys B Date: Sun, 1 Dec 2024 11:48:44 +1000 Subject: [PATCH] Resolve issues with Event IgnoreCancelled annotation being ignored --- .../org/bukkit/plugin/RegisteredListener.java | 25 +++++++++++++------ .../bukkit/plugin/java/JavaPluginLoader.java | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bukkit/plugin/RegisteredListener.java b/src/main/java/org/bukkit/plugin/RegisteredListener.java index 46d054f1..8a3207f2 100644 --- a/src/main/java/org/bukkit/plugin/RegisteredListener.java +++ b/src/main/java/org/bukkit/plugin/RegisteredListener.java @@ -1,5 +1,6 @@ package org.bukkit.plugin; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.Listener; @@ -11,19 +12,22 @@ public class RegisteredListener { private final Event.Priority priority; private final Plugin plugin; private final EventExecutor executor; + private final boolean ignoreCancelled; public RegisteredListener(final Listener pluginListener, final EventExecutor eventExecutor, final Event.Priority eventPriority, final Plugin registeredPlugin) { - listener = pluginListener; - priority = eventPriority; - plugin = registeredPlugin; - executor = eventExecutor; + this(pluginListener, eventExecutor, eventPriority, registeredPlugin, false); + } + + public RegisteredListener(final Listener pluginListener, final EventExecutor eventExecutor, final Event.Priority eventPriority, final Plugin registeredPlugin, final boolean ignoreCancelled) { + this.listener = pluginListener; + this.priority = eventPriority; + this.plugin = registeredPlugin; + this.executor = eventExecutor; + this.ignoreCancelled = ignoreCancelled; } public RegisteredListener(final Listener pluginListener, final Event.Priority eventPriority, final Plugin registeredPlugin, Event.Type type) { - listener = pluginListener; - priority = eventPriority; - plugin = registeredPlugin; - executor = registeredPlugin.getPluginLoader().createExecutor(type, pluginListener); + this(pluginListener, registeredPlugin.getPluginLoader().createExecutor(type, pluginListener), eventPriority, registeredPlugin, false); } public void registerAll() { @@ -59,6 +63,11 @@ public Event.Priority getPriority() { * @return Registered Priority */ public void callEvent(Event event) { + if(event instanceof Cancellable) { + if(((Cancellable) event).isCancelled() && ignoreCancelled) { + return; + } + } executor.execute(listener, event); } } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 06800d4f..6ff0e708 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -272,7 +272,7 @@ public Map, Set> createRegisteredList e.printStackTrace(); } }; - eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin)); + eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); } return ret; }