Fixed the damage and idle sound getter being completely wrong.

This commit is contained in:
libraryaddict 2014-01-19 08:39:23 +13:00
parent f24eaa4854
commit 8535ccf2dd
4 changed files with 13 additions and 20 deletions

@ -206,7 +206,7 @@ public class LibsDisguises extends JavaPlugin {
if (sound != null) { if (sound != null) {
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity); Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null) { if (soundStrength != null) {
sound.setDamageSoundVolume((Float) soundStrength); sound.setDamageAndIdleSoundVolume((Float) soundStrength);
} }
} }

@ -151,7 +151,7 @@ public enum DisguiseSound {
} }
} }
public float getDamageSoundVolume() { public float getDamageAndIdleSoundVolume() {
return damageSoundVolume; return damageSoundVolume;
} }
@ -202,7 +202,7 @@ public enum DisguiseSound {
} }
} }
public void setDamageSoundVolume(float strength) { public void setDamageAndIdleSoundVolume(float strength) {
this.damageSoundVolume = strength; this.damageSoundVolume = strength;
} }

@ -584,9 +584,8 @@ public class PacketsManager {
if (soundType == SoundType.HURT || soundType == SoundType.DEATH if (soundType == SoundType.HURT || soundType == SoundType.DEATH
|| soundType == SoundType.IDLE) { || soundType == SoundType.IDLE) {
// If the volume is the default // If the volume is the default
if (soundType != SoundType.IDLE if (((Float) mods.read(4)).equals(entitySound.getDamageAndIdleSoundVolume())) {
&& ((Float) mods.read(4)).equals(entitySound.getDamageSoundVolume())) { mods.write(4, dSound.getDamageAndIdleSoundVolume());
mods.write(4, dSound.getDamageSoundVolume());
} }
// Here I assume its the default pitch as I can't calculate if its real. // Here I assume its the default pitch as I can't calculate if its real.
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity
@ -678,7 +677,7 @@ public class PacketsManager {
mods.write(1, (int) (loc.getX() * 8D)); mods.write(1, (int) (loc.getX() * 8D));
mods.write(2, (int) (loc.getY() * 8D)); mods.write(2, (int) (loc.getY() * 8D));
mods.write(3, (int) (loc.getZ() * 8D)); mods.write(3, (int) (loc.getZ() * 8D));
mods.write(4, disSound.getDamageSoundVolume()); mods.write(4, disSound.getDamageAndIdleSoundVolume());
float pitch; float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;

@ -52,24 +52,18 @@ public class ReflectionManager {
private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
private static Class itemClass; private static Class itemClass;
private static Method soundMethod; private static Method damageAndIdleSoundMethod;
static { static {
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) { for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
try { try {
if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers()) if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers())
&& method.getParameterTypes().length == 0) { && method.getParameterTypes().length == 0) {
Object entity = createEntityInstance("Pig"); Object entity = createEntityInstance("Cow");
method.setAccessible(true); method.setAccessible(true);
method.invoke(entity); float value = (Float) method.invoke(entity);
Field random = getNmsClass("Entity").getDeclaredField("random"); if (value == 0.4F) {
random.setAccessible(true); damageAndIdleSoundMethod = method;
random.set(entity, null);
method.setAccessible(true);
try {
method.invoke(entity);
} catch (Exception ex) {
soundMethod = method;
break; break;
} }
} }
@ -261,8 +255,8 @@ public class ReflectionManager {
public static Float getSoundModifier(Object entity) { public static Float getSoundModifier(Object entity) {
try { try {
soundMethod.setAccessible(true); damageAndIdleSoundMethod.setAccessible(true);
return (Float) soundMethod.invoke(entity); return (Float) damageAndIdleSoundMethod.invoke(entity);
} catch (Exception ex) { } catch (Exception ex) {
} }
return null; return null;