Repository navigation
fix: stop claims on a used-up grant and count remaining grants correctly - #4967
Merged
MattBDev merged 2 commits intoNov 28, 2026
Merged
Conversation
/plot auto stored a negative grant count once the plot limit was reached, and /plot claim reported the missing grant but claimed the plot anyway.
MattBDev
approved these changes
Nov 27, 2026
MattBDev
requested review from
a team and
MattBDev
and
a balanced review from Copilot
November 27, 2026 01:10
MattBDev
approved these changes
Nov 27, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the plot-grant accounting and enforcement update.
No open issues 🎉
What changed in this PR
This PR fixes plot-grant accounting and enforcement so each grant permits one additional plot beyond a player’s limit.
Changes:
- Corrects
/plot autoto use free slots first and preserve unused grants. - Stops
/plot claimwhen the player has no grants left. - Adds eight unit tests for remaining-grant calculations across single-plot and 2×2 requests.
| File | Description |
|---|---|
| Core/src/test/java/com/plotsquared/core/command/AutoGrantTest.java | Tests grant calculations with free slots, exceeded limits, and surplus grants. |
| Core/src/main/java/com/plotsquared/core/command/Claim.java | Returns immediately after rejecting a claim with depleted grants. |
| Core/src/main/java/com/plotsquared/core/command/Auto.java | Calculates remaining grants from the current balance and plots exceeding free slots. |
Review effort: Balanced
SirYwell
reviewed
Nov 27, 2026
| return true; | ||
| } | ||
|
|
||
| static int remainingGrants(final int grantedPlots, final int diff, final int requested) { |
Member
There was a problem hiding this comment.
diff is a bad name. I think it's also worth to explain the logic as a javadoc comment.
Member
Author
There was a problem hiding this comment.
Its 6 years old comes not from me xD
Member
Author
There was a problem hiding this comment.
You're right, the old local variable is from before, but this parameter is new in this PR. Renamed it to freeSlots and added a Javadoc explaining the calculation in 4a5b3fa.
SirYwell
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
Plot grants are meant to let a player claim one extra plot beyond their limit per grant. Two long-standing mistakes break that count:
/plot autoends up with a grant count of-1instead of0. The stored value was calculated from the free slots and the requested plots only; the number of grants the player actually had was ignored. A player holding five grants therefore also dropped to-1after a single/plot autoand lost the other four./plot claimtells a player with a used-up grant count that they cannot claim more plots, but then claims the plot anyway.Together this turns one grant into two plots:
/plot autouses the grant and leaves-1behind, and the following/plot claimgoes through despite the message. The same happens for multi-plot claims such as/plot auto 2,2, where the stored value becomes even more negative.How to reproduce (7.6.1)
With a non-op player limited to one plot (
plots.plot.1) who already owns one plot:/plot grant add <player>/plot auto– the second plot is claimed/plot grant check <player>shows-1/plot claim– the "can't claim more plots" message appears and the plot is claimed regardlessWhat changed
/plot autoare now the player's grants minus the plots that did not fit into their free slots, so free slots are used first and grants only pay for the rest./plot claimnow stops after reporting that no grants are left.The calculation is covered by unit tests for single plots and for 2x2 claims (at the limit, over the limit, with free slots left, and with grants to spare).
Background
The calculation dates back to 179e9e1 (May 2020); the missing early exit in
/plot claimwas introduced when the messages were moved to the new caption system in 2aa5c27 (#2867).