Don't modify the destroy packet and just send our own

This commit is contained in:
libraryaddict 2021-07-01 09:40:22 +12:00
parent afe4022920
commit 6c17603905

View File

@ -71,26 +71,21 @@ public class PacketListenerEntityDestroy extends PacketAdapter {
public void onPre17Packet(PacketEvent event) { public void onPre17Packet(PacketEvent event) {
int[] entityIds = event.getPacket().getIntegerArrays().read(0); int[] entityIds = event.getPacket().getIntegerArrays().read(0);
int[] newEntityIds = entityIds;
for (int entityId : entityIds) { for (int entityId : entityIds) {
int[] toAdd = getToRemove(event.getPlayer(), entityId); int[] toRemove = getToRemove(event.getPlayer(), entityId);
if (toAdd == null) { if (toRemove == null) {
continue; continue;
} }
newEntityIds = Arrays.copyOf(entityIds, entityIds.length + toAdd.length); try {
for (PacketContainer container : DisguiseUtilities.getDestroyPackets(toRemove)) {
for (int a = 0; a < toAdd.length; a++) { ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), container);
newEntityIds[newEntityIds.length - (a + 1)] = toAdd[a]; }
} catch (InvocationTargetException e) {
e.printStackTrace();
} }
} }
if (entityIds.length == newEntityIds.length) {
return;
}
event.getPacket().getIntegerArrays().write(0, newEntityIds);
} }
} }