Only clone sounds when needed, minor cleanup. Thanks again Jok on discord for pointing this out!

This commit is contained in:
libraryaddict 2021-11-11 21:00:45 +13:00
parent 90f23f92d3
commit e7b370733f

View File

@ -38,17 +38,9 @@ public class PacketListenerSounds extends PacketAdapter {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
if (event.isCancelled()) { if (event.isCancelled() || event.isAsync() || event.isPlayerTemporary()) {
return; return;
} }
if (event.isAsync()) {
return;
}
if (event.getPlayer().getName().contains("UNKNOWN[")) {
return;
}
event.setPacket(event.getPacket().shallowClone());
if (event.getPacketType() == Server.ENTITY_STATUS) { if (event.getPacketType() == Server.ENTITY_STATUS) {
handleEntityStatus(event); handleEntityStatus(event);
@ -106,6 +98,7 @@ public class PacketListenerSounds extends PacketAdapter {
soundType = SoundType.DEATH; soundType = SoundType.DEATH;
} }
} }
if (disguise != null) { if (disguise != null) {
break; break;
} }
@ -169,6 +162,9 @@ public class PacketListenerSounds extends PacketAdapter {
event.setPacket(newPacket); event.setPacket(newPacket);
} else { } else {
event.setPacket(event.getPacket().shallowClone());
mods = event.getPacket().getModifier();
mods.write(0, sound); mods.write(0, sound);
mods.write(1, soundCat); mods.write(1, soundCat);
mods.write(5, volume); mods.write(5, volume);
@ -214,6 +210,7 @@ public class PacketListenerSounds extends PacketAdapter {
if (entity == event.getPlayer() && !disguise.getType().isPlayer()) { if (entity == event.getPlayer() && !disguise.getType().isPlayer()) {
if (!disguise.isSelfDisguiseSoundsReplaced()) { if (!disguise.isSelfDisguiseSoundsReplaced()) {
cancelSound = !cancelSound; cancelSound = !cancelSound;
if (cancelSound) { if (cancelSound) {
return; return;
} }
@ -226,17 +223,21 @@ public class PacketListenerSounds extends PacketAdapter {
return; return;
} }
if (disSound.getSound(soundType) != null) { Object sound = disSound.getSound(soundType);
if (sound == null) {
return;
}
disSound = SoundGroup.getGroup(disguise); disSound = SoundGroup.getGroup(disguise);
if (disSound != null) { if (disSound == null) {
Object sound = disSound.getSound(soundType); return;
}
if (sound != null) {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
PacketContainer packet = new PacketContainer( PacketContainer packet =
sound.getClass().getSimpleName().equals("MinecraftKey") ? Server.CUSTOM_SOUND_EFFECT : Server.NAMED_SOUND_EFFECT); new PacketContainer(sound.getClass().getSimpleName().equals("MinecraftKey") ? Server.CUSTOM_SOUND_EFFECT : Server.NAMED_SOUND_EFFECT);
mods = packet.getModifier(); mods = packet.getModifier();
@ -268,6 +269,3 @@ public class PacketListenerSounds extends PacketAdapter {
} }
} }
} }
}
}
}