Skip to content

Fix donated points calculation using stale stored total instead of current block values#438

Merged
tastybento merged 2 commits into
developfrom
copilot/fix-donation-calculation-issue
May 16, 2026
Merged

Fix donated points calculation using stale stored total instead of current block values#438
tastybento merged 2 commits into
developfrom
copilot/fix-donation-calculation-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

The donated block points were accumulated in the DB at donation-time block config values. When an admin later changes block values, tidyUp() was still using the stale stored total — causing level calculations where the reported total was less than a single block type's current contribution (e.g. total = 49,348 while Iron Block alone = 3,553 × 14 = 49,742).

Changes

  • IslandLevelCalculator.tidyUp(): Replace the stale getDonatedPoints() DB read with a dynamic recalculation from the donatedBlocks count map × current block config values. Keys are lowercased to match the stored config format.
// Before
long donatedPoints = addon.getManager().getDonatedPoints(island);

// After — always reflects current block config
Map<String, Integer> donatedBlocksMap = addon.getManager().getDonatedBlocks(island);
long donatedPoints = donatedBlocksMap.entrySet().stream()
        .mapToLong(entry -> {
            Integer value = addon.getBlockConfig().getValue(island.getWorld(),
                    entry.getKey().toLowerCase(java.util.Locale.ENGLISH));
            return (long) Objects.requireNonNullElse(value, 0) * entry.getValue();
        })
        .sum();
  • getReport(): Updated the per-block value lookup to use getValue(world, key) (world-specific) instead of the flat getBlockValues() map, making the report consistent with the calculation.

Copilot AI linked an issue May 15, 2026 that may be closed by this pull request
…block config values

Instead of reading the stale accumulated donatedPoints value stored in the database
(which was calculated at donation-time using then-current block values), dynamically
recalculate the donated points from the donatedBlocks map using the current block
config values on every level calculation.

This fixes incorrect level calculations when block config values change after blocks
have been donated. Previously the stored total could be less than a single block
type's current contribution, as seen in the issue where Iron Block x 3,553 = 49,742
points but the total donated points reported was only 49,348.

Also update the getReport() donated block section to use getValue(world, key) for
world-specific block value lookups, consistent with how the calculation works.

Fixes #nnn

Agent-Logs-Url: https://github.com/BentoBoxWorld/Level/sessions/8d20bea9-7362-4af9-aa27-e0ae175eec2a

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect level calculation for donation Fix donated points calculation using stale stored total instead of current block values May 16, 2026
Copilot AI requested a review from tastybento May 16, 2026 00:02
@tastybento tastybento marked this pull request as ready for review May 16, 2026 00:17
@sonarqubecloud
Copy link
Copy Markdown

@tastybento tastybento merged commit ee568ba into develop May 16, 2026
3 checks passed
@tastybento tastybento deleted the copilot/fix-donation-calculation-issue branch May 16, 2026 00:19
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.

Not correct level caculation for donation

2 participants