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

24 lines
1.1 KiB
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.entity.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
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 PlayerEntity)) { return; }
PlayerEntity target = (PlayerEntity) event.getTarget();
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; }
((MobEntity) event.getEntityLiving()).setTarget(null);
}
}