diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index c7f26431c..f771cc1f2 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -327,7 +327,7 @@ public class EntityListener implements Listener { } */ - if (Misc.isNPCEntity(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) { + if (Misc.isNPCEntityExcludingVillagers(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) { return; } @@ -337,7 +337,7 @@ public class EntityListener implements Listener { return; } - if (Misc.isNPCEntity(attacker)) { + if (Misc.isNPCEntityExcludingVillagers(attacker)) { return; } @@ -466,7 +466,7 @@ public class EntityListener implements Listener { } */ - if (Misc.isNPCEntity(entity) || !entity.isValid() || !(entity instanceof LivingEntity)) { + if (Misc.isNPCEntityExcludingVillagers(entity) || !entity.isValid() || !(entity instanceof LivingEntity)) { return; } @@ -603,7 +603,7 @@ public class EntityListener implements Listener { LivingEntity entity = event.getEntity(); - if (Misc.isNPCEntity(entity)) { + if (Misc.isNPCEntityExcludingVillagers(entity)) { return; } @@ -636,7 +636,7 @@ public class EntityListener implements Listener { LivingEntity entity = event.getEntity(); - if (Misc.isNPCEntity(entity)) { + if (Misc.isNPCEntityExcludingVillagers(entity)) { return; } @@ -937,7 +937,7 @@ public class EntityListener implements Listener { LivingEntity entity = event.getEntity(); - if (!UserManager.hasPlayerDataKey(player) || Misc.isNPCEntity(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) { + if (!UserManager.hasPlayerDataKey(player) || Misc.isNPCEntityExcludingVillagers(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) { return; } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 8f1f91f0d..ea13ab98d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -522,10 +522,6 @@ public class PlayerListener implements Listener { public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (Misc.isNPCEntity(player)) { - return; - } - //Delay loading for 3 seconds in case the player has a save task running, its hacky but it should do the trick new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 60); @@ -852,7 +848,7 @@ public class PlayerListener implements Listener { public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); - if (Misc.isNPCEntity(player) || !UserManager.hasPlayerDataKey(player)) { + if (Misc.isNPCEntityExcludingVillagers(player) || !UserManager.hasPlayerDataKey(player)) { return; } diff --git a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java index 4736ce5cd..5ec5f1dd2 100644 --- a/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/player/PlayerProfileLoadingTask.java @@ -30,6 +30,11 @@ public class PlayerProfileLoadingTask extends BukkitRunnable { // DO NOT MODIFY THE McMMOPLAYER FROM THIS CODE @Override public void run() { + + if (Misc.isNPCIncludingVillagers(player)) { + return; + } + // Quit if they logged out if (!player.isOnline()) { mcMMO.p.getLogger().info("Aborting profile loading recovery for " + player.getName() + " - player logged out"); diff --git a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java index 076cef3e2..8bd1d8c7e 100644 --- a/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/skills/AlchemyBrewTask.java @@ -38,7 +38,7 @@ public class AlchemyBrewTask extends BukkitRunnable { brewTimer = DEFAULT_BREW_TICKS; if (player != null - && !Misc.isNPCEntity(player) + && !Misc.isNPCEntityExcludingVillagers(player) && Permissions.isSubSkillEnabled(player, SubSkillType.ALCHEMY_CATALYSIS) && UserManager.getPlayer(player) != null) { diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 1ce5733f9..44a7b1047 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -171,7 +171,7 @@ public class UnarmedManager extends SkillManager { * @return true if the defender was not disarmed, false otherwise */ private boolean hasIronGrip(Player defender) { - if (!Misc.isNPCEntity(defender) && Permissions.isSubSkillEnabled(defender, SubSkillType.UNARMED_IRON_GRIP) + if (!Misc.isNPCEntityExcludingVillagers(defender) && Permissions.isSubSkillEnabled(defender, SubSkillType.UNARMED_IRON_GRIP) && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_IRON_GRIP, getPlayer())) { NotificationManager.sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Unarmed.Ability.IronGrip.Defender"); NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Unarmed.Ability.IronGrip.Attacker"); diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index 3f8b5a5a3..b88958206 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -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)) { diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index e2e680e2e..c3a69c65e 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -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. * diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 6a8d1e755..26cd72431 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -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; }