33import com .dumptruckman .minecraft .util .Logging ;
44import org .bukkit .NamespacedKey ;
55import org .bukkit .Registry ;
6+ import org .bukkit .attribute .AttributeInstance ;
67import org .mvplugins .multiverse .core .teleportation .AsyncSafetyTeleporter ;
8+ import org .mvplugins .multiverse .external .vavr .control .Option ;
79import org .mvplugins .multiverse .inventories .MultiverseInventories ;
810import org .mvplugins .multiverse .inventories .handleshare .SpawnChangeListener ;
911import org .mvplugins .multiverse .inventories .profile .group .WorldGroup ;
@@ -65,7 +67,10 @@ public static void init(MultiverseInventories inventories) {
6567 if (Sharables .safetyTeleporter == null ) {
6668 Sharables .safetyTeleporter = inventories .getServiceLocator ().getService (AsyncSafetyTeleporter .class );
6769 }
68- Sharables .maxHealthAttr = Registry .ATTRIBUTE .get (NamespacedKey .minecraft ("max-health" ));
70+ Sharables .maxHealthAttr = Registry .ATTRIBUTE .get (NamespacedKey .minecraft ("max_health" ));
71+ if (Sharables .maxHealthAttr == null ) {
72+ Logging .warning ("Could not find max_health attribute. Health related sharables may not work as expected." );
73+ }
6974 }
7075
7176 /**
@@ -178,8 +183,10 @@ public boolean updatePlayer(Player player, PlayerProfile profile) {
178183 public void updateProfile (PlayerProfile profile , Player player ) {
179184 double health = player .getHealth ();
180185 // Player is dead, so health should be regained to full.
181- if (health <= 0 && maxHealthAttr != null ) {
182- health = player .getAttribute (maxHealthAttr ).getValue ();
186+ if (health <= 0 ) {
187+ health = Option .of (maxHealthAttr ).map (player ::getAttribute )
188+ .map (AttributeInstance ::getValue )
189+ .getOrElse (PlayerStats .HEALTH );
183190 }
184191 profile .set (HEALTH , health );
185192 }
@@ -195,9 +202,10 @@ public boolean updatePlayer(Player player, PlayerProfile profile) {
195202 player .setHealth (value );
196203 } catch (IllegalArgumentException e ) {
197204 Logging .fine ("Invalid value '" + value + "': " + e .getMessage ());
198- if (maxHealthAttr != null ) {
199- player .setHealth (player .getAttribute (maxHealthAttr ).getValue ());
200- }
205+ Option .of (maxHealthAttr ).map (player ::getAttribute )
206+ .map (AttributeInstance ::getValue )
207+ .peek (player ::setHealth )
208+ .onEmpty (() -> player .setHealth (PlayerStats .HEALTH ));
201209 return false ;
202210 }
203211 return true ;
0 commit comments