use of com.viaversion.viaversion.rewriter.meta.MetaHandlerEventImpl in project ViaVersion by ViaVersion.
the class EntityRewriter method handleMetadata.
@Override
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) {
EntityType type = tracker(connection).entityType(entityId);
// Count index for fast removal
int i = 0;
for (Metadata metadata : metadataList.toArray(EMPTY_ARRAY)) {
// Call handlers implementing the old handleMetadata
if (!callOldMetaHandler(entityId, type, metadata, metadataList, connection)) {
metadataList.remove(i--);
continue;
}
MetaHandlerEvent event = null;
for (MetaFilter filter : metadataFilters) {
if (!filter.isFiltered(type, metadata)) {
continue;
}
if (event == null) {
// Only initialize when needed and share event instance
event = new MetaHandlerEventImpl(connection, type, entityId, metadata, metadataList);
}
try {
filter.handler().handle(event, metadata);
} catch (Exception e) {
logException(e, type, metadataList, metadata);
metadataList.remove(i--);
break;
}
if (event.cancelled()) {
// Remove meta, decrease list index counter, and break current filter loop
metadataList.remove(i--);
break;
}
}
if (event != null && event.extraMeta() != null) {
// Finally, add newly created meta
metadataList.addAll(event.extraMeta());
}
i++;
}
}
Aggregations