From 6897e00c6fca46dcdef032c3bb8e5601b59b02e9 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 17 May 2020 18:25:05 +1200 Subject: [PATCH] Fix build failure, fix squids velocity --- .../packethandlers/PacketHandlerVelocity.java | 4 ++ .../PacketListenerEntityDestroy.java | 62 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerVelocity.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerVelocity.java index be18efaf..e786cc52 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerVelocity.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerVelocity.java @@ -28,5 +28,9 @@ public class PacketHandlerVelocity implements IPacketHandler { } packets.clear(); + + PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_VELOCITY); + packet.getIntegers().write(0, entity.getEntityId()); + packets.addPacket(packet); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java new file mode 100644 index 00000000..498d6516 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerEntityDestroy.java @@ -0,0 +1,62 @@ +package me.libraryaddict.disguise.utilities.packets.packetlisteners; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketEvent; +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import org.bukkit.plugin.Plugin; + +import java.util.Arrays; + +/** + * Created by libraryaddict on 3/05/2020. + */ +public class PacketListenerEntityDestroy extends PacketAdapter { + public PacketListenerEntityDestroy(Plugin plugin) { + super(plugin, PacketType.Play.Server.ENTITY_DESTROY); + } + + @Override + public void onPacketSending(PacketEvent event) { + int[] entityIds = event.getPacket().getIntegerArrays().read(0); + int[] newEntityIds = entityIds; + + for (int entityId : entityIds) { + if (entityId == DisguiseAPI.getSelfDisguiseId()) { + return; + } + + Disguise disguise = DisguiseUtilities.getDisguise(event.getPlayer(), entityId); + + if (disguise == null) { + continue; + } + + int len = disguise.getMultiNameLength(); + + if (len == 0) { + continue; + } + + // If this packet has already been processed + if (entityIds.length == newEntityIds.length && + Arrays.stream(entityIds).anyMatch(id -> id == disguise.getArmorstandIds()[0])) { + return; + } + + newEntityIds = Arrays.copyOf(entityIds, entityIds.length + len); + + for (int a = 0; a < len; a++) { + newEntityIds[newEntityIds.length - (a + 1)] = disguise.getArmorstandIds()[a]; + } + } + + if (entityIds.length == newEntityIds.length) { + return; + } + + event.getPacket().getIntegerArrays().write(0, newEntityIds); + } +}