From b3c3df4c7e92ba26d584ddbaa5b278ef27a76a6b Mon Sep 17 00:00:00 2001 From: fretuks Date: Tue, 10 Feb 2026 17:12:16 +0100 Subject: [PATCH] fix bug with leavin game while knocked --- gradle.properties | 2 +- .../net/fretux/knockedback/KnockedManager.java | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 15520b5..5fd05ad 100644 --- a/gradle.properties +++ b/gradle.properties @@ -50,7 +50,7 @@ mod_name=Knockedback # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ -mod_version=1.5.2 +mod_version=1.5.3 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/net/fretux/knockedback/KnockedManager.java b/src/main/java/net/fretux/knockedback/KnockedManager.java index cbdb49b..adc9349 100644 --- a/src/main/java/net/fretux/knockedback/KnockedManager.java +++ b/src/main/java/net/fretux/knockedback/KnockedManager.java @@ -16,6 +16,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; import net.minecraftforge.registries.ForgeRegistries; import java.util.*; @@ -25,20 +26,15 @@ public class KnockedManager { private static final Map knockedEntities = new HashMap<>(); private static final Set grippedEntities = new HashSet<>(); private static final Set killingNow = new HashSet<>(); - public static void markKillInProgress(LivingEntity e) { killingNow.add(e.getUUID()); } - public static void unmarkKillInProgress(LivingEntity e) { killingNow.remove(e.getUUID()); } - - public static int getKnockedDuration() { return Config.COMMON.knockedDuration.get(); } - public static void applyKnockedState(LivingEntity entity) { if (!(entity instanceof Player)) { return; @@ -224,6 +220,18 @@ public class KnockedManager { ); } + @SubscribeEvent + public static void onPlayerLoggedOut(PlayerLoggedOutEvent event) { + if (!(event.getEntity() instanceof ServerPlayer sp)) { + return; + } + if (!isKnocked(sp)) { + return; + } + killAndRemove(sp); + } + + private static void applyKnockedEffects(Player player) { List configured = Config.COMMON.knockedPotionEffects.get(); Map desiredEffects = new HashMap<>();