Files
login_protection/src/main/java/com/micle/loginprotection/events/OnLivingSetAttackTargetEventHandler.java

24 lines
1020 B
Java

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;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class OnLivingSetAttackTargetEventHandler {
@SubscribeEvent
public void LivingSetAttackTargetEvent(LivingSetAttackTargetEvent event) {
if (!(event.getTarget() instanceof Player target)) { 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);
}
}