Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public boolean updatePlayer(Player player, ProfileData profile) {
/**
* Sharing Max Health.
*/
//todo: maybe store attribute modifier as well
public static final Sharable<Double> MAX_HEALTH = new Sharable.Builder<>("max_hit_points", Double.class,
new SharableHandler<Double>() {
@Override
Expand Down Expand Up @@ -231,22 +232,22 @@ public void updateProfile(ProfileData profile, Player player) {
@Override
public boolean updatePlayer(Player player, ProfileData profile) {
Double value = profile.get(HEALTH);
if (value == null) {
player.setHealth(PlayerStats.HEALTH);
return false;
}
try {
if (value == null) {
player.setHealth(PlayerStats.HEALTH);
return false;
}
double maxHealth = getMaxHealth(player);
// This share may handled before MAX_HEALTH.
// Thus this is needed to ensure there is no loss in health stored
if (value > maxHealth) {
Option.of(maxHealthAttr).map(player::getAttribute)
.peek(attr -> attr.setBaseValue(maxHealth));
.peek(attr -> attr.setBaseValue(value));
}
player.setHealth(value);
} catch (IllegalArgumentException e) {
Logging.fine("Invalid value '" + value + "': " + e.getMessage());
player.setHealth(PlayerStats.HEALTH);
Logging.warning("Invalid value '" + value + "': " + e.getMessage());
player.setHealth(getMaxHealth(player));
return false;
}
return true;
Expand All @@ -257,7 +258,7 @@ public boolean updatePlayer(Player player, ProfileData profile) {

private static double getMaxHealth(Player player) {
return Option.of(maxHealthAttr).map(player::getAttribute)
.map(AttributeInstance::getValue)
.map(AttributeInstance::getBaseValue)
.getOrElse(PlayerStats.MAX_HEALTH);
}

Expand Down
Loading