diff --git a/build.gradle b/build.gradle index 7149a66..f93fbe1 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.17.1-1.1.0' +version = '1.17.1-2.0.0' group = 'com.micle.loginprotection' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'LoginProtection-Forge' diff --git a/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java b/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java new file mode 100644 index 0000000..27be596 --- /dev/null +++ b/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEvent.java @@ -0,0 +1,20 @@ +package com.micle.loginprotection.events; + +import com.micle.loginprotection.LoginProtection; +import com.micle.loginprotection.setup.Config; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class OnLivingSetAttackTargetEvent { + @SubscribeEvent + public void LivingSetAttackTargetEvent(LivingSetAttackTargetEvent event) { + if (!(event.getTarget() instanceof Player target)) { return; } + + if (LoginProtection.protected_players.getPlayer(target.getUUID()) == null) { return; } + if (!Config.MAIN_PLAYER_TARGET_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 365f6a5..de7f5e5 100644 --- a/src/main/java/com/micle/loginprotection/setup/Config.java +++ b/src/main/java/com/micle/loginprotection/setup/Config.java @@ -17,6 +17,8 @@ public class Config { public static ForgeConfigSpec.BooleanValue POST_FIRE_ENABLED; public static ForgeConfigSpec.IntValue POST_FIRE_DURATION; + public static ForgeConfigSpec.BooleanValue MAIN_PLAYER_TARGET_ENABLED; + public static void init() { initServer(); @@ -26,6 +28,12 @@ public class Config { private static void initServer() { ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + builder.comment("Main protection settings for protecting inactive (loading) players.").push("main"); + MAIN_PLAYER_TARGET_ENABLED = builder + .comment("Whether mobs will still target/attack a protected player.") + .define("playerTargetEnabled", true); + builder.pop(); + builder.comment("Additional protection settings that apply as soon as a player becomes active.").push("post"); builder.push("grace_period"); POST_GRACE_ENABLED = builder diff --git a/src/main/java/com/micle/loginprotection/setup/Registration.java b/src/main/java/com/micle/loginprotection/setup/Registration.java index c0ad513..593fc82 100755 --- a/src/main/java/com/micle/loginprotection/setup/Registration.java +++ b/src/main/java/com/micle/loginprotection/setup/Registration.java @@ -16,6 +16,7 @@ public class Registration { MinecraftForge.EVENT_BUS.register(new OnPlayerTickEventHandler()); MinecraftForge.EVENT_BUS.register(new OnKeyPressEventHandler()); MinecraftForge.EVENT_BUS.register(new OnPlayerLeaveEventHandler()); + MinecraftForge.EVENT_BUS.register(new OnLivingSetAttackTargetEvent()); int id = 0; LoginProtection.INSTANCE.registerMessage(id++, diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 3308214..f3f8a18 100755 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="loginprotection" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.1.0" #mandatory +version="2.0.0" #mandatory # A display name for the mod displayName="Micle's Login Protection" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/