From 86d728f90deb63e0ceac51671b39c1bc8c28843f Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 23 Nov 2013 04:20:03 +1300 Subject: [PATCH] Fix the errors due to health being changed to a float --- .../disguise/PacketsManager.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/me/libraryaddict/disguise/PacketsManager.java b/src/me/libraryaddict/disguise/PacketsManager.java index 1fbce37a..1d5d2d7b 100644 --- a/src/me/libraryaddict/disguise/PacketsManager.java +++ b/src/me/libraryaddict/disguise/PacketsManager.java @@ -410,9 +410,20 @@ public class PacketsManager { if (loc.equals(soundLoc)) { entitySound = DisguiseSound.getType(entity.getType().name()); if (entitySound != null) { - if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) { - soundType = SoundType.DEATH; - } else { + Object obj = null; + if (entity instanceof LivingEntity) { + try { + obj = LivingEntity.class.getMethod("getHealth").invoke(entity); + } catch (Exception e) { + e.printStackTrace(); + } + if (obj instanceof Float && ((Float) obj) == 0 || ((Integer) obj) == 0) { + soundType = SoundType.DEATH; + } else { + obj = null; + } + } + if (obj == null) { boolean hasInvun = false; Object nmsEntity = ReflectionManager.getNmsEntity(entity); try { @@ -529,9 +540,20 @@ public class PacketsManager { if (disSound == null) return; SoundType soundType = null; - if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) { - soundType = SoundType.DEATH; - } else { + Object obj = null; + if (entity instanceof LivingEntity) { + try { + obj = LivingEntity.class.getMethod("getHealth").invoke(entity); + } catch (Exception e) { + e.printStackTrace(); + } + if (obj instanceof Float && ((Float) obj) == 0 || ((Integer) obj) == 0) { + soundType = SoundType.DEATH; + } else { + obj = null; + } + } + if (obj == null) { soundType = SoundType.HURT; } if (disSound.getSound(soundType) == null