jayhillx

onRespawn

Sep 18th, 2021
774
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @SubscribeEvent
  2.     public void onRespawn(PlayerRespawnEvent event) {
  3.         PlayerEntity player = event.getPlayer();
  4.  
  5.         player.getCapability(HealthCapability.HEALTH_CAPABILITY).ifPresent(health -> {
  6.             if (player.getMaxHealth() >= 2.0F && player.getMaxHealth() <= 20.0F) {
  7.                 player.setHealth(health.getMaxHealth());
  8.                 player.getAttribute(Attributes.MAX_HEALTH).setBaseValue(health.getMaxHealth());
  9.  
  10.             } if (player.getMaxHealth() >= 22.0F) {
  11.                 player.setGameMode(GameType.SPECTATOR);
  12.             }
  13.         });
  14.     }
RAW Paste Data