Fixed a bug preventing wandering traders from granting XP

This commit is contained in:
nossr50
2019-07-05 05:51:41 -07:00
parent 02c1ce749c
commit 304a942f51
3 changed files with 34 additions and 8 deletions

View File

@ -40,17 +40,40 @@ public final class Misc {
private Misc() {};
/**
* Determines if an entity is an NPC but not a villager
* This method aims to establish compatibility between mcMMO and other plugins which create "NPCs"
*
* It does this by checking the following
* 1) The entity is not a Villager
* 2) The entity can be considered an NPC
*
* In this context, an NPC is a bit hard to define. Various plugins determine what an NPC is in different ways.
* @see Misc::isNPCIncludingVillagers
* @param entity target entity
* @return true if the entity is not a Villager and is not a "NPC"
*/
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"));
return (!isVillager(entity)
&& isNPCIncludingVillagers(entity)); //Compatibility with some mod..
}
public static boolean isNPCIncludingVillagers(Player entity) {
public static boolean isNPCClassType(Entity entity) {
return entity instanceof NPC;
}
public static boolean hasNPCMetadataTag(Entity entity) {
return entity.hasMetadata("NPC");
}
public static boolean isVillager(Entity entity) {
return (entity instanceof AbstractVillager);
}
public static boolean isNPCIncludingVillagers(Entity entity) {
return (entity == null
|| (entity.hasMetadata("NPC"))
|| (entity instanceof NPC)
|| (hasNPCMetadataTag(entity))
|| (isNPCClassType(entity))
|| entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
}