@@ -191,6 +191,7 @@ public boolean updatePlayer(Player player, ProfileData profile) {
191191 /**
192192 * Sharing Max Health.
193193 */
194+ //todo: maybe store attribute modifier as well
194195 public static final Sharable <Double > MAX_HEALTH = new Sharable .Builder <>("max_hit_points" , Double .class ,
195196 new SharableHandler <Double >() {
196197 @ Override
@@ -231,22 +232,22 @@ public void updateProfile(ProfileData profile, Player player) {
231232 @ Override
232233 public boolean updatePlayer (Player player , ProfileData profile ) {
233234 Double value = profile .get (HEALTH );
234- if (value == null ) {
235- player .setHealth (PlayerStats .HEALTH );
236- return false ;
237- }
238235 try {
236+ if (value == null ) {
237+ player .setHealth (PlayerStats .HEALTH );
238+ return false ;
239+ }
239240 double maxHealth = getMaxHealth (player );
240241 // This share may handled before MAX_HEALTH.
241242 // Thus this is needed to ensure there is no loss in health stored
242243 if (value > maxHealth ) {
243244 Option .of (maxHealthAttr ).map (player ::getAttribute )
244- .peek (attr -> attr .setBaseValue (maxHealth ));
245+ .peek (attr -> attr .setBaseValue (value ));
245246 }
246247 player .setHealth (value );
247248 } catch (IllegalArgumentException e ) {
248- Logging .fine ("Invalid value '" + value + "': " + e .getMessage ());
249- player .setHealth (PlayerStats . HEALTH );
249+ Logging .warning ("Invalid value '" + value + "': " + e .getMessage ());
250+ player .setHealth (getMaxHealth ( player ) );
250251 return false ;
251252 }
252253 return true ;
@@ -257,7 +258,7 @@ public boolean updatePlayer(Player player, ProfileData profile) {
257258
258259 private static double getMaxHealth (Player player ) {
259260 return Option .of (maxHealthAttr ).map (player ::getAttribute )
260- .map (AttributeInstance ::getValue )
261+ .map (AttributeInstance ::getBaseValue )
261262 .getOrElse (PlayerStats .MAX_HEALTH );
262263 }
263264
0 commit comments