Skip to content

fix: avoid reflective listener scans for dependency metrics#128

Open
DerMistkaefer wants to merge 1 commit intokoca2000:masterfrom
DerMistkaefer:fix/avoid-reflection-listener-scan
Open

fix: avoid reflective listener scans for dependency metrics#128
DerMistkaefer wants to merge 1 commit intokoca2000:masterfrom
DerMistkaefer:fix/avoid-reflection-listener-scan

Conversation

@DerMistkaefer
Copy link

Summary

Replace the reflective listener scan in NoteBlockAPI#onEnable() with direct event handler list inspection for NoteBlockAPI events.

Problem

The previous implementation iterated over all registered listeners of all plugins and called:

  • rl.getListener().getClass().getDeclaredMethods()

This can fail in environments that restrict reflection access to protected/internal plugin classes (e.g. custom security managers / class access guards), causing plugin startup warnings or exceptions.

Changes

Instead of scanning listener classes and method parameter types via reflection, this patch now checks listeners directly from the handler lists of NoteBlockAPI events:

  • PlayerRangeStateChangeEvent
  • SongDestroyingEvent
  • SongEndEvent
  • SongStoppedEvent

Each registered listener's owning plugin is marked as dependent.

Why this is better

  • avoids reflective access to foreign plugin listener classes
  • no dependency on method signatures / parameter scanning
  • uses Bukkit/Paper's event registration API directly
  • simpler and more robust

Compatibility

Behavior is preserved for the metrics use case (deprecated chart), while removing the reflection-based scan.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant