Skip to content

fix: avoid reflective listener scans for dependency metrics#128

Merged
koca2000 merged 1 commit intokoca2000:masterfrom
DerMistkaefer:fix/avoid-reflection-listener-scan
Mar 25, 2026
Merged

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

Conversation

@DerMistkaefer
Copy link
Contributor

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

@koca2000
Copy link
Owner

Thank you for the PR. It will be released in version 1.7.0.

@koca2000 koca2000 merged commit 5319a09 into koca2000:master Mar 25, 2026
2 checks passed
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.

2 participants