Skip to content

Commit

Permalink
Merge pull request #114 from retromcorg/resolve-ignore-cancelle
Browse files Browse the repository at this point in the history
Resolve issues with Event IgnoreCancelled annotation being ignored
  • Loading branch information
Grassboii authored Dec 1, 2024
2 parents f22fa8d + 547feeb commit d27e141
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/main/java/org/bukkit/plugin/RegisteredListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit.plugin;

import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;

Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public Map<Class<? extends Event>, Set<RegisteredListener>> 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;
}
Expand Down

0 comments on commit d27e141

Please sign in to comment.