package org.rocket.network.acara;

import com.github.blackrush.acara.dispatch.Dispatcher;
import com.google.inject.Key;
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<Key<?>> present;

    public RocketPropValidatorDispatcher(Dispatcher dispatcher, List<Key<?>> present) {
        this.dispatcher = dispatcher;
        this.present = present;
    }

    @Override
    public Either<Object, Throwable> dispatch(Object listener, Object o) {
        NetworkEvent event = (NetworkEvent) o;
        NetworkClient client = event.getClient();
        for (Key<?> key : present) {
            if (!client.isPropPresent(key)) {
                throw new IllegalStateException("property " + key + " is not present");
            }
        }

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

@@ -389,23 +389,20 @@
 Key%3C?%3E%3E 
-present
+keys
 ;%0A%0A    p
@@ -473,23 +473,20 @@
 Key%3C?%3E%3E 
-present
+keys
 ) %7B%0A    
@@ -536,25 +536,19 @@
 his.
-present = present
+keys = keys
 ;%0A  
@@ -764,23 +764,20 @@
 %3E key : 
-present
+keys
 ) %7B%0A    

rename poorly named field