mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Double check that a Player is not an NPC when loading profiles
This commit is contained in:
@ -103,7 +103,7 @@ public class EventUtils {
|
||||
Entity entity = entityDamageEvent.getEntity();
|
||||
|
||||
//Check to make sure the entity is not an NPC
|
||||
if(Misc.isNPCEntity(entity))
|
||||
if(Misc.isNPCEntityExcludingVillagers(entity))
|
||||
return false;
|
||||
|
||||
if (!entity.isValid() || !(entity instanceof LivingEntity)) {
|
||||
|
@ -39,13 +39,20 @@ public final class Misc {
|
||||
|
||||
private Misc() {};
|
||||
|
||||
public static boolean isNPCEntity(Entity entity) {
|
||||
public static boolean isNPCEntityExcludingVillagers(Entity entity) {
|
||||
return (entity == null
|
||||
|| (entity.hasMetadata("NPC") && !(entity instanceof Villager))
|
||||
|| (entity instanceof NPC && !(entity instanceof Villager))
|
||||
|| entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
|
||||
}
|
||||
|
||||
public static boolean isNPCIncludingVillagers(Player entity) {
|
||||
return (entity == null
|
||||
|| (entity.hasMetadata("NPC"))
|
||||
|| (entity instanceof NPC)
|
||||
|| entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if two locations are near each other.
|
||||
*
|
||||
|
@ -247,7 +247,7 @@ public final class CombatUtils {
|
||||
EntityType entityType = damager.getType();
|
||||
|
||||
if (target instanceof Player) {
|
||||
if (Misc.isNPCEntity(target)) {
|
||||
if (Misc.isNPCEntityExcludingVillagers(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ public final class CombatUtils {
|
||||
if (tamer != null && tamer instanceof Player && PrimarySkillType.TAMING.shouldProcess(target)) {
|
||||
Player master = (Player) tamer;
|
||||
|
||||
if (!Misc.isNPCEntity(master) && PrimarySkillType.TAMING.getPermissions(master)) {
|
||||
if (!Misc.isNPCEntityExcludingVillagers(master) && PrimarySkillType.TAMING.getPermissions(master)) {
|
||||
processTamingCombat(target, master, wolf, event);
|
||||
}
|
||||
}
|
||||
@ -348,11 +348,11 @@ public final class CombatUtils {
|
||||
if (projectileSource != null && projectileSource instanceof Player && PrimarySkillType.ARCHERY.shouldProcess(target)) {
|
||||
Player player = (Player) projectileSource;
|
||||
|
||||
if (!Misc.isNPCEntity(player) && PrimarySkillType.ARCHERY.getPermissions(player)) {
|
||||
if (!Misc.isNPCEntityExcludingVillagers(player) && PrimarySkillType.ARCHERY.getPermissions(player)) {
|
||||
processArcheryCombat(target, player, event, arrow);
|
||||
}
|
||||
|
||||
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntity(player) && PrimarySkillType.TAMING.getPermissions(player)) {
|
||||
if (target.getType() != EntityType.CREEPER && !Misc.isNPCEntityExcludingVillagers(player) && PrimarySkillType.TAMING.getPermissions(player)) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
||||
tamingManager.attackTarget(target);
|
||||
@ -522,7 +522,7 @@ public final class CombatUtils {
|
||||
break;
|
||||
}
|
||||
|
||||
if (Misc.isNPCEntity(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
||||
if (Misc.isNPCEntityExcludingVillagers(entity) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -859,7 +859,7 @@ public final class CombatUtils {
|
||||
|
||||
Player player = (Player) attacker;
|
||||
|
||||
if (Misc.isNPCEntity(player) || Misc.isNPCEntity(target)) {
|
||||
if (Misc.isNPCEntityExcludingVillagers(player) || Misc.isNPCEntityExcludingVillagers(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user