Skip to content

Instantly share code, notes, and snippets.

@Deamon5550
Created July 6, 2016 19:35
Show Gist options
  • Save Deamon5550/df2aadd0680933f7b7ca4f1970985663 to your computer and use it in GitHub Desktop.
Save Deamon5550/df2aadd0680933f7b7ca4f1970985663 to your computer and use it in GitHub Desktop.
Alternate event factory
/**
* A factory for generating events at runtime based on interfaces.
*/
public interface EventFactory {
/**
* Creates a new event instance of the given event type, generating an
* implementation class if needed. The arguments are specified in
* alphabetical ordering.
*
* @param type The event type
* @param args The event arguments
* @return The new event instance
*/
<E extends Event> E create(Class<E> type, Object... args);
}
public interface ExampleEvent extends Event {
public static ExampleEvent of(int value, int anotherValue) {
return Sponge.getEventFactory().create(ExampleEvent.class, anotherValue, value);
}
int getValue();
int getAnotherValue();
}
Sponge.getEventManager().post(ExampleEvent.of(5, 7));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment