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:
Ursprung
2a71612aea
Commit
4f66fd793b
@ -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;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren