Include total experience in SetExperience step.

It turns out that experience in Minecraft is split out on a couple of different variables, and they are only loosely coupled.

Total experience, level, and level progress are three completely different variables that can be manipulated individually. This means that while 10 experience points from level 0 should bring you up to level 1 with a third of the experience bar full (level 0 to 1 takes 7 points, level 1 to 2 takes 9 points), simply setting the total points value to 10 won't automatically level you up. Using the Player#giveExp(int) method will, however, work this way.
This commit is contained in:
Andreas Troelsen 2018-08-18 23:47:15 +02:00
parent 95e2abdee9
commit fbb5fe7c4a
2 changed files with 5 additions and 0 deletions

View File

@ -21,6 +21,7 @@ These changes will (most likely) be included in the next version.
- The reload command now also reloads global settings, e.g. the global messenger prefix.
- Armor stands can now be placed in arenas and lobbies.
- The new command `/ma ready` (`/ma rdy` for short) can be used as an alternative to the iron block for readying up.
- Total experience is now correctly stored, reset, and restored on arena join/leave. This fixes a potential bug where total experience could increase in the arena, but levels and progress would still get reset at arena end.
Thanks to:
- Sait for adding the /ma ready command

View File

@ -3,6 +3,7 @@ package com.garbagemule.MobArena.steps;
import org.bukkit.entity.Player;
class SetExperience extends PlayerStep {
private int total;
private int level;
private float exp;
@ -12,15 +13,18 @@ class SetExperience extends PlayerStep {
@Override
public void run() {
total = player.getTotalExperience();
level = player.getLevel();
exp = player.getExp();
player.setExp(0);
player.setLevel(0);
player.setTotalExperience(0);
}
@Override
public void undo() {
player.setTotalExperience(total);
player.setLevel(level);
player.setExp(exp);
}