diff --git a/src/main/java/com/minster586/devmode/PluginInterceptor.java b/src/main/java/com/minster586/devmode/PluginInterceptor.java index 8b13789..2dd10a8 100644 --- a/src/main/java/com/minster586/devmode/PluginInterceptor.java +++ b/src/main/java/com/minster586/devmode/PluginInterceptor.java @@ -1 +1,34 @@ +package com.minster586.devmode; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredListener; + +import java.util.Optional; + +public class PluginInterceptor { + + public static Optional getCancellingPlugin(Event event) { + if (!event.isCancelled()) return Optional.empty(); + + HandlerList handlerList = event.getHandlers(); + for (RegisteredListener listener : handlerList.getRegisteredListeners()) { + Plugin plugin = listener.getPlugin(); + + try { + listener.callEvent(event); // Simulate who handles it + } catch (Exception ignored) { + // Ignore exceptions thrown during simulated call + } + + // If event remains cancelled, this plugin may be responsible + if (event.isCancelled()) { + return Optional.of(plugin.getName()); + } + } + + return Optional.empty(); + } +}