NotFaceguy's fix for sound issues that has apparently been plaguing him for decades
This commit is contained in:
parent
fc97a5952b
commit
ffcf4fd282
@ -23,9 +23,10 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Set;
|
||||
|
||||
public class PacketListenerSounds extends PacketAdapter {
|
||||
|
||||
/**
|
||||
* This is a fix for the stupidity that is
|
||||
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
|
||||
* This is a fix for the stupidity that is "I can't separate the sounds from the sounds the player
|
||||
* heard, and the sounds of the entity tracker heard"
|
||||
*/
|
||||
private static boolean cancelSound;
|
||||
|
||||
@ -43,18 +44,23 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getPlayer().getName().contains("UNKNOWN[")) // If the player is temporary
|
||||
{
|
||||
if (event.getPlayer().getName().contains("UNKNOWN[")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
if (event.getPacketType() == Server.ENTITY_STATUS) {
|
||||
handleEntityStatus(event);
|
||||
} else if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
|
||||
handleNamedSoundEffect(event);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNamedSoundEffect(PacketEvent event) {
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
Player observer = event.getPlayer();
|
||||
|
||||
if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
|
||||
SoundType soundType = null;
|
||||
|
||||
Entity disguisedEntity = null;
|
||||
@ -65,7 +71,6 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
|
||||
int[] soundCords = new int[]{(Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4)};
|
||||
|
||||
loop:
|
||||
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
|
||||
for (TargetedDisguise entityDisguise : disguises) {
|
||||
Entity entity = entityDisguise.getEntity();
|
||||
@ -86,31 +91,42 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
continue;
|
||||
}
|
||||
|
||||
disguise = entityDisguise;
|
||||
disguisedEntity = entity;
|
||||
entitySound = SoundGroup.getGroup(entity.getType().name());
|
||||
|
||||
if (entitySound == null) {
|
||||
event.setCancelled(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((!(entity instanceof LivingEntity)) || ((LivingEntity) entity).getHealth() > 0) {
|
||||
boolean hasInvun = ReflectionManager.hasInvul(entity);
|
||||
|
||||
soundType = entitySound.getType(soundEffectObj, !hasInvun);
|
||||
} else {
|
||||
soundType = SoundType.DEATH;
|
||||
}
|
||||
|
||||
if (soundType != null) {
|
||||
disguise = entityDisguise;
|
||||
disguisedEntity = entity;
|
||||
break loop;
|
||||
}
|
||||
if (disguise != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (disguise != null && disguise.isSoundsReplaced() && (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
|
||||
if (disguise == null || !disguise.isSoundsReplaced()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Blocks null and CANCEL, HURT and DEATH are 100% handled by entity status!
|
||||
if (soundType != SoundType.STEP && soundType != SoundType.IDLE) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (disguisedEntity == observer && !disguise.isSelfDisguiseSoundsReplaced()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object sound = null;
|
||||
|
||||
SoundGroup disguiseSound = SoundGroup.getGroup(disguise);
|
||||
|
||||
if (disguiseSound != null) {
|
||||
@ -119,13 +135,13 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
|
||||
if (sound == null) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
Enum soundCat = ReflectionManager.getSoundCategory(disguise.getType());
|
||||
float volume = (float) mods.read(5);
|
||||
float pitch = (float) mods.read(6);
|
||||
|
||||
// Time to change the pitch and volume
|
||||
if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE) {
|
||||
// If the volume is the default
|
||||
if (volume == entitySound.getDamageAndIdleSoundVolume()) {
|
||||
volume = disguiseSound.getDamageAndIdleSoundVolume();
|
||||
@ -181,9 +197,11 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
mods.write(6, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event.getPacketType() == Server.ENTITY_STATUS) {
|
||||
|
||||
private void handleEntityStatus(PacketEvent event) {
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
Player observer = event.getPlayer();
|
||||
|
||||
if ((byte) mods.read(1) != 2) {
|
||||
return;
|
||||
}
|
||||
@ -197,29 +215,40 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
|
||||
Entity entity = disguise.getEntity();
|
||||
|
||||
if (!disguise.getType().isPlayer() && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
|
||||
if (disguise instanceof TargetedDisguise) {
|
||||
Set<TargetedDisguise> discs = DisguiseUtilities.getDisguises().get(entity.getEntityId());
|
||||
for (TargetedDisguise targetedDisguise : discs) {
|
||||
if (targetedDisguise != disguise) {
|
||||
continue;
|
||||
}
|
||||
if (!targetedDisguise.canSee(observer)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SoundType soundType = SoundType.HURT;
|
||||
|
||||
if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) {
|
||||
soundType = SoundType.DEATH;
|
||||
}
|
||||
|
||||
if (entity == event.getPlayer() && !disguise.getType().isPlayer()) {
|
||||
if (!disguise.isSelfDisguiseSoundsReplaced()) {
|
||||
cancelSound = !cancelSound;
|
||||
if (cancelSound) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SoundGroup disSound = SoundGroup.getGroup(entity.getType().name());
|
||||
|
||||
if (disSound == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SoundType soundType = SoundType.HURT;
|
||||
Object obj = null;
|
||||
|
||||
if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) {
|
||||
soundType = SoundType.DEATH;
|
||||
}
|
||||
|
||||
if (disSound.getSound(soundType) == null || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) {
|
||||
if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) {
|
||||
cancelSound = !cancelSound;
|
||||
|
||||
if (cancelSound) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (disSound.getSound(soundType) != null) {
|
||||
disSound = SoundGroup.getGroup(disguise);
|
||||
|
||||
if (disSound != null) {
|
||||
@ -253,6 +282,7 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
|
||||
mods.write(6, pitch);
|
||||
|
||||
event.setCancelled(true);
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
@ -263,5 +293,4 @@ public class PacketListenerSounds extends PacketAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user