Browse Source

Fixed a bug preventing wandering traders from granting XP

nossr50 6 years ago
parent
commit
304a942f51
3 changed files with 34 additions and 8 deletions
  1. 3 0
      Changelog.txt
  2. 1 1
      pom.xml
  3. 30 7
      src/main/java/com/gmail/nossr50/util/Misc.java

+ 3 - 0
Changelog.txt

@@ -1,3 +1,6 @@
+Version 2.1.95
+    Fixed a bug preventing Wandering Traders from granting XP
+
 Version 2.1.94
 Version 2.1.94
     2 new devs have joined the mcMMO team (electronicboy, kashike), bringing the active dev team to 3 including myself! Strings relating to authors of mcMMO have been updated to reflect this
     2 new devs have joined the mcMMO team (electronicboy, kashike), bringing the active dev team to 3 including myself! Strings relating to authors of mcMMO have been updated to reflect this
     Fixed a bug where 2 people using Tree Feller could result in the tree being rejected for being too big
     Fixed a bug where 2 people using Tree Feller could result in the tree being rejected for being too big

+ 1 - 1
pom.xml

@@ -2,7 +2,7 @@
     <modelVersion>4.0.0</modelVersion>
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.gmail.nossr50.mcMMO</groupId>
     <groupId>com.gmail.nossr50.mcMMO</groupId>
     <artifactId>mcMMO</artifactId>
     <artifactId>mcMMO</artifactId>
-    <version>2.1.94</version>
+    <version>2.1.95-SNAPSHOT</version>
     <name>mcMMO</name>
     <name>mcMMO</name>
     <url>https://github.com/mcMMO-Dev/mcMMO</url>
     <url>https://github.com/mcMMO-Dev/mcMMO</url>
     <scm>
     <scm>

+ 30 - 7
src/main/java/com/gmail/nossr50/util/Misc.java

@@ -40,17 +40,40 @@ public final class Misc {
 
 
     private 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) {
     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 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(Player entity) {
+    public static boolean isNPCIncludingVillagers(Entity entity) {
         return (entity == null
         return (entity == null
-                || (entity.hasMetadata("NPC"))
-                || (entity instanceof NPC)
+                || (hasNPCMetadataTag(entity))
+                || (isNPCClassType(entity))
                 || entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
                 || entity.getClass().getName().equalsIgnoreCase("cofh.entity.PlayerFake"));
     }
     }