Browse Source

fix bug where armor stand could be renamed to heart symbols

nossr50 1 week ago
parent
commit
00c0b2e5ec

+ 1 - 0
Changelog.txt

@@ -9,6 +9,7 @@ Version 2.2.043
     Added Copper_Golem to experience.yml for Combat XP
     Fixed ExploitFix.PreventArmorStandInteraction in experience.yml not being respected
     Added ExploitFix.PreventMannequinInteraction to experience.yml to prevent mannequins from granting XP or other effects
+    Fixed bug where Armor Stands would get renamed to heart symbols upon breaking them
 
     NOTES:
     You don't need to update your experience.yml, that one updates automatically when you run mcMMO after an update.

+ 2 - 2
src/main/java/com/gmail/nossr50/listeners/EntityListener.java

@@ -1203,11 +1203,11 @@ public class EntityListener implements Listener {
         }
     }
 
-    private static boolean isMannequinEntity(Entity attacker) {
+    public static boolean isMannequinEntity(Entity attacker) {
         return MANNEQUIN.contains(attacker.getType().toString());
     }
 
-    private static boolean isArmorStandEntity(Entity attacker) {
+    public static boolean isArmorStandEntity(Entity attacker) {
         return ARMOR_STAND.contains(attacker.getType().toString());
     }
 }

+ 11 - 4
src/main/java/com/gmail/nossr50/util/MobHealthbarUtils.java

@@ -1,5 +1,8 @@
 package com.gmail.nossr50.util;
 
+import static com.gmail.nossr50.listeners.EntityListener.isArmorStandEntity;
+import static com.gmail.nossr50.listeners.EntityListener.isMannequinEntity;
+
 import com.gmail.nossr50.datatypes.MobHealthbarType;
 import com.gmail.nossr50.datatypes.meta.OldName;
 import com.gmail.nossr50.mcMMO;
@@ -40,8 +43,12 @@ public final class MobHealthbarUtils {
      * @param damage damage done by the attack triggering this
      */
     public static void handleMobHealthbars(LivingEntity target, double damage, mcMMO plugin) {
-        if (mcMMO.isHealthBarPluginEnabled() || !mcMMO.p.getGeneralConfig()
-                .getMobHealthbarEnabled()) {
+        if (isArmorStandEntity(target) || isMannequinEntity(target)) {
+            return;
+        }
+
+        if (mcMMO.isHealthBarPluginEnabled()
+                || !mcMMO.p.getGeneralConfig().getMobHealthbarEnabled()) {
             return;
         }
 
@@ -54,13 +61,13 @@ public final class MobHealthbarUtils {
             return;
         }
 
-        String originalName = target.getName();
+        final String originalName = target.getName();
         String oldName = target.getCustomName();
 
         /*
          * Store the name in metadata
          */
-        if (target.getMetadata(MetadataConstants.METADATA_KEY_OLD_NAME_KEY).size() <= 0) {
+        if (target.getMetadata(MetadataConstants.METADATA_KEY_OLD_NAME_KEY).isEmpty()) {
             target.setMetadata(MetadataConstants.METADATA_KEY_OLD_NAME_KEY,
                     new OldName(originalName, plugin));
         }