mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Double check that a Player is not an NPC when loading profiles
This commit is contained in:
parent
73ce7e729c
commit
218b2a1a75
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user