Skip to content

fix: stop claims on a used-up grant and count remaining grants correctly - #4967

Merged
MattBDev merged 2 commits into
IntellectualSites:mainfrom
TheMeinerLP:fix/grant-count-and-claim
Nov 28, 2026
Merged

MattBDev merged 2 commits into
IntellectualSites:mainfrom
TheMeinerLP:fix/grant-count-and-claim

Conversation

@TheMeinerLP

Copy link
Copy Markdown
Member

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:

  • A player at their plot limit who redeems a grant with /plot auto ends up with a grant count of -1 instead of 0. 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 -1 after a single /plot auto and lost the other four.
  • /plot claim tells 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 auto uses the grant and leaves -1 behind, and the following /plot claim goes 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:

  1. /plot grant add <player>
  2. As the player: /plot auto – the second plot is claimed
  3. /plot grant check <player> shows -1
  4. As the player, standing on an unclaimed plot: /plot claim – the "can't claim more plots" message appears and the plot is claimed regardless

What changed

  • The remaining grants after /plot auto are 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 claim now 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 claim was introduced when the messages were moved to the new caption system in 2aa5c27 (#2867).

/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.
@TheMeinerLP
TheMeinerLP requested a review from a team as a code owner November 26, 2026 20:39
@MattBDev
MattBDev requested review from a team and MattBDev and a balanced review from Copilot November 27, 2026 01:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 auto to use free slots first and preserve unused grants.
  • Stops /plot claim when 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

return true;
}

static int remainingGrants(final int grantedPlots, final int diff, final int requested) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff is a bad name. I think it's also worth to explain the logic as a javadoc comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its 6 years old comes not from me xD

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TheMeinerLP
TheMeinerLP requested a review from SirYwell November 27, 2026 09:43
@MattBDev
MattBDev merged commit d7a26b0 into IntellectualSites:main Nov 28, 2026
7 checks passed
@NotMyFault NotMyFault added the Bugfix This PR fixes a bug label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants