Skip to content

Commit

Permalink
Fix a bug with experience storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 14, 2024
1 parent 55910ca commit 23a5a72
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public class PlayerStorage {

private double health;
private int hunger;

private int exp;

private int totalExp;
private float exp;
private int expLevels;

private float walkSpeed;
Expand Down Expand Up @@ -111,7 +112,8 @@ private void storeAttributes() {
}

private void storeExperience() {
this.exp = this.player.getPlayer().getTotalExperience();
this.totalExp = this.player.getPlayer().getTotalExperience();
this.exp = this.player.getPlayer().getExp();
this.expLevels = this.player.getPlayer().getLevel();
}

Expand Down Expand Up @@ -147,6 +149,7 @@ public void restore(Set<Type> toRestore) {
this.attributes.clear();
this.health = 0;
this.hunger = 0;
this.totalExp = 0;
this.exp = 0;
this.expLevels = 0;
this.effects.clear();
Expand Down Expand Up @@ -199,11 +202,17 @@ private void restoreFlight() {
}

private void restoreExperience() {
this.player.getPlayer().setTotalExperience(this.exp);
this.player.getPlayer().setTotalExperience(this.totalExp);
this.player.getPlayer().setExp(this.exp);
this.player.getPlayer().setLevel(this.expLevels);
}

private void restoreEffects() {
// Clear all effects from the arena
for (PotionEffect effect : this.player.getPlayer().getActivePotionEffects()) {
this.player.getPlayer().removePotionEffect(effect.getType());
}

for (PotionEffect effect : this.effects) {
this.player.getPlayer().addPotionEffect(effect);
}
Expand Down Expand Up @@ -250,6 +259,7 @@ private void clearState(Set<Type> toStore) {

if (all || toStore.contains(Type.EXPERIENCE)) {
this.player.getPlayer().setTotalExperience(0);
this.player.getPlayer().setExp(0);
this.player.getPlayer().setLevel(0);
}

Expand Down

0 comments on commit 23a5a72

Please sign in to comment.