Skip to content

Fix XP increase when restoring advancements on world switch#47

Merged
tastybento merged 3 commits into
developfrom
copilot/fix-experience-increase-on-teleport
May 20, 2026
Merged

Fix XP increase when restoring advancements on world switch#47
tastybento merged 3 commits into
developfrom
copilot/fix-experience-increase-on-teleport

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Some Minecraft advancements reward XP when their criteria are awarded. When setAdvancements() restored a player's advancements on world entry, those XP rewards fired, increasing the player's experience beyond the stored value on every teleport.

Changes

  • Store.setAdvancements(): Save the player's current XP before calling awardCriteria() on any advancement, then restore it afterward. Returns early if there are no stored advancements to avoid unnecessary XP calls.
// Save current experience before granting advancements, because some advancements
// reward XP when their criteria are awarded, which would incorrectly increase the
// player's experience points.
int savedExp = getTotalExperience(player);
advancements.forEach((k, v) -> { ... });
// Restore experience to prevent advancement rewards from modifying it
setTotalExperience(player, savedExp);
  • StoreTest: Add testGetInventoryAdvancementsPreservesExperience — stores a player with a completed advancement, then calls getInventory and asserts setTotalExperience is called the expected number of times (including the restoration call inside setAdvancements).

Copilot AI and others added 2 commits May 20, 2026 22:07
When granting advancement criteria via awardCriteria(), some Minecraft
advancements reward XP, causing the player's experience to increase on
every world switch. Fix by saving the player's current XP before
granting advancement criteria in setAdvancements() and restoring it
afterward.

Also add test testGetInventoryAdvancementsPreservesExperience to verify
that setTotalExperience is called after advancement criteria are awarded,
ensuring XP is properly restored.

Agent-Logs-Url: https://github.com/BentoBoxWorld/InvSwitcher/sessions/dde552a1-224e-42d1-94cb-218e3609eaf8

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix experience points increase when teleporting worlds Fix XP increase when restoring advancements on world switch May 20, 2026
Copilot AI requested a review from tastybento May 20, 2026 22:08
@tastybento tastybento marked this pull request as ready for review May 20, 2026 22:15
@sonarqubecloud
Copy link
Copy Markdown

@tastybento tastybento merged commit 76f86cf into develop May 20, 2026
3 checks passed
@tastybento tastybento deleted the copilot/fix-experience-increase-on-teleport branch May 20, 2026 22:18
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.

When teleporting between a non-BentoBox world and a BentoBox world, experience points automatically increase.

2 participants