package org.rocket.network.acara;

import com.github.blackrush.acara.dispatch.Dispatcher;
import org.fungsi.Either;
import org.rocket.network.NetworkClient;
import org.rocket.network.event.NetworkEvent;

import java.util.List;

final class RocketPropValidatorDispatcher implements Dispatcher {
    private final Dispatcher dispatcher;
    private final List<Validations.Validation> validations;

    public RocketPropValidatorDispatcher(Dispatcher dispatcher, List<Validations.Validation> validations) {
        this.dispatcher = dispatcher;
        this.validations = validations;
    }

    @Override
    public Either<Object, Throwable> dispatch(Object listener, Object o) {
        NetworkEvent event = (NetworkEvent) o;
        NetworkClient client = event.getClient();
        for (Validations.Validation validation : validations) {
            if (!validation.validate(client)) {
                throw new IllegalStateException(validation.describe());
            }
        }

        return dispatcher.dispatch(listener, event);
    }
}

@@ -287,32 +287,24 @@
 tcher %7B%0A    
-private 
 final Dispat
@@ -328,16 +328,8 @@
     
-private 
 fina

enable testing