package de.bitbrain.braingdx.event;

import com.badlogic.gdx.Gdx;
import org.apache.commons.collections.map.MultiValueMap;

import java.util.Collection;

/**
 * @since 0.2.0
 * @author Miguel Gonzalez Sanchez
 */
public class GameEventManagerImpl implements GameEventManager {
   
   private final MultiValueMap listenerMapping = new MultiValueMap();

   @Override
   public <T extends GameEvent> void register(GameEventListener<T> listener, Class<T> clazz) {
      listenerMapping.put(clazz, listener);
   }

   @SuppressWarnings("unchecked")
   @Override
   public <T extends GameEvent> void unregister(GameEventListener<T> listener, Class<T> clazz) {
      Collection<?> listeners = (Collection<GameEventListener<T>>) listenerMapping.get(clazz);
      if (listeners.remove(listener)) {
         if (listeners.isEmpty()) {
            listenerMapping.remove(clazz);
         }
      }
   }

   @SuppressWarnings("unchecked")
   @Override
   public <T extends GameEvent> void publish(T event) {
      Collection<GameEventListener<T>> listeners = (Collection<GameEventListener<T>>) listenerMapping.get(event.getClass());
      if (listeners != null) {
         for (GameEventListener<T> listener : listeners) {
            listener.onEvent(event);
         }
      } else {
         Gdx.app.error("FATAL", "No GameEventListener for event type " + event.getClass() + " registered!");
      }
   }

   @Override
   public void clear() {
      listenerMapping.clear();
   }

   @Override
   public <T extends GameEvent> void clear(Class<T> clazz) {
      listenerMapping.remove(clazz);
   }

}

@@ -1288,55 +1288,48 @@
 app.
-error(%22FATAL%22, %22No GameEventListener for
+debug(%22EVENT%22, %22Not publishing
  event 
+of 
 type
@@ -1353,16 +1353,30 @@
 ss() + %22
+ - no listener
  registe

Change error to debug message when no listeners are defined for published events