Plugin vs Script
Plugins allow you to more easily manage creating complex behaviors, where scripts are for short one-shot actions.
What is a plugin?
A plugin is a class that implements the interface software.coley.recaf.plugin.Plugin
. When Recaf launches it looks in the plugins directory for JAR files that contain these plugin classes. It will then attempt to load and initialize them. Because a plugin is distributed as a JAR file a plugin developer can create complex logic and organize it easily across multiple classes in the JAR.
What is a script?
A script is a single Java source file that is executed by users whenever they choose. They can be written as a full class to support similar capabilities to plugins such as service injection, or in a short-hand that offers automatic imports of most common utility classes, but no access to services.
Full class script
A full class script is just a regular class that defines a non-static void run()
. The run()
method is called whenever the user executes the script.
You can access any of Recaf's services by declaring a constructor annotated with @Inject
. For more information and examples see the article on using services in plugins and scripts.
Shorthand script
A shorthand script lets you write your logic without needing to declare a class and run()
method. These shorthand scripts are given a variable reference to the current workspace, and a SLF4J logger. You can access the current workspace as workspace
and the logger as log
.
Another example working with the provided workspace
:
Last updated