Defining startable plugins in Java
You can develop you custom startable plugin in Java, but special considerations apply.
If you have Java files for your startable plugin, place your Java class and libraries files in the same places as with other plugin types.
In Gosu, your startable plugin must call the execute method on the callback handler object, as discussed in previous topics.
override function start( cbh: StartablePluginCallbackHandler, isStarting: boolean ) : void {
_callback = cbh
_callback.execute( \ -> {
//...
}
}
However, the Java language does not directly support blocks. If you implement your plugin in Java, you cannot use a Gosu block. However, instead you can use an anonymous class.
From Java, the method signatures for the
execute methods (there
are multiple variants) take a GWRunnable
for the block argument. GWRunnable
is a simple interface that contains a single method, called run. Instead of using a block,
you can define an in-line anonymous Java class that implements the run method. This is analogous
to the standard Java design pattern for creating an anonymous class to
use the standard class java.lang.Runnable.
GWRunnable myBlock = new GWRunnable() {
public void run() {
System.out.println("I am startable plugin code running in an anonymous inner class");
// Add more code here...
}
};
_callbackHandler.execute(myBlock);
