diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index ddf3e5fe..12db2901 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -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. */ diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerViewSelfDisguise.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerViewSelfDisguise.java index c50fc79d..0e15d3be 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerViewSelfDisguise.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerViewSelfDisguise.java @@ -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 diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java index 9b2bfcb9..fd5feaf1 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/NmsVersion.java @@ -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; + } }