-
Notifications
You must be signed in to change notification settings - Fork 13
Regear fix for 1.21.8+ #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughRefactors regearKit loop to use a precomputed maxIndex for iteration and removes a redundant continue statement within an assignment branch. No public APIs or signatures changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/java/dev/noah/perplayerkit/KitManager.java (2)
303-305: Clone ItemStack before assignment to prevent kit mutation via shared references.Assigning the same ItemStack instance from the stored kit into the player inventory means later in-inventory mutations (durability, meta edits, enchants) can mutate the saved kit in memory. Clone on write.
- playerInventory[i] = kit[i]; + playerInventory[i] = kit[i].clone();
307-308: Enforce inventory update on every regearKit call
RegearCommand.java:105 invokesKitManager.get().regearKit(player, slot)without a subsequentplayer.updateInventory(), causing potential visual desync. Addplayer.updateInventory()after this call—or centralize the call by addingplayer.updateInventory()inKitManager.regearKitimmediately afterplayer.getInventory().setContents(...).
🧹 Nitpick comments (2)
src/main/java/dev/noah/perplayerkit/KitManager.java (2)
286-289: LGTM: clearer bound with precomputed maxIndex.Precomputing the loop bound improves readability and avoids repeated Math.min calls. Consider marking it final for intent.
- int maxIndex = Math.min(kit.length, playerInventory.length); + final int maxIndex = Math.min(kit.length, playerInventory.length);
288-301: Avoid per-iteration String material checks; precompute Material set once.Using toString() each iteration and a String Set is wasteful and brittle. Convert config strings to Material once, then compare enums in the loop.
Add import:
+import org.bukkit.Material;Precompute before the loop:
Set<Material> wlMaterials = new HashSet<>(); for (String s : whitelist) { Material m = Material.matchMaterial(s); if (m != null) wlMaterials.add(m); }Then replace the checks inside the loop:
- if (invertWhitelist) { - if (whitelist.contains(kit[i].getType().toString())) { + if (invertWhitelist) { + if (wlMaterials.contains(kit[i].getType())) { continue; } - } else { - if (!whitelist.contains(kit[i].getType().toString())) { + } else { + if (!wlMaterials.contains(kit[i].getType())) { continue; } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/main/java/dev/noah/perplayerkit/KitManager.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/dev/noah/perplayerkit/KitManager.java (1)
src/main/java/dev/noah/perplayerkit/commands/RegearCommand.java (7)
RegearInventoryHolder(191-200)Override(56-116)RegearCommand(27-201)EventHandler(147-188)Override(194-199)EventHandler(118-145)RegearCommand(38-46)
1.21.8 error log
Summary by CodeRabbit