Readd support for DamageEvent, but conditional

This commit is contained in:
libraryaddict 2024-12-17 12:18:26 +13:00
parent c4ea9b4bdb
commit 6bd3141704
3 changed files with 19 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.particle.Particle;
import com.github.retrooper.packetevents.protocol.player.Equipment;
@ -3240,6 +3241,10 @@ public class DisguiseUtilities {
}
}
public static boolean isRegistered(MappedEntity mappedEntity) {
return mappedEntity.getId(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()) >= 0;
}
/**
* Method to send a packet to the self disguise, translate their entity ID to the fake id.
*/

View File

@ -5,6 +5,7 @@ import com.github.retrooper.packetevents.event.SimplePacketListenerAbstract;
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.packettype.PacketType.Play.Server;
import com.github.retrooper.packetevents.protocol.world.damagetype.DamageTypes;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation;
@ -36,9 +37,16 @@ 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.DAMAGE_EVENT*/}) { // Damage event disabled for now, PE seems to be kicking players for null damage type
Server.ENTITY_POSITION_SYNC, Server.DAMAGE_EVENT}) {
// Packet DAMAGE_EVENT does not have all mappings added for every version of Minecraft in PacketEvents
// https://github.com/retrooper/packetevents/blob/2.0/mappings/damage/damagetype_mappings.json
if (packet == Server.DAMAGE_EVENT && !DisguiseUtilities.isRegistered(DamageTypes.CRAMMING)) {
continue;
}
listenedPackets[packet.ordinal()] = true;
}
}
@Override

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities.reflection;
import lombok.Getter;
@Getter
public enum NmsVersion {
v1_12("1.12", "1.12.1", "1.12.2"),
v1_13("1.13", "1.13.1", "1.13.2"),
@ -22,7 +23,6 @@ public enum NmsVersion {
v1_21_R3("1.21.4"),
UNSUPPORTED("N/A");
@Getter
private final String[] supportedVersions;
NmsVersion(String... minecraftVersions) {
@ -51,4 +51,8 @@ public enum NmsVersion {
public boolean isSupported() {
return ReflectionManager.getVersion() != null && ReflectionManager.getVersion().ordinal() >= ordinal();
}
public boolean isVersion() {
return ReflectionManager.getVersion() == this;
}
}