Did a hackish fix for duplicate damage sounds in self disguises
This commit is contained in:
parent
3f2be04de7
commit
eb01397c7d
@ -82,6 +82,7 @@ public class PacketsManager {
|
|||||||
private static boolean viewDisguisesListenerEnabled;
|
private static boolean viewDisguisesListenerEnabled;
|
||||||
private static LibsDisguises libsDisguises;
|
private static LibsDisguises libsDisguises;
|
||||||
private static DisguiseAPI disguiseAPI = new DisguiseAPI();
|
private static DisguiseAPI disguiseAPI = new DisguiseAPI();
|
||||||
|
private static boolean cancelSound;
|
||||||
|
|
||||||
protected static void addPacketListeners(final JavaPlugin libsDisguises) {
|
protected static void addPacketListeners(final JavaPlugin libsDisguises) {
|
||||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||||
@ -435,6 +436,8 @@ public class PacketsManager {
|
|||||||
Packets.Server.NAMED_SOUND_EFFECT, Packets.Server.ENTITY_STATUS) {
|
Packets.Server.NAMED_SOUND_EFFECT, Packets.Server.ENTITY_STATUS) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
if (event.isCancelled())
|
||||||
|
return;
|
||||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||||
Player observer = event.getPlayer();
|
Player observer = event.getPlayer();
|
||||||
if (event.getPacketID() == Packets.Server.NAMED_SOUND_EFFECT) {
|
if (event.getPacketID() == Packets.Server.NAMED_SOUND_EFFECT) {
|
||||||
@ -561,6 +564,11 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
if (disSound.getSound(soundType) == null
|
if (disSound.getSound(soundType) == null
|
||||||
|| (disguise.canHearSelfDisguise() && entity == event.getPlayer())) {
|
|| (disguise.canHearSelfDisguise() && entity == event.getPlayer())) {
|
||||||
|
if (disguise.canHearSelfDisguise() && entity == event.getPlayer()) {
|
||||||
|
cancelSound = !cancelSound;
|
||||||
|
if (cancelSound)
|
||||||
|
return;
|
||||||
|
}
|
||||||
disSound = DisguiseSound.getType(disguise.getType().name());
|
disSound = DisguiseSound.getType(disguise.getType().name());
|
||||||
if (disSound != null) {
|
if (disSound != null) {
|
||||||
String sound = disSound.getSound(soundType);
|
String sound = disSound.getSound(soundType);
|
||||||
@ -599,7 +607,7 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
viewDisguisesListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST,
|
viewDisguisesListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGH,
|
||||||
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ATTACH_ENTITY, Packets.Server.REL_ENTITY_MOVE,
|
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ATTACH_ENTITY, Packets.Server.REL_ENTITY_MOVE,
|
||||||
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
|
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
|
||||||
Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT,
|
Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT,
|
||||||
@ -613,6 +621,7 @@ public class PacketsManager {
|
|||||||
if (entity == event.getPlayer()) {
|
if (entity == event.getPlayer()) {
|
||||||
int fakeId = DisguiseAPI.getFakeDisguise(entity.getEntityId());
|
int fakeId = DisguiseAPI.getFakeDisguise(entity.getEntityId());
|
||||||
if (fakeId > 0) {
|
if (fakeId > 0) {
|
||||||
|
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
|
||||||
PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer());
|
PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer());
|
||||||
try {
|
try {
|
||||||
for (PacketContainer packet : packets) {
|
for (PacketContainer packet : packets) {
|
||||||
@ -671,8 +680,9 @@ public class PacketsManager {
|
|||||||
|
|
||||||
case Packets.Server.ENTITY_STATUS:
|
case Packets.Server.ENTITY_STATUS:
|
||||||
if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise()
|
if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise()
|
||||||
&& (Byte) event.getPacket().getModifier().read(1) == 2)
|
&& (Byte) event.getPacket().getModifier().read(1) == 2) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user