From 6ed20517e92ed237d922b2d129eace57afa3d3a3 Mon Sep 17 00:00:00 2001 From: micle Date: Wed, 29 Sep 2021 01:56:28 +0100 Subject: [PATCH] Added config option for mobs ignoring player during the grace period. --- .../events/OnLivingSetAttackTargetEvent.java | 7 +++++-- src/main/java/com/micle/loginprotection/setup/Config.java | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java b/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java index 6e7f929..98948e2 100644 --- a/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java +++ b/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java @@ -1,6 +1,7 @@ package com.micle.loginprotection.events; import com.micle.loginprotection.LoginProtection; +import com.micle.loginprotection.data.ProtectedPlayer; import com.micle.loginprotection.setup.Config; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.player.Player; @@ -12,8 +13,10 @@ public class OnLivingSetAttackTargetEvent { public void LivingSetAttackTargetEvent(LivingSetAttackTargetEvent event) { if (!(event.getTarget() instanceof Player target)) { return; } - if (LoginProtection.protected_players.getPlayer(target.getUUID()) == null) { return; } - if (!Config.MAIN_IGNORE_PLAYER_ENABLED.get()) { return; } + ProtectedPlayer player = LoginProtection.protected_players.getPlayer(target.getUUID()); + if (player == null) { return; } + if (player.isLoading() && !Config.MAIN_IGNORE_PLAYER_ENABLED.get()) { return; } + if (!player.isLoading() && !Config.POST_GRACE_IGNORE_PLAYER_ENABLED.get()) { return; } ((Mob) event.getEntityLiving()).setTarget(null); } diff --git a/src/main/java/com/micle/loginprotection/setup/Config.java b/src/main/java/com/micle/loginprotection/setup/Config.java index a842936..f58a090 100644 --- a/src/main/java/com/micle/loginprotection/setup/Config.java +++ b/src/main/java/com/micle/loginprotection/setup/Config.java @@ -8,6 +8,7 @@ public class Config { public static ForgeConfigSpec SERVER_CONFIG; public static ForgeConfigSpec.BooleanValue POST_GRACE_ENABLED; + public static ForgeConfigSpec.BooleanValue POST_GRACE_IGNORE_PLAYER_ENABLED; public static ForgeConfigSpec.IntValue POST_GRACE_DURATION; public static ForgeConfigSpec.BooleanValue POST_DROWN_ENABLED; public static ForgeConfigSpec.BooleanValue POST_WATER_ENABLED; @@ -42,6 +43,9 @@ public class Config { POST_GRACE_DURATION = builder .comment("Grace period duration in seconds.") .defineInRange("graceDuration", 10, 1, Integer.MAX_VALUE/40); + POST_GRACE_IGNORE_PLAYER_ENABLED = builder + .comment("Whether mobs will ignore a player during their grace period.") + .define("graceIgnorePlayerEnabled", true); builder.pop(); builder.push("water_protection"); POST_DROWN_ENABLED = builder