Conditional beans
Since Vital was developed with multiplatform support in mind, specific components need to be restricted to specific platforms only.
For example, the inventory system doesn't need to be active if you're running a BungeeCord server, even if that module happens to be added to your plugin.
Also, some modules may support cross-module features, like inventories that can automatically be translated when vital-localization is also used, etc.
To restrict any of your Spring beans, you can use the Spring @Conditional annotation on your class.
The vital-core module already provides you with some conventione conditions for restricting your beans to specific platforms or when specific modules are used in your plugin.
E.g.
@Conditional(RequiresSpigot.class)
@Component
public class MySpigotOnlyBean {
}
The class defined above will only be created by Spring, when your plugin is run on a Spigot or Paper server.
If your plugin is not running on Spigot or Paper, this class is ignored.
Or restrict a bean to only be active when a specific Vital module is used.
@Conditional(RequiresVitalCommands.class)
@Component
public class MyVitalCommandsOnlyBean {
}
The class defined above will only be created by Spring, when your plugin is also using the vital-commands module.
If your plugin doesn't use that module, this class is ignored.
You can also mix and create multiple conditions!
@Conditional({RequiresSpigot.class, RequiresVitalCommands.class})
@Component
public class MySpigotOnlyAndVitalCommandsOnlyBean {
}
The class defined above will only be created by Spring, when your plugin is running on a Spigot or Paper server AND your plugin is also using the vital-commands module.
If your plugin is NOT running on Spigot or Paper, or the vital-commands module is not added to your plugin, this class is ignored.