Advertisement
jayhillx

onPlayerDeath 04

Aug 16th, 2021
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. @SubscribeEvent
  2. public void onPlayerDeath(LivingDeathEvent event) {
  3. Entity entity = event.getEntity();
  4.  
  5. if (entity instanceof PlayerEntity) {
  6. PlayerEntity player = (PlayerEntity) entity;
  7.  
  8. player.getCapability(HealthCapabilities.HEALTH_CAPABILITY).ifPresent(instance -> {
  9. if (player.getMaxHealth() >= 2 && player.getMaxHealth() <= 20) {
  10. instance.setHealth((int) (player.getMaxHealth() + 2));
  11. }
  12. });
  13.  
  14. /** Sends remaining lives in server chat. */
  15. delayedTasks.add(() -> {
  16. for (PlayerEntity players : player.getServer().getPlayerList().getPlayers()) {
  17. int lives = (int) (10 - (player.getMaxHealth() / 2));
  18.  
  19. if (lives >= 2) {
  20. players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has " + lives + "
  21. lives remaining . . ."), player.getUniqueID());
  22. } else if (lives == 1) {
  23. players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has one life
  24. remaining!"), player.getUniqueID());
  25. } else {
  26. players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has been
  27. eliminated!"), player.getUniqueID());
  28. }
  29. }
  30. });
  31.  
  32. /** Summons lightning if a player dies on last life. */
  33. if (player.getMaxHealth() == 20) {
  34. LightningBoltEntity lightning = EntityType.LIGHTNING_BOLT.create(player.world);
  35. lightning.moveForced(Vector3d.copyCenteredHorizontally(player.getPosition()));
  36. lightning.setEffectOnly(true);
  37. lightning.setCaster(player instanceof ServerPlayerEntity ? (ServerPlayerEntity)player : null);
  38. player.world.addEntity(lightning);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement