Skip to content

fix: cap donated block counts to current block limits in level calculation#443

Merged
tastybento merged 2 commits into
developfrom
copilot/fix-donate-blocks-counting
May 20, 2026
Merged

fix: cap donated block counts to current block limits in level calculation#443
tastybento merged 2 commits into
developfrom
copilot/fix-donate-blocks-counting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

When a block's donation limit is lowered after players have already donated above the new threshold, the excess blocks continue counting toward island level. The donated count was never validated against the current limit at calculation time.

Changes

  • IslandLevelCalculator.tidyUp(): When computing donated points, look up the current block limit for each donated block type and apply Math.min(donatedCount, limit) before multiplying by value. This mirrors the existing limitCountAndValue() enforcement applied to on-island blocks during chunk scanning.
// Before — no limit applied to donated count
return (long) Objects.requireNonNullElse(value, 0) * entry.getValue();

// After — donated count capped to current limit
int count = entry.getValue();
Integer limit = addon.getBlockConfig().getLimit(key);
if (limit != null) {
    count = Math.min(count, limit);
}
return (long) Objects.requireNonNullElse(value, 0) * count;
  • IslandLevelCalculatorTidyUpTest: Three new tests covering donated-under-limit (full count used), donated-over-limit (capped to current limit), and no limit configured (full count used).

Note: This change is retrospective — existing servers where limits were previously uncapped will see a level reduction on next recalculation for affected islands.

…lculation

When a block limit is lowered after players have already donated blocks, the
donated count is now capped to the current limit in IslandLevelCalculator.tidyUp().
This ensures excess donated blocks no longer contribute points beyond the limit.

Adds three new tests to IslandLevelCalculatorTidyUpTest covering:
- donated count under limit (full count used)
- donated count over limit (capped to current limit)
- donated count with no limit (full count used)

Agent-Logs-Url: https://github.com/BentoBoxWorld/Level/sessions/3c49eef0-18f1-4340-bdd3-2afd5ce36286

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix donate blocks counting when limit is changed fix: cap donated block counts to current block limits in level calculation May 20, 2026
Copilot AI requested a review from tastybento May 20, 2026 21:49
@tastybento tastybento marked this pull request as ready for review May 20, 2026 21:50
@sonarqubecloud
Copy link
Copy Markdown

@tastybento tastybento merged commit 0548a0a into develop May 20, 2026
3 checks passed
@tastybento tastybento deleted the copilot/fix-donate-blocks-counting branch May 20, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If donate blocks are more then limit they still counts

2 participants