Changed version to 2.0.0. Added configurable setting for mobs to not target a protected player.

This commit is contained in:
2021-09-28 22:02:03 +01:00
parent b71a1b5b0b
commit 9b9ffc2840
5 changed files with 31 additions and 2 deletions

View File

@ -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'

View File

@ -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);
}
}

View File

@ -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

View File

@ -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++,

View File

@ -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/