I don’t think you know how this works. It is possible to ‘register’ and ‘unregister’ very easily with a filter:
server.events.playerMove()
.filter(new Fn<PlayerMoveEvent, Boolean>() {
public Boolean call(PlayerMoveEvent event) {
return event.getPosition().getX() > 0;
}
}).map(new Fn<PlayerMoveEvent, Vector>() {
public Vector call(PlayerMoveEvent event) {
return event.getPlayer().getPosition();
}
}).forEach(new Fn<Event, Void>(){
public Void call(Vector v) {
doSomething(v);
}
});
Filter takes a function that returns a boolean and if that function returns true for a given value, the filter passes. The above filter only ‘registered’ when a move location’s x value is greater than zero. In that way there is no need for ‘registering’ or ‘unregistering’.
Thanks for the clarification! I actually did and do know what you mean and totally agree. That’s what I was trying to express with the more dynamic system of my above post. Now rereading it I can see where the confusion comes from - sorry about not being more specific about it. That might be due to the fact that English is not my first language and/or it being 5:45 am right now.
@kenzierocks
Yeah, you can do “the cool lambda stuff” with jdk6. A Lambda expression is just syntax sugar for a functional interface. Java 8 lambdas just allow less typing. In java6, you would just create a new anonymous class and override the method of the interface.
The real reason to switch to Java 8 is interfaces with a default implementation. Which sk89q has said that he wants this functionality… Okay ? So switch to java8 then. No big deal. Servers have to upgrade. That’s not a problem.
Also, IntelliJ IDEA hides all the ugly new Interface() blah stuff for you.