From 23a5a7200baa860432e90ac9cc00cc94207213a3 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 14 Jul 2024 14:20:45 -0500 Subject: [PATCH] Fix a bug with experience storage --- .../arena/competition/PlayerStorage.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java b/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java index 20a403ca..c8592932 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java @@ -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; @@ -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(); } @@ -147,6 +149,7 @@ public void restore(Set toRestore) { this.attributes.clear(); this.health = 0; this.hunger = 0; + this.totalExp = 0; this.exp = 0; this.expLevels = 0; this.effects.clear(); @@ -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); } @@ -250,6 +259,7 @@ private void clearState(Set toStore) { if (all || toStore.contains(Type.EXPERIENCE)) { this.player.getPlayer().setTotalExperience(0); + this.player.getPlayer().setExp(0); this.player.getPlayer().setLevel(0); }