package org.rocket.network.guice;

import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.PrivateBinder;
import com.google.inject.multibindings.Multibinder;
import org.rocket.network.Controller;
import org.rocket.network.ControllerFactory;
import org.rocket.network.NetworkClient;

import java.util.Set;

public abstract class ClientControllerModule extends BaseControllerModule {
    private PrivateBinder controllerBinder;
    private Multibinder<Object> controllerMultibinder;

    @Override
    protected void before() {
        controllerBinder = binder().newPrivateBinder();
        controllerMultibinder = Multibinder.newSetBinder(controllerBinder, Object.class, Controller.class);
    }

    @Override
    protected void after() {
        controllerBinder.bind(ControllerFactory.class).to(Hook.class);
        controllerBinder.expose(ControllerFactory.class);
    }

    @Override
    protected Multibinder<Object> controllerMultibinder() {
        return controllerMultibinder;
    }

    @Override
    protected Binder controllerBinder() {
        return controllerBinder;
    }

    static class Hook implements ControllerFactory {
        @Inject Injector injector;

        @Override
        public Set<Object> create(NetworkClient client) {
            return injector.getInstance(CONTROLLERS_KEY);
        }
    }
}

@@ -119,23 +119,28 @@
 .inject.
-Injecto
+PrivateBinde
 r;%0Aimpor
@@ -157,32 +157,27 @@
 le.inject.Pr
-ivateBin
+ovi
 der;%0Aimport 
@@ -445,16 +445,17 @@
 odule %7B%0A
+%0A
     priv
@@ -862,20 +862,26 @@
 ass).to(
-Hook
+TheFactory
 .class);
@@ -930,32 +930,104 @@
 rFactory.class);
+%0A%0A        controllerMultibinder = null;%0A        controllerBinder = null;
 %0A    %7D%0A%0A    @Ove
@@ -1046,35 +1046,22 @@
 otected 
-Multibinder%3CObject%3E
+Binder
  control
@@ -1059,30 +1059,25 @@
 r controller
-Multib
+B
 inder() %7B%0A  
@@ -1095,30 +1095,25 @@
 n controller
-Multib
+B
 inder;%0A    %7D
@@ -1134,38 +1134,51 @@
 e%0A    protected 
-Binder
+Multibinder%3CObject%3E
  controllerBinde
@@ -1164,33 +1164,38 @@
 ject%3E controller
-B
+Multib
 inder() %7B%0A      
@@ -1205,33 +1205,38 @@
 eturn controller
-B
+Multib
 inder;%0A    %7D%0A%0A  
@@ -1254,12 +1254,18 @@
 ass 
-Hook
+TheFactory
  imp
@@ -1304,34 +1304,195 @@
     
-@Inject Injector injector;
+private final Provider%3CSet%3CObject%3E%3E controllers;%0A%0A        @Inject%0A        TheFactory(@Controller Provider%3CSet%3CObject%3E%3E controllers) %7B%0A            this.controllers = controllers;%0A        %7D
 %0A%0A  
@@ -1588,44 +1588,24 @@
 urn 
-injector.getInstance(CONTROLLERS_KEY
+controllers.get(
 );%0A 

fix client controller module