Optimize settings API check in SpecialItemListener to avoid redundant calls #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses performance feedback on #13: the settings API availability check was being called inside a coroutine for every online player, causing redundant checks and unnecessary coroutine launches.
Changes
plugin.hasSettingsApi()check outside theforEachPlayerloophasSettingsApivariable to use across all player iterationsBefore
forEachPlayer { plugin.launch { if (plugin.hasSettingsApi()) { // Called N times if (settingsService.hasSoundsEnabled(it.uniqueId)) { it.playSound(...) } } } }After
Reduces check from O(N) to O(1) where N is the number of online players.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.