Skip to content

Commit

Permalink
Fix health not being restored properly with custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Oct 23, 2024
1 parent 30647d6 commit 26d6038
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void storeAttributes() {
if (instance == null) {
continue;
}

this.attributes.put(attribute, instance.getBaseValue());
}

Expand Down Expand Up @@ -172,8 +172,8 @@ public void restore(Set<Type> toRestore) {
private void restoreAll() {
this.restoreInventory();
this.restoreGameMode();
this.restoreHealth();
this.restoreAttributes();
this.restoreHealth();
this.restoreExperience();
this.restoreFlight();
this.restoreEffects();
Expand All @@ -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<Attribute, Double> entry : this.attributes.entrySet()) {
AttributeInstance instance = this.player.getPlayer().getAttribute(entry.getKey());
Expand All @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,7 +17,14 @@ public JoinRandomTeamAction(Map<String, String> 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);
}
}
}

0 comments on commit 26d6038

Please sign in to comment.