Bukkit/CraftBukkit — pull request #571 by jhaegg (2011-12-06 14:01:38+00:00)
Title: Fix for two experience issues.

This fixes the following problems

1. /xp 6, /xp 8 makes the player lvl 2 while /xp 8, /xp 6 make the player level ~1.7.

This is not a huge problem but if you have a system where the player retains experience after death this error will become quite big. If the player is set to respawn with 700 experience points the player will be level 100. If the player were to reach level 100 by ordinary means this would require 18 357 experience points.

2. Enchantments do not cause the players total experience to change.

The solution I am proposing might not be the most elegant but it does not require any removed or modified lines in net.minecraft.server, just three single line inserts (excluding comments) and a few changes to CraftPlayer. This did require a magic number to compensate for floating point drift, a solution which I am not very happy about but it works fine even when 50+ iterations are performed which should be enough for normal use.

I am currently testing it on a server (after performing my own tests ofc.) which relies heavily on set/getTotalExperience working correctly and everything seems to be working fine.