Fix sounds, release 9.0.6

This commit is contained in:
libraryaddict 2016-05-16 03:51:16 +12:00
parent b17191a462
commit 06c0084e3a
2 changed files with 181 additions and 173 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>LibsDisguises</groupId> <groupId>LibsDisguises</groupId>
<artifactId>LibsDisguises</artifactId> <artifactId>LibsDisguises</artifactId>
<version>9.0.5-SNAPSHOT</version> <version>9.0.6</version>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>

View File

@ -16,7 +16,6 @@ import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -47,6 +46,7 @@ public class PacketListenerSounds extends PacketAdapter
{ {
return; return;
} }
if (event.isAsync()) if (event.isAsync())
{ {
return; return;
@ -63,19 +63,28 @@ public class PacketListenerSounds extends PacketAdapter
if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) if (event.getPacketType() == Server.NAMED_SOUND_EFFECT)
{ {
Object soundEffect = mods.read(0);
SoundType soundType = null; SoundType soundType = null;
Location soundLoc = new Location(observer.getWorld(), ((Integer) mods.read(2)) / 8D, ((Integer) mods.read(3)) / 8D, int[] soundCords = new int[]
((Integer) mods.read(4)) / 8D); {
(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)
};
int chunkX = (int) Math.floor((soundCords[0] / 8D) / 16D);
int chunkZ = (int) Math.floor((soundCords[2] / 8D) / 16D);
if (!observer.getWorld().isChunkLoaded(chunkX, chunkZ))
{
return;
}
Entity disguisedEntity = null; Entity disguisedEntity = null;
DisguiseSound entitySound = null; DisguiseSound entitySound = null;
Disguise disguise = null; Disguise disguise = null;
Entity[] entities = soundLoc.getChunk().getEntities(); String soundEffect = ReflectionManager.convertSoundEffectToString(mods.read(0));
Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities();
for (Entity entity : entities) for (Entity entity : entities)
{ {
@ -85,15 +94,23 @@ public class PacketListenerSounds extends PacketAdapter
{ {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D, int[] entCords = new int[]
((int) (loc.getZ() * 8)) / 8D);
if (loc.equals(soundLoc))
{ {
(int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8)
};
if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2])
{
continue;
}
entitySound = DisguiseSound.getType(entity.getType().name()); entitySound = DisguiseSound.getType(entity.getType().name());
if (entitySound != null) if (entitySound == null)
{ {
continue;
}
Object obj = null; Object obj = null;
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity)
@ -129,8 +146,8 @@ public class PacketListenerSounds extends PacketAdapter
if (entity instanceof LivingEntity) if (entity instanceof LivingEntity)
{ {
hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks") hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks")
.getInt(nmsEntity) == ReflectionManager .getInt(nmsEntity) == ReflectionManager.getNmsField("EntityLiving", "maxNoDamageTicks")
.getNmsField("EntityLiving", "maxNoDamageTicks").getInt(nmsEntity); .getInt(nmsEntity);
} }
else else
{ {
@ -145,8 +162,7 @@ public class PacketListenerSounds extends PacketAdapter
ex.printStackTrace(); ex.printStackTrace();
} }
soundType = entitySound.getType(ReflectionManager.convertSoundEffectToString(soundEffect), soundType = entitySound.getType(soundEffect, !hasInvun);
!hasInvun);
} }
if (soundType != null) if (soundType != null)
@ -157,14 +173,9 @@ public class PacketListenerSounds extends PacketAdapter
} }
} }
} }
}
}
if (disguise != null) if (disguise != null && disguise.isSoundsReplaced()
{ && (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer))
if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer())
{
if (disguise.isSoundsReplaced())
{ {
String sound = null; String sound = null;
@ -183,8 +194,8 @@ public class PacketListenerSounds extends PacketAdapter
{ {
try try
{ {
int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(), int typeId = observer.getWorld().getBlockTypeIdAt((int) Math.floor(soundCords[0] / 8D),
soundLoc.getBlockY() - 1, soundLoc.getBlockZ()); (int) Math.floor(soundCords[1] / 8D), (int) Math.floor(soundCords[2] / 8D));
Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "getId", int.class) Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "getId", int.class)
.invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId); .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId);
@ -193,8 +204,7 @@ public class PacketListenerSounds extends PacketAdapter
{ {
Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
mods.write(0, mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step));
ReflectionManager.getNmsMethod(step.getClass(), "d").invoke(step));
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
} }
} }
@ -245,8 +255,8 @@ public class PacketListenerSounds extends PacketAdapter
if (pitch > 97 || pitch < 111) if (pitch > 97 || pitch < 111)
return; return;
pitch = (DisguiseUtilities.random.nextFloat() pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat())
- DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F; * 0.2F + 1.5F;
// Min = 1.5 // Min = 1.5
// Cap = 97.5 // Cap = 97.5
// Max = 1.7 // Max = 1.7
@ -258,8 +268,8 @@ public class PacketListenerSounds extends PacketAdapter
if (pitch >= 63 || pitch <= 76) if (pitch >= 63 || pitch <= 76)
return; return;
pitch = (DisguiseUtilities.random.nextFloat() pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat())
- DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F; * 0.2F + 1.0F;
// Min = 1 // Min = 1
// Cap = 63 // Cap = 63
// Max = 1.2 // Max = 1.2
@ -282,8 +292,6 @@ public class PacketListenerSounds extends PacketAdapter
} }
} }
} }
}
}
else if (event.getPacketType() == Server.ENTITY_STATUS) else if (event.getPacketType() == Server.ENTITY_STATUS)
{ {
if ((byte) mods.read(1) != 2) if ((byte) mods.read(1) != 2)