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