Added config option for mobs ignoring player during the grace period.

This commit is contained in:
2021-09-29 01:56:28 +01:00
parent 916a0c888a
commit 6ed20517e9
2 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package com.micle.loginprotection.events; package com.micle.loginprotection.events;
import com.micle.loginprotection.LoginProtection; import com.micle.loginprotection.LoginProtection;
import com.micle.loginprotection.data.ProtectedPlayer;
import com.micle.loginprotection.setup.Config; import com.micle.loginprotection.setup.Config;
import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -12,8 +13,10 @@ public class OnLivingSetAttackTargetEvent {
public void LivingSetAttackTargetEvent(LivingSetAttackTargetEvent event) { public void LivingSetAttackTargetEvent(LivingSetAttackTargetEvent event) {
if (!(event.getTarget() instanceof Player target)) { return; } if (!(event.getTarget() instanceof Player target)) { return; }
if (LoginProtection.protected_players.getPlayer(target.getUUID()) == null) { return; } ProtectedPlayer player = LoginProtection.protected_players.getPlayer(target.getUUID());
if (!Config.MAIN_IGNORE_PLAYER_ENABLED.get()) { return; } 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); ((Mob) event.getEntityLiving()).setTarget(null);
} }

View File

@ -8,6 +8,7 @@ public class Config {
public static ForgeConfigSpec SERVER_CONFIG; public static ForgeConfigSpec SERVER_CONFIG;
public static ForgeConfigSpec.BooleanValue POST_GRACE_ENABLED; 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.IntValue POST_GRACE_DURATION;
public static ForgeConfigSpec.BooleanValue POST_DROWN_ENABLED; public static ForgeConfigSpec.BooleanValue POST_DROWN_ENABLED;
public static ForgeConfigSpec.BooleanValue POST_WATER_ENABLED; public static ForgeConfigSpec.BooleanValue POST_WATER_ENABLED;
@ -42,6 +43,9 @@ public class Config {
POST_GRACE_DURATION = builder POST_GRACE_DURATION = builder
.comment("Grace period duration in seconds.") .comment("Grace period duration in seconds.")
.defineInRange("graceDuration", 10, 1, Integer.MAX_VALUE/40); .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.pop();
builder.push("water_protection"); builder.push("water_protection");
POST_DROWN_ENABLED = builder POST_DROWN_ENABLED = builder