GH-227 Sort combat regions by priority which supports overlapping regions in knockback feature#227
GH-227 Sort combat regions by priority which supports overlapping regions in knockback feature#227
Conversation
… knockback feature Took 1 hour 18 minutes
… knockback feature Took 1 hour 18 minutes Took 15 seconds
WalkthroughThe change refactors how the code finds a region for a given location. It adds a new method that picks the region with the highest priority from a set of applicable regions. The main method now uses this helper to return the top-priority combat region if one exists, or nothing if none do. This replaces the old approach that returned the first combat region found during iteration. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java(3 hunks)
🔇 Additional comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java (1)
36-51: Nice refactoring!The updated method is cleaner and easier to follow by delegating the priority logic to a helper method.
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java
Show resolved
Hide resolved
Took 9 minutes
Took 4 minutes
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java (1)
125-125:⚠️ Potential issueCritical bug: Still sorting by lowest priority instead of highest!
The sorting bug from previous reviews is still present. You're sorting in ascending order and taking the first element, which gives the lowest priority region, not the highest.
Fix this by reversing the sort order:
- .sorted(Comparator.comparingInt(ProtectedRegion::getPriority)) + .sorted(Comparator.comparingInt(ProtectedRegion::getPriority).reversed())
🧹 Nitpick comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java (1)
111-111: Consider making this method private.The method doesn't need package visibility since it's only used internally.
- ProtectedRegion highestPriorityRegion(ApplicableRegionSet applicableRegions) { + private ProtectedRegion highestPriorityRegion(ApplicableRegionSet applicableRegions) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (2)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/region/WorldGuardRegionProvider.java (2)
16-18: Import additions look good.The new imports for
ComparatorandSetsupport the priority-based sorting functionality.
41-49: Good refactor to use priority-based selection.The logic change to use the new helper method makes the code cleaner and implements the priority-based region selection as intended.
Sorting mechanism does not work for border, particles and delayed knockback