Update PluginInterceptor.java
This commit is contained in:
@@ -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<String> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user