Skip to content

4. The auto injector

RedsTom edited this page May 15, 2021 · 2 revisions

Use and master the auto-injector

One of the major features of the BotServer API is the injection tool. It permits to easily get variables all around your code.

The only places where you can use this auto-inject is into the different methods called by the server itself.

At the moment, you cannot auto-inject your own variables.

For example, you can use auto-injector into the load methods of the plugin, or in the events.

@BotPlugin(
  id = "Example",
  name = "Example",
  author = "Me"
)
public class Main {
   
    public void load(@Inject("server") IServer server) {
        server.getLogger().info("Plugin loaded.");
    }

    public void unload() {
    }

}

As you can see in this example, the Inject annotation takes a parameter. This is the name of the variable to inject. In this example, the injected variable is the server instance.

You can find here the different variables that can be used with the auto-injector.

Name Type
server org.redstom.botapi.server.IServer
Clone this wiki locally