From 28688d54ad0a271a3a45434b2312c824840ce2fc Mon Sep 17 00:00:00 2001 From: minster586 <43217359+minster586@users.noreply.github.com> Date: Wed, 23 Jul 2025 18:31:44 -0400 Subject: [PATCH] Update PluginInterceptor.java --- .../minster586/devmode/PluginInterceptor.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) 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(); + } +}