From 26d60389a728175ac691b6214d7f74287d049ebd Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Wed, 23 Oct 2024 10:59:04 +0100 Subject: [PATCH] Fix health not being restored properly with custom attributes --- .../arena/competition/PlayerStorage.java | 16 ++++++++-------- .../event/action/types/JoinRandomTeamAction.java | 10 +++++++++- 2 files changed, 17 insertions(+), 9 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 d9649f1c..55666902 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java @@ -114,7 +114,7 @@ private void storeAttributes() { if (instance == null) { continue; } - + this.attributes.put(attribute, instance.getBaseValue()); } @@ -172,8 +172,8 @@ public void restore(Set toRestore) { private void restoreAll() { this.restoreInventory(); this.restoreGameMode(); - this.restoreHealth(); this.restoreAttributes(); + this.restoreHealth(); this.restoreExperience(); this.restoreFlight(); this.restoreEffects(); @@ -188,11 +188,6 @@ private void restoreGameMode() { this.player.getPlayer().setGameMode(this.gameMode); } - private void restoreHealth() { - this.player.getPlayer().setHealth(this.health); - this.player.getPlayer().setFoodLevel(this.hunger); - } - private void restoreAttributes() { for (Map.Entry entry : this.attributes.entrySet()) { AttributeInstance instance = this.player.getPlayer().getAttribute(entry.getKey()); @@ -207,6 +202,11 @@ private void restoreAttributes() { this.player.getPlayer().setFlySpeed(this.flySpeed); } + private void restoreHealth() { + this.player.getPlayer().setHealth(this.health); + this.player.getPlayer().setFoodLevel(this.hunger); + } + private void restoreFlight() { this.player.getPlayer().setAllowFlight(this.allowFlight); this.player.getPlayer().setFlying(this.flight); @@ -293,8 +293,8 @@ public enum Type { ALL(PlayerStorage::storeAll, PlayerStorage::restoreAll), INVENTORY(PlayerStorage::storeInventory, PlayerStorage::restoreInventory), GAMEMODE(PlayerStorage::storeGameMode, PlayerStorage::restoreGameMode), - HEALTH(PlayerStorage::storeHealth, PlayerStorage::restoreHealth), ATTRIBUTES(PlayerStorage::storeAttributes, PlayerStorage::restoreAttributes), + HEALTH(PlayerStorage::storeHealth, PlayerStorage::restoreHealth), EXPERIENCE(PlayerStorage::storeExperience, PlayerStorage::restoreExperience), FLIGHT(PlayerStorage::storeFlight, PlayerStorage::restoreFlight), EFFECTS(PlayerStorage::storeEffects, PlayerStorage::restoreEffects), diff --git a/plugin/src/main/java/org/battleplugins/arena/event/action/types/JoinRandomTeamAction.java b/plugin/src/main/java/org/battleplugins/arena/event/action/types/JoinRandomTeamAction.java index c7ba6327..c0884204 100644 --- a/plugin/src/main/java/org/battleplugins/arena/event/action/types/JoinRandomTeamAction.java +++ b/plugin/src/main/java/org/battleplugins/arena/event/action/types/JoinRandomTeamAction.java @@ -4,6 +4,7 @@ import org.battleplugins.arena.competition.team.TeamManager; import org.battleplugins.arena.event.action.EventAction; import org.battleplugins.arena.resolver.Resolvable; +import org.battleplugins.arena.team.ArenaTeam; import java.util.Map; @@ -16,7 +17,14 @@ public JoinRandomTeamAction(Map params) { public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) { if (arenaPlayer.getTeam() == null) { TeamManager teamManager = arenaPlayer.getCompetition().getTeamManager(); - teamManager.joinTeam(arenaPlayer, teamManager.findSuitableTeam()); + + ArenaTeam suitableTeam = teamManager.findSuitableTeam(); + if (suitableTeam == null) { + arenaPlayer.getArena().getPlugin().warn("A suitable team could not be found for player {}!", arenaPlayer.getPlayer().getName()); + return; + } + + teamManager.joinTeam(arenaPlayer, suitableTeam); } } }