Changed version to 2.0.0. Added configurable setting for mobs to not target a protected player.
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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++,
|
||||
|
||||
Reference in New Issue
Block a user