mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-04 13:54:35 +01:00
Fix hurt sound for self disguises
This commit is contained in:
parent
1fbda44bb1
commit
675bba5ecc
@ -21,6 +21,7 @@ import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerAttachEntity;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerCollectItem;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDamageEvent;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
|
||||
@ -3079,6 +3080,8 @@ public class DisguiseUtilities {
|
||||
return new WrapperPlayServerDestroyEntities(event);
|
||||
case ENTITY_POSITION_SYNC:
|
||||
return new WrapperPlayServerEntityPositionSync(event);
|
||||
case DAMAGE_EVENT:
|
||||
return new WrapperPlayServerDamageEvent(event);
|
||||
default:
|
||||
throw new IllegalStateException(event.getPacketType() + " wasn't in the enums");
|
||||
}
|
||||
@ -3131,6 +3134,8 @@ public class DisguiseUtilities {
|
||||
return ((WrapperPlayServerCollectItem) wrapper).getCollectorEntityId();
|
||||
} else if (wrapper instanceof WrapperPlayServerEntityPositionSync) {
|
||||
return ((WrapperPlayServerEntityPositionSync) wrapper).getId();
|
||||
} else if (wrapper instanceof WrapperPlayServerDamageEvent) {
|
||||
return ((WrapperPlayServerDamageEvent) wrapper).getEntityId();
|
||||
} else {
|
||||
throw new IllegalStateException("The packet " + wrapper.getClass() + " has no entity ID");
|
||||
}
|
||||
@ -3221,6 +3226,10 @@ public class DisguiseUtilities {
|
||||
if (((WrapperPlayServerEntityPositionSync) wrapper).getId() == playerId) {
|
||||
((WrapperPlayServerEntityPositionSync) wrapper).setId(DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
} else if (wrapper instanceof WrapperPlayServerDamageEvent) {
|
||||
if (((WrapperPlayServerDamageEvent) wrapper).getEntityId() == playerId) {
|
||||
((WrapperPlayServerDamageEvent) wrapper).setEntityId(DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class PacketListenerViewSelfDisguise extends SimplePacketListenerAbstract
|
||||
Server.ATTACH_ENTITY, Server.ENTITY_RELATIVE_MOVE_AND_ROTATION, Server.ENTITY_RELATIVE_MOVE, Server.ENTITY_HEAD_LOOK,
|
||||
Server.ENTITY_ROTATION, Server.ENTITY_TELEPORT, Server.ENTITY_MOVEMENT, Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT,
|
||||
Server.ENTITY_ANIMATION, Server.ENTITY_EFFECT, Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS,
|
||||
Server.ENTITY_POSITION_SYNC}) {
|
||||
Server.ENTITY_POSITION_SYNC, Server.DAMAGE_EVENT}) {
|
||||
listenedPackets[packet.ordinal()] = true;
|
||||
}
|
||||
}
|
||||
@ -197,6 +197,17 @@ public class PacketListenerViewSelfDisguise extends SimplePacketListenerAbstract
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event.getPacketType() == Server.DAMAGE_EVENT) {
|
||||
if (disguise.isSelfDisguiseSoundsReplaced()) {
|
||||
event.setCancelled(true);
|
||||
// No sound is sent but instead the client is expected to play a hurt sound on damage
|
||||
SoundGroup group = SoundGroup.getGroup(disguise);
|
||||
ResourceLocation sound = group.getSound(SoundGroup.SoundType.HURT);
|
||||
|
||||
if (sound != null) {
|
||||
observer.playSound(observer.getLocation(), sound.toString(), 1f, 1f);
|
||||
}
|
||||
}
|
||||
} else if (event.getPacketType() == Server.ENTITY_VELOCITY && !DisguiseUtilities.isPlayerVelocity(observer)) {
|
||||
// The player only sees velocity changes when there is a velocity event. As the method claims there
|
||||
// was no velocity event...
|
||||
|
Loading…
Reference in New Issue
Block a user