Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SubscribeEvent
- public void onPlayerDeath(LivingDeathEvent event) {
- Entity entity = event.getEntity();
- if (entity instanceof PlayerEntity) {
- PlayerEntity player = (PlayerEntity) entity;
- player.getCapability(HealthCapabilities.HEALTH_CAPABILITY).ifPresent(instance -> {
- if (player.getMaxHealth() >= 2 && player.getMaxHealth() <= 20) {
- instance.setHealth((int) (player.getMaxHealth() + 2));
- }
- });
- /** Sends remaining lives in server chat. */
- delayedTasks.add(() -> {
- for (PlayerEntity players : player.getServer().getPlayerList().getPlayers()) {
- int lives = (int) (10 - (player.getMaxHealth() / 2));
- if (lives >= 2) {
- players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has " + lives + "
- lives remaining . . ."), player.getUniqueID());
- } else if (lives == 1) {
- players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has one life
- remaining!"), player.getUniqueID());
- } else {
- players.sendMessage(HealthMessages.getRemainingLives(player, player.getScoreboardName() + " has been
- eliminated!"), player.getUniqueID());
- }
- }
- });
- /** Summons lightning if a player dies on last life. */
- if (player.getMaxHealth() == 20) {
- LightningBoltEntity lightning = EntityType.LIGHTNING_BOLT.create(player.world);
- lightning.moveForced(Vector3d.copyCenteredHorizontally(player.getPosition()));
- lightning.setEffectOnly(true);
- lightning.setCaster(player instanceof ServerPlayerEntity ? (ServerPlayerEntity)player : null);
- player.world.addEntity(lightning);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement