From 81879b6ec4cba616ac88009efaa4d08f1e3e650a Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Fri, 19 Jan 2024 21:00:50 +0500 Subject: [PATCH] kill immediately if no players and reset data when knocked dies --- .../common/events/KnockdownsEvents.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/ru/octol1ttle/knockdowns/common/events/KnockdownsEvents.java b/common/src/main/java/ru/octol1ttle/knockdowns/common/events/KnockdownsEvents.java index d09e8ec..30ee56c 100644 --- a/common/src/main/java/ru/octol1ttle/knockdowns/common/events/KnockdownsEvents.java +++ b/common/src/main/java/ru/octol1ttle/knockdowns/common/events/KnockdownsEvents.java @@ -31,11 +31,23 @@ public class KnockdownsEvents { private static void registerOnLivingDeath() { EntityEvent.LIVING_DEATH.register((entity, source) -> { - if (entity.getWorld().isClient() || !(entity instanceof IKnockableDown knockable) || knockable.is_KnockedDown()) { + if (entity.getWorld().isClient() || !(entity instanceof IKnockableDown knockable)) { return EventResult.pass(); } ServerPlayerEntity serverPlayer = (ServerPlayerEntity) entity; + MinecraftServer server = serverPlayer.getServer(); + if (server == null || server.getCurrentPlayerCount() == 1) { + return EventResult.pass(); + } + + if (knockable.is_KnockedDown()) { + knockable.set_KnockedDown(false); + knockable.set_ReviverCount(0); + knockable.set_ReviveTimer(KnockdownsCommon.REVIVE_WAIT_TIME); + + return EventResult.pass(); + } entity.clearStatusEffects(); entity.setInvulnerable(true); @@ -53,10 +65,8 @@ public class KnockdownsEvents { TranslatableTextContent content = (TranslatableTextContent) entity.getDamageTracker().getDeathMessage().getContent(); Text replaced = Text.translatableWithFallback(content.getKey().replace("death.", "knockdown."), content.getKey(), content.getArgs()); - MinecraftServer server = serverPlayer.getServer(); - if (server != null) { - server.getPlayerManager().broadcast(replaced, false); - } + + server.getPlayerManager().broadcast(replaced, false); return EventResult.interruptFalse(); });