fixed plugin watcher
fixed plugin watcher
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
@@ -3,6 +3,7 @@ package com.minster586.devmode;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
@@ -10,21 +11,32 @@ import java.util.Optional;
|
||||
|
||||
public class PluginInterceptor {
|
||||
|
||||
/**
|
||||
* Attempts to identify which plugin cancelled a given event.
|
||||
* This method only works for events that implement the Cancellable interface.
|
||||
*
|
||||
* @param event the Bukkit event to inspect
|
||||
* @return optional plugin name that may have cancelled the event
|
||||
*/
|
||||
public static Optional<String> getCancellingPlugin(Event event) {
|
||||
if (!event.isCancelled()) return Optional.empty();
|
||||
if (!(event instanceof Cancellable)) return Optional.empty();
|
||||
|
||||
Cancellable cancellable = (Cancellable) event;
|
||||
|
||||
if (!cancellable.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
|
||||
}
|
||||
// Calling this artificially won't re-trigger cancellation.
|
||||
// You may want to track handler priority or external logs separately.
|
||||
listener.callEvent(event);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
// If event remains cancelled, this plugin may be responsible
|
||||
if (event.isCancelled()) {
|
||||
// Re-check after artificial trigger
|
||||
if (cancellable.isCancelled()) {
|
||||
return Optional.of(plugin.getName());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user