package net.alcuria.umbracraft.engine.events;

import net.alcuria.umbracraft.Game;

import com.badlogic.gdx.utils.Array;

/** A simple event system. Listeners subscribe by calling
 * {@link EventPublisher#subscribe(EventListener)} and events are published via
 * the {@link EventPublisher#publish(Event)} method. Subscribing classes are
 * responsible for using instanceof to determine if any published events are the
 * correct type.
 * @author Andrew Keturi */
public class EventPublisher {
	Array<EventListener> listeners = new Array<EventListener>();

	public void publish(Event event) {

		// Notify listeners
		for (EventListener listener : listeners) {
			listener.onEvent(event);
		}
	}

	public void removeAllListeners() {
		listeners.clear();
		Game.log("Cleared.");
	}

	public void subscribe(EventListener listener) {
		listeners.add(listener);
		Game.log("Subscribed. Listener count: " + listeners.size);
	}

	public void unsubscribe(EventListener listener) {
		listeners.removeValue(listener, true);
		Game.log("Unsubscribed. Listener count: " + listeners.size);
	}
}

@@ -549,16 +549,116 @@
 er%3E();%0A%0A
+%09/** Publishes an event, notifying all listeners.%0A%09 * @param event the %7B@link Event%7D to publish. */%0A
 %09public 
@@ -688,31 +688,8 @@
 t) %7B
-%0A%0A%09%09// Notify listeners
 %0A%09%09f
@@ -762,24 +762,55 @@
 t);%0A%09%09%7D%0A%09%7D%0A%0A
+%09/** Removes all listeners. */%0A
 %09public void
@@ -878,24 +878,207 @@
 red.%22);%0A%09%7D%0A%0A
+%09/** Adds an %7B@link EventListener%7D to the subscribed list to receive events%0A%09 * when %7B@link EventPublisher#publish(Event)%7D is called.%0A%09 * @param listener the %7B@link EventListener%7D */%0A
 %09public void
@@ -1206,16 +1206,76 @@
 e);%0A%09%7D%0A%0A
+%09/** Unsubscribes a single listener.%0A%09 * @param listener */%0A
 %09public 

Add javadocs to the EventPublisher