Created
July 6, 2016 19:35
-
-
Save Deamon5550/df2aadd0680933f7b7ca4f1970985663 to your computer and use it in GitHub Desktop.
Alternate event factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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