From 8535ccf2dd3805b845f3ce17181cf5b0bb6b1474 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 19 Jan 2014 08:39:23 +1300 Subject: [PATCH] Fixed the damage and idle sound getter being completely wrong. --- .../libraryaddict/disguise/LibsDisguises.java | 2 +- .../disguise/utilities/DisguiseSound.java | 4 ++-- .../disguise/utilities/PacketsManager.java | 7 +++---- .../disguise/utilities/ReflectionManager.java | 20 +++++++------------ 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 2e84f111..9780c5a4 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -206,7 +206,7 @@ public class LibsDisguises extends JavaPlugin { if (sound != null) { Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity); if (soundStrength != null) { - sound.setDamageSoundVolume((Float) soundStrength); + sound.setDamageAndIdleSoundVolume((Float) soundStrength); } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java b/src/me/libraryaddict/disguise/utilities/DisguiseSound.java index 0a594cc9..bb925c82 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseSound.java @@ -151,7 +151,7 @@ public enum DisguiseSound { } } - public float getDamageSoundVolume() { + public float getDamageAndIdleSoundVolume() { return damageSoundVolume; } @@ -202,7 +202,7 @@ public enum DisguiseSound { } } - public void setDamageSoundVolume(float strength) { + public void setDamageAndIdleSoundVolume(float strength) { this.damageSoundVolume = strength; } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index dd26524e..25c47892 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -584,9 +584,8 @@ public class PacketsManager { if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE) { // If the volume is the default - if (soundType != SoundType.IDLE - && ((Float) mods.read(4)).equals(entitySound.getDamageSoundVolume())) { - mods.write(4, dSound.getDamageSoundVolume()); + if (((Float) mods.read(4)).equals(entitySound.getDamageAndIdleSoundVolume())) { + mods.write(4, dSound.getDamageAndIdleSoundVolume()); } // Here I assume its the default pitch as I can't calculate if its real. if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity @@ -678,7 +677,7 @@ public class PacketsManager { mods.write(1, (int) (loc.getX() * 8D)); mods.write(2, (int) (loc.getY() * 8D)); mods.write(3, (int) (loc.getZ() * 8D)); - mods.write(4, disSound.getDamageSoundVolume()); + mods.write(4, disSound.getDamageAndIdleSoundVolume()); float pitch; if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index ef7568ec..a85c0768 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -52,24 +52,18 @@ public class ReflectionManager { private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; private static Class itemClass; - private static Method soundMethod; + private static Method damageAndIdleSoundMethod; static { for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) { try { if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers()) && method.getParameterTypes().length == 0) { - Object entity = createEntityInstance("Pig"); + Object entity = createEntityInstance("Cow"); method.setAccessible(true); - method.invoke(entity); - Field random = getNmsClass("Entity").getDeclaredField("random"); - random.setAccessible(true); - random.set(entity, null); - method.setAccessible(true); - try { - method.invoke(entity); - } catch (Exception ex) { - soundMethod = method; + float value = (Float) method.invoke(entity); + if (value == 0.4F) { + damageAndIdleSoundMethod = method; break; } } @@ -261,8 +255,8 @@ public class ReflectionManager { public static Float getSoundModifier(Object entity) { try { - soundMethod.setAccessible(true); - return (Float) soundMethod.invoke(entity); + damageAndIdleSoundMethod.setAccessible(true); + return (Float) damageAndIdleSoundMethod.invoke(entity); } catch (Exception ex) { } return null;