3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Go back to fast entity data list iteration and mutation

This is a fairly hot method and the array list cannot be modified outside of the already managed event cancellation and provided extra list
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-08-25 18:59:48 +02:00
Ursprung 2a71612aea
Commit 4f66fd793b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F

Datei anzeigen

@ -110,7 +110,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
public void handleEntityData(final int entityId, final List<EntityData> dataList, final UserConnection connection) {
final TrackedEntity entity = tracker(connection).entity(entityId);
final EntityType type = entity != null ? entity.entityType() : null;
for (final EntityData entityData : dataList.toArray(EMPTY_ARRAY)) { // Copy the list to allow mutation
// Iterate over indexed list to allow for removal and addition of elements, decrease current index and size if an element is removed
int size = dataList.size();
for (int i = 0; i < size; i++) {
final EntityData entityData = dataList.get(i);
EntityDataHandlerEvent event = null;
for (final EntityDataFilter filter : entityDataFilters) {
if (!filter.isFiltered(type, entityData)) {
@ -125,13 +129,15 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
filter.handler().handle(event, entityData);
} catch (final Exception e) {
logException(e, type, dataList, entityData);
dataList.remove(entityData);
dataList.remove(i--);
size--;
break;
}
if (event.cancelled()) {
// Remove entity data, and break current filter loop
dataList.remove(entityData);
dataList.remove(i--);
size--;
break;
}
}